1 // -*- C++ -*- 2 // $Id: id3lib_strings.h,v 1.4 2003/03/02 13:56:21 t1mpy Exp $ 3 4 // id3lib: a software library for creating and manipulating id3v1/v2 tags 5 // Copyright 1999, 2000 Scott Thomas Haug 6 // Copyright 2002 Thijmen Klok (thijmen@id3lib.org) 7 8 // This library is free software; you can redistribute it and/or modify it 9 // under the terms of the GNU Library General Public License as published by 10 // the Free Software Foundation; either version 2 of the License, or (at your 11 // option) any later version. 12 // 13 // This library is distributed in the hope that it will be useful, but WITHOUT 14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 16 // License for more details. 17 // 18 // You should have received a copy of the GNU Library General Public License 19 // along with this library; if not, write to the Free Software Foundation, 20 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 22 // The id3lib authors encourage improvements and optimisations to be sent to 23 // the id3lib coordinator. Please see the README file for details on where to 24 // send such submissions. See the AUTHORS file for a list of people who have 25 // contributed to id3lib. See the ChangeLog file for a list of changes to 26 // id3lib. These files are distributed with id3lib at 27 // http://download.sourceforge.net/id3lib/ 28 29 #ifndef _ID3LIB_STRINGS_H_ 30 #define _ID3LIB_STRINGS_H_ 31 32 #include <string> 33 #include <cstring> 34 35 #if (defined(__GNUC__) && (__GNUC__ >= 3) || (defined(_MSC_VER) && _MSC_VER > 1000)) 36 namespace std 37 { 38 template<> 39 struct char_traits<unsigned char> 40 { 41 typedef unsigned char char_type; 42 // Unsigned as wint_t in unsigned. 43 typedef unsigned long int_type; 44 typedef streampos pos_type; 45 typedef streamoff off_type; 46 typedef mbstate_t state_type; 47 48 static void 49 assign(char_type& __c1, const char_type& __c2) 50 { __c1 = __c2; } 51 52 static bool 53 eq(const char_type& __c1, const char_type& __c2) 54 { return __c1 == __c2; } 55 56 static bool 57 lt(const char_type& __c1, const char_type& __c2) 58 { return __c1 < __c2; } 59 60 static int 61 compare(const char_type* __s1, const char_type* __s2, size_t __n) 62 { 63 for (size_t __i = 0; __i < __n; ++__i) 64 if (!eq(__s1[__i], __s2[__i])) 65 return lt(__s1[__i], __s2[__i]) ? -1 : 1; 66 return 0; 67 } 68 69 static size_t 70 length(const char_type* __s) 71 { 72 const char_type* __p = __s; 73 while (__p) 74 ++__p; 75 return (__p - __s); 76 } 77 78 static const char_type* 79 find(const char_type* __s, size_t __n, const char_type& __a) 80 { 81 for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p) 82 if (*__p == __a) return __p; 83 return 0; 84 } 85 86 static char_type* 87 move(char_type* __s1, const char_type* __s2, size_t __n) 88 { return (char_type*) memmove(__s1, __s2, __n * sizeof(char_type)); } 89 90 static char_type* 91 copy(char_type* __s1, const char_type* __s2, size_t __n) 92 { return (char_type*) memcpy(__s1, __s2, __n * sizeof(char_type)); } 93 94 static char_type* 95 assign(char_type* __s, size_t __n, char_type __a) 96 { 97 for (char_type* __p = __s; __p < __s + __n; ++__p) 98 assign(*__p, __a); 99 return __s; 100 } 101 102 static char_type 103 to_char_type(const int_type& __c) 104 { return char_type(); } 105 106 static int_type 107 to_int_type(const char_type& __c) { return int_type(); } 108 109 static bool 110 eq_int_type(const int_type& __c1, const int_type& __c2) 111 { return __c1 == __c2; } 112 113 static int_type 114 eof() { return static_cast<int_type>(-1); } 115 116 static int_type 117 not_eof(const int_type& __c) 118 { return eq_int_type(__c, eof()) ? int_type(0) : __c; } 119 }; 120 121 #ifndef _GLIBCPP_USE_WCHAR_T 122 #if (defined(ID3_NEED_WCHAR_TEMPLATE)) 123 template<> 124 struct char_traits<wchar_t> 125 { 126 typedef wchar_t char_type; 127 typedef wint_t int_type; 128 typedef streamoff off_type; 129 typedef streampos pos_type; 130 typedef mbstate_t state_type; 131 132 static void 133 assign(char_type& __c1, const char_type& __c2) 134 { __c1 = __c2; } 135 136 static bool 137 eq(const char_type& __c1, const char_type& __c2) 138 { return __c1 == __c2; } 139 140 static bool 141 lt(const char_type& __c1, const char_type& __c2) 142 { return __c1 < __c2; } 143 144 static int 145 compare(const char_type* __s1, const char_type* __s2, size_t __n) 146 { return wmemcmp(__s1, __s2, __n); } 147 148 static size_t 149 length(const char_type* __s) 150 { return wcslen(__s); } 151 152 static const char_type* 153 find(const char_type* __s, size_t __n, const char_type& __a) 154 { return wmemchr(__s, __a, __n); } 155 156 static char_type* 157 move(char_type* __s1, const char_type* __s2, int_type __n) 158 { return wmemmove(__s1, __s2, __n); } 159 160 static char_type* 161 copy(char_type* __s1, const char_type* __s2, size_t __n) 162 { return wmemcpy(__s1, __s2, __n); } 163 164 static char_type* 165 assign(char_type* __s, size_t __n, char_type __a) 166 { return wmemset(__s, __a, __n); } 167 168 static char_type 169 to_char_type(const int_type& __c) { return char_type(__c); } 170 171 static int_type 172 to_int_type(const char_type& __c) { return int_type(__c); } 173 174 static bool 175 eq_int_type(const int_type& __c1, const int_type& __c2) 176 { return __c1 == __c2; } 177 178 static state_type 179 _S_get_state(const pos_type& __pos) { return __pos.state(); } 180 181 static int_type 182 eof() { return static_cast<int_type>(WEOF); } 183 184 static int_type 185 _S_eos() { return char_type(); } 186 187 static int_type 188 not_eof(const int_type& __c) 189 { return eq_int_type(__c, eof()) ? 0 : __c; } 190 }; 191 #endif 192 #endif 193 } // namespace std 194 #endif 195 196 namespace dami 197 { 198 typedef std::basic_string<char> String; 199 typedef std::basic_string<unsigned char> BString; 200 typedef std::basic_string<wchar_t> WString; 201 }; 202 203 #endif /* _ID3LIB_STRINGS_H_ */ 204 205