GNU CommonC++

strchar.h

Go to the documentation of this file.
00001 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
00002 // Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
00003 //
00004 // This program is free software; you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation; either version 2 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 //
00018 // As a special exception, you may use this file as part of a free software
00019 // library without restriction.  Specifically, if other files instantiate
00020 // templates or use macros or inline functions from this file, or you compile
00021 // this file and link it with other files to produce an executable, this
00022 // file does not by itself cause the resulting executable to be covered by
00023 // the GNU General Public License.  This exception does not however
00024 // invalidate any other reasons why the executable file might be covered by
00025 // the GNU General Public License.
00026 //
00027 // This exception applies only to the code released under the name GNU
00028 // Common C++.  If you copy code from other releases into a copy of GNU
00029 // Common C++, as the General Public License permits, the exception does
00030 // not apply to the code that you add in this way.  To avoid misleading
00031 // anyone as to the status of such modified files, you must delete
00032 // this exception notice from them.
00033 //
00034 // If you write modifications of your own for GNU Common C++, it is your choice
00035 // whether to permit this exception to apply to your modifications.
00036 // If you do not wish that, delete this exception notice.
00037 //
00038 
00045 #ifndef CCXX_STRCHAR_H_
00046 #define CCXX_STRCHAR_H_
00047 
00048 #ifndef CCXX_CONFIG_H_
00049 #include <cc++/config.h>
00050 #endif
00051 
00052 #ifndef CCXX_MISSING_H_
00053 #include <cc++/missing.h>
00054 #endif
00055 
00056 #include <cctype>
00057 #include <string>
00058 #include <cstring>
00059 
00060 #ifdef  HAVE_STRINGS_H
00061 extern "C" {
00062 #include <strings.h>
00063 }
00064 #endif
00065 
00066 #ifdef  HAVE_STRCASECMP
00067 #ifndef stricmp
00068 #define stricmp(x, y) strcasecmp(x, y)
00069 #endif
00070 #ifndef strnicmp
00071 #define strnicmp(x, y, n) strncasecmp(x, y, n)
00072 #endif
00073 #endif
00074 
00075 #ifdef  CCXX_NAMESPACES
00076 namespace ost {
00077 #endif
00078 
00079 __EXPORT char *lsetField(char *target, size_t size, const char *src, const char fill = 0);
00080 __EXPORT char *rsetField(char *target, size_t size, const char *src, const char fill = 0);
00081 __EXPORT char *setString(char *target, size_t size, const char *src);
00082 __EXPORT char *addString(char *target, size_t size, const char *src);
00083 __EXPORT char *newString(const char *src, size_t size = 0);
00084 __EXPORT void delString(char *str);
00085 __EXPORT char *setUpper(char *string, size_t size);
00086 __EXPORT char *setLower(char *string, size_t size);
00087 __EXPORT char *find(const char *cs, char *str, size_t len = 0);
00088 __EXPORT char *rfind(const char *cs, char *str, size_t len = 0);
00089 __EXPORT char *ifind(const char *cs, char *str, size_t len = 0);
00090 __EXPORT char *strip(const char *cs, char *str, size_t len = 0);
00091 __EXPORT size_t strchop(const char *cs, char *str, size_t len = 0);
00092 __EXPORT size_t strtrim(const char *cs, char *str, size_t len = 0);
00093 
00094 inline char *dupString(const char *src, size_t size = 0)
00095     {return newString(src, size);}
00096 
00097 /*
00098 class keystring
00099 {
00100 private:
00101     const char *c_str;
00102 
00103 public:
00104     inline keystring(const char *s)
00105         {c_str = s;}
00106 
00107     inline keystring()
00108         {c_str = NULL;};
00109 
00110     virtual int compare(const char *s2)
00111         {return stricmp(c_str, s2);};
00112 
00113     inline const char *operator =(const char *s)
00114         {return c_str = s;};
00115 
00116     friend inline int operator==(keystring k1, keystring k2)
00117         {return (k1.compare(k2) == 0);};
00118 
00119     friend inline int operator==(keystring k1, const char *c)
00120         {return (k1.compare(c) == 0);};
00121 
00122     friend inline int operator!=(keystring k1, const char *c)
00123         {return (k1.compare(c) != 0);};
00124 
00125     friend inline int operator==(const char *c, keystring k1)
00126         {return (k1.compare(c) == 0);};
00127 
00128     friend inline int operator!=(const char *c, keystring k1)
00129         {return (k1.compare(c) != 0);};
00130 
00131     friend inline int operator!=(keystring k1, keystring k2)
00132         {return (k1.compare(k2) != 0);};
00133 
00134     friend inline int operator<(keystring k1, keystring k2)
00135         {return (k1.compare(k2) < 0);};
00136 
00137     friend inline int operator>(keystring k1, keystring k2)
00138         {return (k1.compare(k2) > 0);};
00139 
00140     friend inline int operator<=(keystring k1, keystring k2)
00141         {return (k1.compare(k2) <= 0);};
00142 
00143     friend inline int operator>=(keystring k1, keystring k2)
00144         {return (k1.compare(k2) >= 0);};
00145 
00146     friend inline int operator!(keystring k1)
00147         {return k1.c_str == NULL;};
00148 
00149     friend inline int length(keystring k1)
00150         {return static_cast<int>(strlen(k1.c_str));};
00151 
00152     friend inline const char *text(keystring k1)
00153         {return k1.c_str;};
00154 
00155     inline const char *operator ()()
00156         {return c_str;};
00157 
00158     inline operator const char *()
00159         {return c_str;};
00160 };
00161 
00162 */
00163 
00164 #ifdef  CCXX_NAMESPACES
00165 }
00166 #endif
00167 
00168 #endif