00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef Tanl_Text_strings_H
00025 #define Tanl_Text_strings_H
00026
00027
00028 #include "platform.h"
00029
00030
00031 #include <cctype>
00032 #include <cstring>
00033 #include <string>
00034 #include <functional>
00035
00036 #include "text/text.h"
00037
00038 #if defined(HAVE_TR1_UNORDERED_MAP)
00039
00040 # include <tr1/unordered_map>
00041 # define HASH_NS std::tr1
00042
00043 #elif defined(HAVE_EXT_HASH_MAP_SET)
00044 # include <ext/hash_map>
00045 # define HASH_NS __gnu_cxx
00046 #else
00047 # include <hash_map>
00048 # define HASH_NS std
00049 #endif
00050
00051 using HASH_NS::hash;
00052
00053 #ifndef __GNUC__
00054
00057 char* strndup(char const* s, int len);
00058 #endif
00059
00060 namespace Tanl {
00061 namespace Text {
00062
00063
00067
00068
00069 extern void itoa(long, char*);
00070
00071
00072 inline char to_lower(char c) { return (char)tolower(c); }
00073 extern char* to_lower(char*);
00074 extern std::string& to_lower(std::string&);
00075 extern void to_lower(register char* d, register char const* s);
00076
00077 inline char to_upper(char c) { return (char)toupper(c); }
00078 extern char* to_upper(char*);
00079 extern std::string& to_upper(std::string&);
00080 extern void to_upper(register char* d, register char const* s);
00081
00082 char const* next_token(char const*& start, char const* end,
00083 const char* sep);
00084 char const* next_token(char const*& start, const char* sep,
00085 char esc);
00086
00087 std::string operator+(const std::string s, const int i);
00088 std::string operator+(const int i, const std::string s);
00089 std::string operator+(const std::string s, const unsigned i);
00090 std::string operator+(const unsigned i, const std::string s);
00091
00096 char* strstr(const char* haystack, const char* needle,
00097 size_t count);
00098
00099 inline int strncasecmp(const char* s1, const char* s2)
00100 {
00101 return ::strncasecmp(s1, s2, ::strlen(s2));
00102 }
00103
00108 bool strStartsWith(const char* s1, const char* init);
00109
00114 inline bool strempty(const char* s)
00115 {
00116 return !s || (s[0] == '\0');
00117 }
00118
00119 }
00120 }
00121
00122
00123 namespace std
00124 {
00125 template <>
00126 struct equal_to<char const*> :
00127 public binary_function<char const*, char const*, bool>
00128 {
00129 bool operator()(first_argument_type __x, first_argument_type __y) const {
00130 return ::strcmp(__x, __y) == 0;
00131 }
00132 };
00133 }
00134
00135 #endif