44 inline char *
stdstr(
char **ipstr,
const char *istr,
unsigned int memPadFactor = 1) {
48 int len = (int)strlen(istr) + 1;
49 *ipstr =
new char [ len * memPadFactor ];
50 memcpy(*ipstr, istr, len);
67 #define SW_toupper(c) SW_toupper_array[(unsigned char)c]
75 #define SW_tolower(c) SW_tolower_array[(unsigned char)c]
104 if ((**buf >> 6) == 2) {
112 if ((**buf & 32) == 0) { subsequent = 1; }
113 else if ((**buf & 16) == 0) { subsequent = 2; }
114 else if ((**buf & 8) == 0) { subsequent = 3; }
115 else if ((**buf & 4) == 0) { subsequent = 4; }
116 else if ((**buf & 2) == 0) { subsequent = 5; }
117 else if ((**buf & 1) == 0) { subsequent = 6; }
120 ch = **buf & (0xFF>>(subsequent + 1));
122 for (
int i = 1; i <= subsequent; ++i) {
126 if (((*buf)[i] >> 6) != 2) {
131 ch |= (*buf)[i] & 63;
133 *buf += (subsequent+1);
135 if (!skipValidation) {
137 if (subsequent > 3) ch = 0;
139 if (ch > 0x1FFFFF) ch = 0;
141 if (ch > 0x10FFFF) ch = 0;
143 if (ch < 0x80 && subsequent > 0) ch = 0;
144 if (ch < 0x800 && subsequent > 1) ch = 0;
145 if (ch < 0x10000 && subsequent > 2) ch = 0;
146 if (ch < 0x200000 && subsequent > 3) ch = 0;
166 unsigned long base = appendTo->
size();
169 if (uchar > 0x10FFFF) uchar = 0xFFFD;
170 char bytes = uchar < 0x80 ? 1 : uchar < 0x800 ? 2 : uchar < 0x10000 ? 3 : 4;
174 (*appendTo)[
base ] = (
unsigned char)uchar;
177 (*appendTo)[base+1] = (
unsigned char)(0x80 | (uchar & 0x3f));
179 (*appendTo)[
base ] = (
unsigned char)(0xc0 | (uchar & 0x1f));
182 (*appendTo)[base+2] = (
unsigned char)(0x80 | (uchar & 0x3f));
184 (*appendTo)[base+1] = (
unsigned char)(0x80 | (uchar & 0x3f));
186 (*appendTo)[
base ] = (
unsigned char)(0xe0 | (uchar & 0x0f));
189 (*appendTo)[base+3] = (
unsigned char)(0x80 | (uchar & 0x3f));
191 (*appendTo)[base+2] = (
unsigned char)(0x80 | (uchar & 0x3f));
193 (*appendTo)[base+1] = (
unsigned char)(0x80 | (uchar & 0x3f));
195 (*appendTo)[
base ] = (
unsigned char)(0xf0 | (uchar & 0x07));
#define SWORD_NAMESPACE_START
SWBuf assureValidUTF8(const char *buf)
const unsigned char SW_tolower_array[256]
SWORD_NAMESPACE_START const unsigned char SW_toupper_array[256]
SWBuf wcharToUTF8(const wchar_t *buf)
SWBuf utf8ToWChar(const char *buf)
int stricmp(const char *s1, const char *s2)
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
const char * stristr(const char *s1, const char *s2)
unsigned long size() const
SWBuf * getUTF8FromUniChar(SW_u32 uchar, SWBuf *appendTo)
char * strstrip(char *istr)
int strnicmp(const char *s1, const char *s2, int len)
#define SWORD_NAMESPACE_END
SW_u32 getUniCharFromUTF8(const unsigned char **buf, bool skipValidation=false)
void setSize(unsigned long len)