/************************************************************************* * * HTCd - Copyright (C) 1998-2006 Henrik Rydberg * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef SREFH #define SREFH #include #include typedef char sref_t[1024]; class sref { public: sref() : map((char*)&dim),dim(0) {} explicit sref(char* p) : map(p),dim(strlen(p)) {} explicit sref(const char* p) : map((char*)p),dim(strlen(p)) {} sref(char* p,int n) : map(p),dim(n) {} sref(const char* p,int n) : map((char*)p),dim(n) {} int size() const { return dim; } bool empty() const { return dim==0; } bool nempty() const { return dim!=0; } char* data() { return map; } const char* data() const { return map; } char& operator[](int pos) { return map[pos]; } const char& operator[](int pos) const { return map[pos]; } char* begin() { return map; } const char* begin() const { return map; } char* end() { return map+dim; } const char* end() const { return map+dim; } int operator*() const { return dim?*map:0; } int front() const { return dim?*map:0; } int back() const { return dim?map[dim-1]:0; } //////////////////////////////////////////////////////////////// sref popf() const { return dim?sref(map+1,dim-1):*this; } sref popb() const { return dim?sref(map,dim-1):*this; } sref adv(int n) const { return n>0?(n=(const sref& a,const sref& b) { return a.compare(b)>=0; } inline bool operator>(const sref& a,const sref& b) { return a.compare(b)>0; } ////////////////////////////////////////////////////////////////////////// inline int operator-(const sref& a,const sref& b) { return a.data()-b.data(); } ////////////////////////////////////////////////////////////////////////// inline int ltn(const sref& a,const sref& b) { return a.compare(b,cset_lcase)<0; } inline int len(const sref& a,const sref& b) { return a.compare(b,cset_lcase)<=0; } inline int eqn(const sref& a,const sref& b) { return a.compare(b,cset_lcase)==0; } inline int nen(const sref& a,const sref& b) { return a.compare(b,cset_lcase)!=0; } inline int gen(const sref& a,const sref& b) { return a.compare(b,cset_lcase)>=0; } inline int gtn(const sref& a,const sref& b) { return a.compare(b,cset_lcase)>0; } ////////////////////////////////////////////////////////////////////////// inline int atob(const sref& s) { sref_t buf; return atoi(s.copyto(buf))!=0; } inline int atoi(const sref& s) { sref_t buf; return atoi(s.copyto(buf)); } inline double atof(const sref& s) { sref_t buf; return atof(s.copyto(buf)); } #endif