ts_string.h

00001 /*  wcecompat: Windows CE C Runtime Library "compatibility" library.
00002  *
00003  *  Copyright (C) 2001-2002 Essemer Pty Ltd.  All rights reserved.
00004  *  http://www.essemer.com.au/
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 
00022 #ifndef __wcecompat__ts_string_h__
00023 #define __wcecompat__ts_string_h__
00024 
00025 
00026 #include <string.h>
00027 #include <windows.h>
00028 
00029 
00030 void ascii2unicode(const char* ascii, WCHAR* unicode);
00031 void unicode2ascii(const WCHAR* unicode, char* ascii);
00032 void ascii2unicode(const char* ascii, WCHAR* unicode, int maxChars);
00033 void unicode2ascii(const WCHAR* unicode, char* ascii, int maxChars);
00034 
00035 
00036 //
00037 // ascii/unicode typesafe versions of strlen
00038 //
00039 
00040 inline size_t ts_strlen(const char* str)
00041 {
00042         return strlen(str);
00043 }
00044 
00045 inline size_t ts_strlen(const unsigned short* str)
00046 {
00047         return wcslen(str);
00048 }
00049 
00050 
00051 //
00052 // ascii/unicode typesafe versions of strsize
00053 // (returns size in bytes of str, not num characters as strlen does.  Does not include zero termination)
00054 //
00055 
00056 inline size_t ts_strsize(const char* str)
00057 {
00058         return strlen(str);
00059 }
00060 
00061 inline size_t ts_strsize(const unsigned short* str)
00062 {
00063         return wcslen(str)*2;
00064 }
00065 
00066 
00067 //
00068 // ascii/unicode typesafe versions of strsize
00069 // (returns size in bytes of str, not num characters as strlen does.  Includes zero termination)
00070 //
00071 
00072 inline size_t ts_strsizez(const char* str)
00073 {
00074         return strlen(str)+1;
00075 }
00076 
00077 inline size_t ts_strsizez(const unsigned short* str)
00078 {
00079         return (wcslen(str)+1)*2;
00080 }
00081 
00082 
00083 //
00084 // ascii/unicode typesafe versions of strcpy
00085 //
00086 
00087 inline char* ts_strcpy(char* dest, const char* src)
00088 {
00089         return strcpy(dest, src);
00090 }
00091 
00092 inline char* ts_strcpy(char* dest, const unsigned short* src)
00093 {
00094         unicode2ascii(src, dest);
00095         return dest;
00096 }
00097 
00098 inline unsigned short* ts_strcpy(unsigned short* dest, const char* src)
00099 {
00100         ascii2unicode(src, dest);
00101         return dest;
00102 }
00103 
00104 inline unsigned short* ts_strcpy(unsigned short* dest, const unsigned short* src)
00105 {
00106         return wcscpy(dest, src);
00107 }
00108 
00109 
00110 //
00111 // ascii/unicode typesafe versions of strncpy
00112 //
00113 
00114 inline char* ts_strncpy(char* dest, const char* src, int n)
00115 {
00116         return strncpy(dest, src, n);
00117 }
00118 
00119 inline char* ts_strncpy(char* dest, const unsigned short* src, int n)
00120 {
00121         unicode2ascii(src, dest, n);
00122         return dest;
00123 }
00124 
00125 inline unsigned short* ts_strncpy(unsigned short* dest, const char* src, int n)
00126 {
00127         ascii2unicode(src, dest, n);
00128         return dest;
00129 }
00130 
00131 inline unsigned short* ts_strncpy(unsigned short* dest, const unsigned short* src, int n)
00132 {
00133         return wcsncpy(dest, src, n);
00134 }
00135 
00136 
00137 //
00138 // ascii/unicode typesafe versions of strcat
00139 //
00140 
00141 inline char* ts_strcat(char* dest, const char* src)
00142 {
00143         return strcat(dest, src);
00144 }
00145 
00146 char* ts_strcat(char* dest, const unsigned short* src);
00147 unsigned short* ts_strcat(unsigned short* dest, const char* src);
00148 
00149 inline unsigned short* ts_strcat(unsigned short* dest, const unsigned short* src)
00150 {
00151         return wcscat(dest, src);
00152 }
00153 
00154 
00155 //
00156 // ascii/unicode typesafe versions of strdup
00157 //
00158 
00159 inline char* ts_strdup(const char* str)
00160 {
00161         return _strdup(str);
00162 }
00163 
00164 char* ts_strdup_unicode_to_ascii(const unsigned short* str);
00165 
00166 inline unsigned short* ts_strdup(const unsigned short* str)
00167 {
00168         return wcsdup(str);
00169 }
00170 
00171 unsigned short* ts_strdup_ascii_to_unicode(const char* str);
00172 
00173 
00174 #endif /* __wcecompat__ts_string_h__ */

Generated on Mon Jun 5 10:20:48 2006 for Intelligence.kdevelop by  doxygen 1.4.6