CharTraits.h

00001 // $Id: CharTraits.h 21 2010-09-05 04:18:17Z cschwarz1 $
00002 
00003 #ifndef BASE_CHARTRAITS_H
00004 #define BASE_CHARTRAITS_H
00005 
00006 #include <cstdarg>
00007 #include "portable.h"
00008 
00009 namespace base {
00011     template<class charT> struct PPBASE_EXPORT CharTraits {};
00012 
00014     template<> struct PPBASE_EXPORT CharTraits<void> {
00015         typedef size_t size_type; 
00016 
00018         static const void *memchr(const void *s, char c, size_type n);
00020         static void *memchr(void *s, char c, size_type n);
00022         static int memcmp(const void *a, const void *b, size_type n);
00024         static void memmove(void *d, const void *s, size_type n);
00026         static void memset(void *d, char ch, size_type n);
00027     };
00028 
00030     template<> struct PPBASE_EXPORT CharTraits<char> {
00031         typedef size_t size_type;              
00032         static const char  ch_ast = '*';       
00033         static const char  ch_neg = '-';       
00034         static const char  ch_qm  = '?';       
00035         static const char  ch0    = '0';       
00036         static const char  cha    = 'a';       
00037         static const char  chA    = 'A';       
00038         static const char  chx    = 'x';       
00039         static const char  chX    = 'X';       
00040         static const char *empty;              
00041         static const char *eoln;               
00042         static const char  nul    = '\0';      
00043     #ifdef _WIN32
00044         static const char  path_separator_char = '\\';  
00045     #else
00046         static const char  path_separator_char = '/';   
00047     #endif
00048         static const char *path_separator_string;  
00049 
00050         static size_type dtoa(double n, char *s);
00052         static int isalnum(char ch);
00054         static int isalpha(char ch);
00056         static int isdigit(char ch);
00058         static int isspace(char ch);
00060         static size_type length(const char *s);
00062         static size_type ltoa(long n, char *s);
00064         static size_type lltoa(longlong_t n, char *s);
00066         static int memcmp(const char *a, const char *b, size_type n);
00068         static void memmove(char *d, const char *s, size_type n);
00070         static void memset(char *d, char ch, size_type n);
00072         static int strcasecmp(const char *a, const char *b);
00074         static const char *strchr(const char *a, char b);
00076         static char *strchr(char *a, char b);
00078         static int strcmp(const char *a, const char *b);
00080         static char *strcpy(char *dest, const char *src);
00082         static int strncmp(const char *a, const char *b, size_t n);
00084         static char *strncpy(char *dest, const char *src, size_t n);
00086         static void swap(char *ch);
00088         static char tolower(char ch);
00090         static char toupper(char ch);
00092         static size_type ultoa(unsigned long n, char *s);
00094         static size_type ulltoa(u_longlong_t n, char *s);
00096         static size_type vxprintf(char *d, size_type n, const char *f, va_list ap);
00097     };
00098 
00100     template<> struct PPBASE_EXPORT CharTraits<wchar_t> {
00101         typedef size_t size_type;              
00102         static const wchar_t  ch_ast = L'*';   
00103         static const wchar_t  ch_neg = L'-';   
00104         static const wchar_t  ch_qm  = L'?';   
00105         static const wchar_t  ch0    = L'0';   
00106         static const wchar_t  cha    = L'a';   
00107         static const wchar_t  chA    = L'A';   
00108         static const wchar_t  chx    = L'x';   
00109         static const wchar_t  chX    = L'X';   
00110         static const wchar_t *empty;           
00111         static const wchar_t *eoln;            
00112         static const wchar_t  nul    = L'\0';  
00113     #ifdef _WIN32
00114         static const wchar_t  path_separator_char = L'\\';  
00115     #else
00116         static const wchar_t  path_separator_char = L'/';   
00117     #endif
00118         static const wchar_t *path_separator_string;        
00119 
00120         static size_type dtoa(double n, wchar_t *s);
00122         static int isalnum(wchar_t ch);
00124         static int isalpha(wchar_t ch);
00126         static int isdigit(wchar_t ch);
00128         static int isspace(wchar_t ch);
00130         static size_type length(const wchar_t *s);
00132         static size_type ltoa(long n, wchar_t *s);
00134         static size_type lltoa(longlong_t n, wchar_t *s);
00136         static int memcmp(const wchar_t *a, const wchar_t *b, size_type n);
00138         static void memmove(wchar_t *d, const wchar_t *s, size_type n);
00140         static void memset(wchar_t *d, wchar_t ch, size_type n);
00142         static int strcasecmp(const wchar_t *a, const wchar_t *b);
00144         static const wchar_t *strchr(const wchar_t *a, wchar_t b);
00146         static wchar_t *strchr(wchar_t *a, wchar_t b);
00148         static int strcmp(const wchar_t *a, const wchar_t *b);
00150         static wchar_t *strcpy(wchar_t *dest, const wchar_t *src);
00152         static int strncmp(const wchar_t *a, const wchar_t *b, size_type n);
00154         static wchar_t *strncpy(wchar_t *dest, const wchar_t *src, size_type n);
00156         static void swap(wchar_t *ch);
00158         static wchar_t tolower(wchar_t ch);
00160         static wchar_t toupper(wchar_t ch);
00162         static size_type ultoa(unsigned long n, wchar_t *s);
00164         static size_type ulltoa(u_longlong_t n, wchar_t *s);
00166         static size_type vxprintf(wchar_t *d, size_type n, const wchar_t *f, va_list ap);
00167     };
00168 }
00169 
00170 #endif