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