1
 
/*      Copyright (C) 2004 Garrett A. Kajmowicz
 
3
 
        This file is part of the uClibc++ Library.
 
4
 
        This library is free software; you can redistribute it and/or
 
5
 
        modify it under the terms of the GNU Lesser General Public
 
6
 
        License as published by the Free Software Foundation; either
 
7
 
        version 2.1 of the License, or (at your option) any later version.
 
9
 
        This library 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 GNU
 
12
 
        Lesser General Public License for more details.
 
14
 
        You should have received a copy of the GNU Lesser General Public
 
15
 
        License along with this library; if not, write to the Free Software
 
16
 
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 
#include <basic_definitions>
 
24
 
#ifdef __UCLIBCXX_HAS_WCHAR__
 
29
 
#ifndef __HEADER_CHAR_TRAITS
 
30
 
#define __HEADER_CHAR_TRAITS 1
 
33
 
        /* Inlining all wrapped function calls to shrink the amount of code generated*/ 
 
34
 
        //Typedefs to use for stuff
 
35
 
        typedef signed int char_traits_off_type;
 
38
 
        template<class charT> struct _UCXXEXPORT char_traits { };
 
41
 
        template<> struct _UCXXEXPORT char_traits<char> {
 
42
 
                typedef char char_type;
 
43
 
                typedef short int int_type;
 
44
 
                typedef char_traits_off_type off_type;
 
45
 
                typedef char_traits_off_type pos_type;
 
46
 
                typedef char state_type;
 
48
 
                inline static void assign(char_type & c, const char_type & d) { c = d; }
 
50
 
                static bool eq(const char_type& c1, const char_type& c2);
 
52
 
                static char_type to_char_type(const int_type & i);
 
54
 
                inline static int_type to_int_type(const char_type & c){
 
55
 
                        return (short int)(unsigned char)c;
 
58
 
                inline static bool eq_int_type(const int_type & a, const int_type & b){
 
66
 
                inline static bool lt(const char_type& c1, const char_type& c2){
 
67
 
                        if(strncmp(&c1, &c2, 1) < 0){
 
73
 
                inline static char_type* move(char_type* s1, const char_type* s2, size_t n){
 
74
 
                        return (char*) memmove(s1, s2, n);
 
77
 
                inline static char_type* copy(char_type* s1, const char_type* s2, size_t n){
 
78
 
                        for(unsigned long int i=0; i< n; ++i){
 
84
 
                inline static char_type* assign(char_type* s, size_t n, char_type a){
 
85
 
                        return (char *)memset(s, a, n);
 
88
 
                inline static int compare(const char_type* s1, const char_type* s2, size_t n){
 
89
 
                        return strncmp(s1, s2, n);
 
92
 
                inline static size_t length(const char_type* s){
 
96
 
                static const char_type* find(const char_type* s, int n, const char_type& a);
 
98
 
                inline static char_type eos() { return 0; }
 
99
 
                inline static int_type eof() { return -1; }
 
100
 
                inline static int_type not_eof(const int_type & i) {
 
107
 
                static state_type get_state(pos_type p){
 
115
 
#ifdef __UCLIBCXX_HAS_WCHAR__
 
116
 
        template<> struct _UCXXEXPORT char_traits<wchar_t> {
 
117
 
                typedef wchar_t char_type;
 
118
 
                typedef wint_t int_type;
 
119
 
                typedef char_traits_off_type off_type;
 
120
 
                typedef char_traits_off_type pos_type;
 
121
 
                typedef mbstate_t state_type;
 
123
 
                static void assign(char_type & c, const char_type & d){ c=d; }
 
125
 
                static char_type to_char_type(const int_type & i){
 
129
 
                static int_type to_int_type(const char_type & c){
 
133
 
                inline static bool eq_int_type(const int_type & a, const int_type & b){
 
140
 
                inline static bool eq(const char_type& c1, const char_type& c2){
 
141
 
                        if(wcsncmp(&c1, &c2, 1) == 0){
 
147
 
                inline static bool lt(const char_type& c1, const char_type& c2){
 
148
 
                        if(wcsncmp(&c1, &c2, 1) < 0){
 
154
 
                inline static char_type* move(char_type* s1, const char_type* s2, size_t n){
 
155
 
                        return (char_type*) memmove(s1, s2, n * sizeof(char_type));
 
158
 
                inline static char_type* copy(char_type* s1, const char_type* s2, size_t n){
 
159
 
                        for(unsigned long int i=0; i< n; ++i){
 
160
 
                                assign(s1[i], s2[i]);
 
165
 
                inline static char_type* assign(char_type* s, size_t n, char_type a){
 
166
 
                        return (char_type *)memset(s, a, n);    /*FIXME*/
 
169
 
                inline static int compare(const char_type* s1, const char_type* s2, size_t n){
 
170
 
                        return wcsncmp(s1, s2, n);
 
173
 
                inline static size_t length(const char_type* s){
 
177
 
                static const char_type* find(const char_type* s, int n, const char_type& a);
 
179
 
                inline static char_type eos() { return 0; }
 
180
 
                inline static int_type eof() { return WEOF; }
 
181
 
                inline static int_type not_eof(const int_type & i) {
 
188
 
                static state_type get_state(pos_type){