GNU CommonC++
strchar.h
Go to the documentation of this file.
1 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 // As a special exception, you may use this file as part of a free software
18 // library without restriction. Specifically, if other files instantiate
19 // templates or use macros or inline functions from this file, or you compile
20 // this file and link it with other files to produce an executable, this
21 // file does not by itself cause the resulting executable to be covered by
22 // the GNU General Public License. This exception does not however
23 // invalidate any other reasons why the executable file might be covered by
24 // the GNU General Public License.
25 //
26 // This exception applies only to the code released under the name GNU
27 // Common C++. If you copy code from other releases into a copy of GNU
28 // Common C++, as the General Public License permits, the exception does
29 // not apply to the code that you add in this way. To avoid misleading
30 // anyone as to the status of such modified files, you must delete
31 // this exception notice from them.
32 //
33 // If you write modifications of your own for GNU Common C++, it is your choice
34 // whether to permit this exception to apply to your modifications.
35 // If you do not wish that, delete this exception notice.
36 //
37 
44 #ifndef CCXX_STRCHAR_H_
45 #define CCXX_STRCHAR_H_
46 
47 #ifndef CCXX_CONFIG_H_
48 #include <cc++/config.h>
49 #endif
50 
51 #ifndef CCXX_MISSING_H_
52 #include <cc++/missing.h>
53 #endif
54 
55 #include <cctype>
56 #include <string>
57 #include <cstring>
58 
59 #ifdef HAVE_STRINGS_H
60 extern "C" {
61 #include <strings.h>
62 }
63 #endif
64 
65 #ifdef HAVE_STRCASECMP
66 #ifndef stricmp
67 #define stricmp(x, y) strcasecmp(x, y)
68 #endif
69 #ifndef strnicmp
70 #define strnicmp(x, y, n) strncasecmp(x, y, n)
71 #endif
72 #endif
73 
74 #ifdef CCXX_NAMESPACES
75 namespace ost {
76 #endif
77 
78 __EXPORT char *lsetField(char *target, size_t size, const char *src, const char fill = 0);
79 __EXPORT char *rsetField(char *target, size_t size, const char *src, const char fill = 0);
80 __EXPORT char *setString(char *target, size_t size, const char *src);
81 __EXPORT char *addString(char *target, size_t size, const char *src);
82 __EXPORT char *newString(const char *src, size_t size = 0);
83 __EXPORT void delString(char *str);
84 __EXPORT char *setUpper(char *string, size_t size);
85 __EXPORT char *setLower(char *string, size_t size);
86 __EXPORT char *find(const char *cs, char *str, size_t len = 0);
87 __EXPORT char *rfind(const char *cs, char *str, size_t len = 0);
88 __EXPORT char *ifind(const char *cs, char *str, size_t len = 0);
89 __EXPORT char *strip(const char *cs, char *str, size_t len = 0);
90 __EXPORT size_t strchop(const char *cs, char *str, size_t len = 0);
91 __EXPORT size_t strtrim(const char *cs, char *str, size_t len = 0);
92 
93 inline char *dupString(const char *src, size_t size = 0)
94  {return newString(src, size);}
95 
96 /*
97 class keystring
98 {
99 private:
100  const char *c_str;
101 
102 public:
103  inline keystring(const char *s)
104  {c_str = s;}
105 
106  inline keystring()
107  {c_str = NULL;};
108 
109  virtual int compare(const char *s2)
110  {return stricmp(c_str, s2);};
111 
112  inline const char *operator =(const char *s)
113  {return c_str = s;};
114 
115  friend inline int operator==(keystring k1, keystring k2)
116  {return (k1.compare(k2) == 0);};
117 
118  friend inline int operator==(keystring k1, const char *c)
119  {return (k1.compare(c) == 0);};
120 
121  friend inline int operator!=(keystring k1, const char *c)
122  {return (k1.compare(c) != 0);};
123 
124  friend inline int operator==(const char *c, keystring k1)
125  {return (k1.compare(c) == 0);};
126 
127  friend inline int operator!=(const char *c, keystring k1)
128  {return (k1.compare(c) != 0);};
129 
130  friend inline int operator!=(keystring k1, keystring k2)
131  {return (k1.compare(k2) != 0);};
132 
133  friend inline int operator<(keystring k1, keystring k2)
134  {return (k1.compare(k2) < 0);};
135 
136  friend inline int operator>(keystring k1, keystring k2)
137  {return (k1.compare(k2) > 0);};
138 
139  friend inline int operator<=(keystring k1, keystring k2)
140  {return (k1.compare(k2) <= 0);};
141 
142  friend inline int operator>=(keystring k1, keystring k2)
143  {return (k1.compare(k2) >= 0);};
144 
145  friend inline int operator!(keystring k1)
146  {return k1.c_str == NULL;};
147 
148  friend inline int length(keystring k1)
149  {return static_cast<int>(strlen(k1.c_str));};
150 
151  friend inline const char *text(keystring k1)
152  {return k1.c_str;};
153 
154  inline const char *operator ()()
155  {return c_str;};
156 
157  inline operator const char *()
158  {return c_str;};
159 };
160 
161 */
162 
163 #ifdef CCXX_NAMESPACES
164 }
165 #endif
166 
167 #endif