From 5df79c53745fde5d6c3340a2979b1429cd5892c1 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sat, 8 Oct 2011 20:30:28 +0200 Subject: Initial import of htcd system 1.0 Signed-off-by: Henrik Rydberg --- src/mt/stringref.h | 239 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 239 insertions(+) create mode 100644 src/mt/stringref.h (limited to 'src/mt/stringref.h') diff --git a/src/mt/stringref.h b/src/mt/stringref.h new file mode 100644 index 0000000..a66ac21 --- /dev/null +++ b/src/mt/stringref.h @@ -0,0 +1,239 @@ +/************************************************************************* + * + * 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 -- cgit v1.2.3