ucs2string.h

Go to the documentation of this file.
00001 /*
00002  *      UCS-2 string library (char_trait<ucs2char_t> implementation).
00003  *
00004  *      Copyright (c) 2005-2007 Naoaki Okazaki
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  * 
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00019  *
00020  */
00021 
00022 /* $Id: ucs2string.h 328 2007-02-10 17:50:11Z nyaochi $ */
00023 
00024 #ifndef __UCS2STRING_H__
00025 #define __UCS2STRING_H__
00026 
00027 #include <ucs2char.h>
00028 #include <string>
00029 
00030 struct ucs2char_traits
00031 {
00032         typedef ucs2char_t                                      char_type;
00033         typedef int                                                     int_type;
00034         typedef std::streamoff                          off_type;
00035         typedef std::fpos<std::mbstate_t>       pos_type;
00036         typedef std::mbstate_t                          state_type;
00037 
00038         static void assign(char_type& __cl, const char_type& __cr)
00039         {
00040                 __cl = __cr;
00041         }
00042 
00043         static bool eq(const char_type& __cl, const char_type& __cr)
00044         {
00045                 return __cl == __cr;
00046         }
00047 
00048         static bool lt(const char_type& __cl, const char_type& __cr)
00049         {
00050                 return __cl < __cr;
00051         }
00052 
00053         static int compare(const char_type* __s1, const char_type* __s2, size_t __n)
00054         {
00055                 return ucs2memcmp(__s1, __s2, __n);
00056         }
00057 
00058         static size_t length(const char_type* __s)
00059         {
00060                 return ucs2len(__s);
00061         }
00062 
00063         static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
00064         {
00065                 return ucs2memchr(__s, __a, __n);
00066         }
00067 
00068         static char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
00069         {
00070                 return ucs2memmove(__s1, __s2, __n);
00071         }
00072 
00073         static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
00074         {
00075                 return ucs2memcpy(__s1, __s2, __n);
00076         }
00077         
00078         static char_type* assign(char_type* __s, size_t __n, char_type __a)
00079         {
00080                 return ucs2memset(__s, __a, __n);
00081         }
00082         
00083         static char_type to_char_type(const int_type& __c)
00084         {
00085                 return char_type(__c);
00086         }
00087         
00088         static int_type to_int_type(const char_type& __c)
00089         {
00090                 return int_type(__c);
00091         }
00092 
00093         static bool eq_int_type(const int_type& __c1, const int_type& __c2)
00094         {
00095                 return __c1 == __c2;
00096         }
00097 
00098     static int_type eof()
00099         {
00100                 return static_cast<int_type>(0xFFFF);
00101         }
00102 
00103         static int_type not_eof(const int_type& __c)
00104     {
00105                 return eq_int_type(__c, eof()) ? 0 : __c;
00106         }
00107 };
00108 
00109 typedef std::basic_string<ucs2char_t, ucs2char_traits, std::allocator<ucs2char_t> > ucs2string;
00110 
00111 #endif/*__UCS2STRING_H__*/