last changes
[vspell.git] / libvspell / mystring.h
blobd10c40b6b8ae900c2c7fb8553416fd19a257e9ff
1 #ifndef __MYSTRING_H__ // -*- tab-width: 2 mode: c++ -*-
2 #define __MYSTRING_H__
4 struct char_traits_strid:public std::char_traits<strid>
6 typedef strid char_type;
7 typedef int int_type;
8 //typedef streampos pos_type;
9 //typedef streamoff off_type;
10 //typedef mbstate_t state_type;
12 static void
13 assign(char_type& __c1, const char_type& __c2)
14 { __c1 = __c2; }
16 static bool
17 eq(const char_type& __c1, const char_type& __c2)
18 { return __c1 == __c2; }
20 static bool
21 lt(const char_type& __c1, const char_type& __c2)
22 { return __c1 < __c2; }
24 static int
25 compare(const char_type* __s1, const char_type* __s2, size_t __n)
26 { return memcmp((const char*)__s1, (const char*)__s2, __n*sizeof(char_type)); }
28 static size_t length(const char_type* __s)
30 int i = 0;
31 while (__s[i])
32 i++;
33 return i;
37 static const char_type*
38 find(const char_type* __s, size_t __n, const char_type& __a)
40 for (size_t i = 0;i < __n;i ++)
41 if (__s[i] == __a)
42 return &__s[i];
43 return 0;
46 static char_type*
47 move(char_type* __s1, const char_type* __s2, size_t __n)
48 { return static_cast<char_type*>(memmove(__s1, __s2, __n*sizeof(char_type))); }
50 static char_type*
51 copy(char_type* __s1, const char_type* __s2, size_t __n)
52 { return static_cast<char_type*>(memcpy(__s1, __s2, __n*sizeof(char_type))); }
54 static char_type*
55 assign(char_type* __s, size_t __n, char_type __a)
57 for (size_t i = 0;i < __n;i ++)
58 __s[i] = __a;
59 return __s;
62 static char_type
63 to_char_type(const int_type& __c)
64 { return static_cast<char_type>(__c); }
66 // To keep both the byte 0xff and the eof symbol 0xffffffff
67 // from ending up as 0xffffffff.
68 static int_type
69 to_int_type(const char_type& __c)
70 { return static_cast<int_type>(static_cast<unsigned char>(__c)); }
72 static bool
73 eq_int_type(const int_type& __c1, const int_type& __c2)
74 { return __c1 == __c2; }
76 static int_type
77 eof() { return static_cast<int_type>(EOF); }
79 static int_type
80 not_eof(const int_type& __c)
81 { return (__c == eof()) ? 0 : __c; }
83 typedef std::basic_string<strid,char_traits_strid> strid_string;
84 #endif