Rise
The Vieneo Province
StringUtilities.h
Go to the documentation of this file.
1 #pragma once
2 
3 inline void UTF8_to_WChar(wchar_t* res, const char *string) {
4  long b = 0,
5  c = 0;
6  if ((unsigned char)string[0] == 0xEF && (unsigned char)string[1] == 0xBB && (unsigned char)string[2] == 0xBF)
7  string += 3;
8  for (const char *a = string; *a; a++)
9  if (((unsigned char)*a) < 128 || (*a & 192) == 192)
10  c++;
11  res[c] = 0;
12  for (unsigned char *a = (unsigned char*)string; *a; a++) {
13  if (!(*a & 128))
14  //Byte represents an ASCII character. Direct copy will do.
15  res[b] = *a;
16  else if ((*a & 192) == 128)
17  //Byte is the middle of an encoded character. Ignore.
18  continue;
19  else if ((*a & 224) == 192)
20  //Byte represents the start of an encoded character in the range
21  //U+0080 to U+07FF
22  res[b] = ((*a & 31) << 6) | a[1] & 63;
23  else if ((*a & 240) == 224)
24  //Byte represents the start of an encoded character in the range
25  //U+07FF to U+FFFF
26  res[b] = ((*a & 15) << 12) | ((a[1] & 63) << 6) | a[2] & 63;
27  else if ((*a & 248) == 240) {
28  //Byte represents the start of an encoded character beyond the
29  //U+FFFF limit of 16-bit integers
30  res[b] = '?';
31  }
32  b++;
33  }
34 }
35 
36 inline bool IsNullOrWhitespace(const WCHAR* string)
37 {
38  for (size_t index = 0; index < wcslen(string); index++)
39  {
40  if (string[index] != ' ')
41  return false;
42  }
43  return true;
44 }
void UTF8_to_WChar(wchar_t *res, const char *string)
bool IsNullOrWhitespace(const WCHAR *string)