Gammu internals  1.38.0
Unicode

Functions

size_t UnicodeLength (const unsigned char *str)
 
char * DecodeUnicodeString (const unsigned char *src)
 
char * DecodeUnicodeConsole (const unsigned char *src)
 
void DecodeUnicode (const unsigned char *src, char *dest)
 
void EncodeUnicode (unsigned char *dest, const char *src, size_t len)
 
void ReadUnicodeFile (unsigned char *Dest, const unsigned char *Source)
 
void CopyUnicodeString (unsigned char *Dest, const unsigned char *Source)
 
gboolean EncodeUTF8QuotedPrintable (char *dest, const unsigned char *src)
 
void DecodeUTF8QuotedPrintable (unsigned char *dest, const char *src, size_t len)
 
int EncodeWithUTF8Alphabet (unsigned long src, unsigned char *ret)
 
int DecodeWithUTF8Alphabet (const unsigned char *src, wchar_t *dest, size_t len)
 
gboolean DecodeHexUnicode (unsigned char *dest, const char *src, size_t len)
 
void EncodeHexUnicode (char *dest, const unsigned char *src, size_t len)
 
gboolean mywstrncmp (unsigned const char *a, unsigned const char *b, int num)
 
unsigned char * mywstrstr (unsigned const char *haystack, unsigned const char *needle)
 
gboolean mywstrncasecmp (unsigned const char *a, unsigned const char *b, int num)
 
gboolean EncodeUTF8 (char *dest, const unsigned char *src)
 
void DecodeUTF8 (unsigned char *dest, const char *src, size_t len)
 
gboolean DecodeHexBin (unsigned char *dest, const unsigned char *src, size_t len)
 

Detailed Description

Unicode manipulation functions. Please note that most of functions here rely on initialised libc char conversions, what is usually done by locales initialisation. Recommended way for doing this is calling GSM_InitLocales.

Function Documentation

§ CopyUnicodeString()

void CopyUnicodeString ( unsigned char *  Dest,
const unsigned char *  Source 
)

Copies unicode string.

Definition at line 1192 of file coding.c.

Referenced by DUMMY_AddFilePart(), DUMMY_AddFolder(), DUMMY_GetAlarm(), DUMMY_GetSMSFolders(), DUMMY_SetAlarm(), GSM_DecodeNokiaRTTLRingtone(), GSM_DecodeVCALENDAR_VTODO(), GSM_DecodeVCARD(), GSM_DecodeVNOTE(), GSM_EncodeSMS30MultiPartSMS(), GSM_EncodeVCARD(), GSM_PhonebookGetEntryName(), GSM_RingtoneConvert(), loadre(), N71_65_DecodePhonebook(), N71_65_EncodePhonebookFrame(), NOKIA_EncodeDateTime(), and VCALGetTextPart().

1193 {
1194  int j = 0;
1195 
1196  /* No need to copy if both are on same address */
1197  if (Dest == Source) return;
1198 
1199  while (Source[j]!=0x00 || Source[j+1]!=0x00) {
1200  Dest[j] = Source[j];
1201  Dest[j+1] = Source[j+1];
1202  j=j+2;
1203  }
1204  Dest[j] = 0;
1205  Dest[j+1] = 0;
1206 }

§ DecodeHexBin()

gboolean DecodeHexBin ( unsigned char *  dest,
const unsigned char *  src,
size_t  len 
)

Decode hex encoded binary text.

Definition at line 411 of file coding.c.

References DecodeWithHexBinAlphabet(), FALSE, and TRUE.

412 {
413  size_t i,current=0;
414  int low, high;
415 
416  for (i = 0; i < len/2 ; i++) {
417  low = DecodeWithHexBinAlphabet(src[i*2+1]);
418  high = DecodeWithHexBinAlphabet(src[i*2]);
419  if (low < 0 || high < 0) return FALSE;
420  dest[current++] = (high << 4) | low;
421  }
422  dest[current] = 0;
423  return TRUE;
424 }
#define FALSE
Definition: gammu-types.h:25
#define TRUE
Definition: gammu-types.h:28
int DecodeWithHexBinAlphabet(unsigned char mychar)
Definition: coding.c:361

§ DecodeHexUnicode()

gboolean DecodeHexUnicode ( unsigned char *  dest,
const char *  src,
size_t  len 
)

Decodes string from hex quoted unicode.

Definition at line 382 of file coding.c.

References DecodeWithHexBinAlphabet(), FALSE, and TRUE.

383 {
384  size_t i, current = 0;
385  int val0, val1, val2, val3;
386 
387  for (i = 0; i < len ; i += 4) {
388  val0 = DecodeWithHexBinAlphabet(src[i + 0]);
389  val1 = DecodeWithHexBinAlphabet(src[i + 1]);
390  val2 = DecodeWithHexBinAlphabet(src[i + 2]);
391  val3 = DecodeWithHexBinAlphabet(src[i + 3]);
392 
393  if (val0 < 0 || val1 < 0 || val2 < 0 || val3 < 0) {
394  return FALSE;
395  }
396 
397  dest[current++] = (val0 << 4) + val1;
398  dest[current++] = (val2 << 4) + val3;
399  }
400  dest[current++] = 0;
401  dest[current] = 0;
402 
403  return TRUE;
404 }
#define FALSE
Definition: gammu-types.h:25
#define TRUE
Definition: gammu-types.h:28
int DecodeWithHexBinAlphabet(unsigned char mychar)
Definition: coding.c:361

§ DecodeUnicode()

void DecodeUnicode ( const unsigned char *  src,
char *  dest 
)

Converts string from unicode to local charset.

Definition at line 223 of file coding.c.

References DecodeWithUnicodeAlphabet().

Referenced by DecodeUnicodeConsole(), DecodeUnicodeString(), and GSM_PackSemiOctetNumber().

224 {
225  int i=0,o=0;
226  wchar_t value, second;
227 
228  while (src[(2*i)+1]!=0x00 || src[2*i]!=0x00) {
229  value = src[i * 2] * 256 + src[i * 2 + 1];
230  /* Decode UTF-16 */
231  if (value >= 0xD800 && value <= 0xDBFF) {
232  second = src[(i + 1) * 2] * 256 + src[(i + 1) * 2 + 1];
233  if (second >= 0xDC00 && second <= 0xDFFF) {
234  i++;
235  value = ((value - 0xD800) << 10) + (second - 0xDC00) + 0x010000;
236  }
237  }
238  o += DecodeWithUnicodeAlphabet(value, dest + o);
239  i++;
240  }
241  dest[o]=0;
242 }
int DecodeWithUnicodeAlphabet(wchar_t src, unsigned char *dest)
Definition: coding.c:210

§ DecodeUnicodeConsole()

char* DecodeUnicodeConsole ( const unsigned char *  src)

Converts string to console charset.

Returns
Pointer to static string.

Definition at line 256 of file coding.c.

References _GSM_Debug_Info::coding, DecodeUnicode(), EncodeUTF8(), and GSM_global_debug.

Referenced by ReadVCALText().

257 {
258  static char dest[500];
259 
260  if (GSM_global_debug.coding[0] != 0) {
261  if (!strcmp(GSM_global_debug.coding,"utf8")) {
262  EncodeUTF8(dest, src);
263  } else {
264 #ifdef WIN32
265  setlocale(LC_ALL, GSM_global_debug.coding);
266 #endif
267  DecodeUnicode(src,dest);
268  }
269  } else {
270 #ifdef WIN32
271  setlocale(LC_ALL, ".OCP");
272 #endif
273  DecodeUnicode(src,dest);
274 #ifdef WIN32
275  setlocale(LC_ALL, ".ACP");
276 #endif
277  }
278  return dest;
279 }
const char * coding
Definition: debug.h:38
GSM_Debug_Info GSM_global_debug
Definition: debug.c:33
void DecodeUnicode(const unsigned char *src, char *dest)
Definition: coding.c:223
gboolean EncodeUTF8(char *dest, const unsigned char *src)
Definition: coding.c:1835

§ DecodeUnicodeString()

§ DecodeUTF8()

void DecodeUTF8 ( unsigned char *  dest,
const char *  src,
size_t  len 
)

Decode text from UTF-8.

Definition at line 1947 of file coding.c.

References DecodeWithUTF8Alphabet(), and EncodeWithUnicodeAlphabet().

Referenced by DecodeXMLUTF8(), and ReadVCALText().

1948 {
1949  size_t i=0,j=0,z;
1950  wchar_t ret;
1951 
1952  while (i < len) {
1953  z = DecodeWithUTF8Alphabet(src+i,&ret,len-i);
1954  if (z<2) {
1955  i+=EncodeWithUnicodeAlphabet(&src[i], &ret);
1956  } else {
1957  i+=z;
1958  }
1959  dest[j++] = (ret >> 8) & 0xff;
1960  dest[j++] = ret & 0xff;
1961  }
1962  dest[j++] = 0;
1963  dest[j] = 0;
1964 }
int DecodeWithUTF8Alphabet(const unsigned char *src, wchar_t *dest, size_t len)
Definition: coding.c:1866
int EncodeWithUnicodeAlphabet(const unsigned char *src, wchar_t *dest)
Definition: coding.c:198

§ DecodeUTF8QuotedPrintable()

void DecodeUTF8QuotedPrintable ( unsigned char *  dest,
const char *  src,
size_t  len 
)

Decodes UTF-8 quoted printable string.

Definition at line 1911 of file coding.c.

References DecodeWithHexBinAlphabet(), DecodeWithUTF8Alphabet(), EncodeWithUnicodeAlphabet(), and TRUE.

Referenced by ReadVCALText().

1912 {
1913  size_t i,j=0;
1914  int z;
1915  unsigned char mychar[10];
1916  wchar_t ret;
1917 
1918  for (i = 0; i<=len; ) {
1919  z=0;
1920  while (TRUE) {
1921  if (src[z*3+i] != '=' || z*3+i+3>len ||
1922  DecodeWithHexBinAlphabet(src[z*3+i+1])==-1 ||
1923  DecodeWithHexBinAlphabet(src[z*3+i+2])==-1) {
1924  break;
1925  }
1926  mychar[z] = 16*DecodeWithHexBinAlphabet(src[z*3+i+1])+DecodeWithHexBinAlphabet(src[z*3+i+2]);
1927  z++;
1928  /* Is it plain ASCII? */
1929  if (z == 1 && mychar[0] < 194) break;
1930  /* Do we already have valid UTF-8 char? */
1931  if (DecodeWithUTF8Alphabet(mychar, &ret, z) == z) break;
1932  }
1933  if (z>0) {
1934  i += z * 3;
1935  /* we ignore wrong sequence */
1936  if (DecodeWithUTF8Alphabet(mychar,&ret,z)==0) continue;
1937  } else {
1938  i+=EncodeWithUnicodeAlphabet(&src[i], &ret);
1939  }
1940  dest[j++] = (ret >> 8) & 0xff;
1941  dest[j++] = ret & 0xff;
1942  }
1943  dest[j++] = 0;
1944  dest[j] = 0;
1945 }
int DecodeWithUTF8Alphabet(const unsigned char *src, wchar_t *dest, size_t len)
Definition: coding.c:1866
int EncodeWithUnicodeAlphabet(const unsigned char *src, wchar_t *dest)
Definition: coding.c:198
#define TRUE
Definition: gammu-types.h:28
int DecodeWithHexBinAlphabet(unsigned char mychar)
Definition: coding.c:361

§ DecodeWithUTF8Alphabet()

int DecodeWithUTF8Alphabet ( const unsigned char *  src,
wchar_t dest,
size_t  len 
)

Decodes string from UTF-8.

Definition at line 1866 of file coding.c.

Referenced by DecodeUTF8(), and DecodeUTF8QuotedPrintable().

1867 {
1868  if (len < 1) return 0;
1869  if (src[0] < 128) {
1870  (*dest) = src[0];
1871  return 1;
1872  }
1873  if (src[0] < 194) return 0;
1874  if (src[0] < 224) {
1875  if (len < 2) return 0;
1876  (*dest) = (src[0]-192)*64 + (src[1]-128);
1877  return 2;
1878  }
1879  if (src[0] < 240) {
1880  if (len < 3) return 0;
1881  (*dest) = (src[0]-224)*4096 + (src[1]-128)*64 + (src[2]-128);
1882  return 3;
1883  }
1884  return 0;
1885 }

§ EncodeHexUnicode()

void EncodeHexUnicode ( char *  dest,
const unsigned char *  src,
size_t  len 
)

Encodes string to hex quoted unicode.

Definition at line 406 of file coding.c.

References EncodeHexBin().

407 {
408  EncodeHexBin(dest, src, len * 2);
409 }
void EncodeHexBin(char *dest, const unsigned char *src, size_t len)
Definition: coding.c:426

§ EncodeUnicode()

void EncodeUnicode ( unsigned char *  dest,
const char *  src,
size_t  len 
)

Encodes string from local charset to unicode.

Definition at line 301 of file coding.c.

References EncodeWithUnicodeAlphabet().

Referenced by AddEMSText(), DUMMY_DialService(), DUMMY_GetFilePart(), DUMMY_GetFolderListing(), DUMMY_GetNetworkInfo(), DUMMY_GetNextFileFolder(), DUMMY_GetSMSFolders(), DUMMY_GetWAPBookmark(), DUMMY_Initialise(), DUMMY_PreAPICall(), DUMMY_SendFilePart(), GSM_DecodeMMSFileToMultiPart(), GSM_DecodeMultiPartSMS(), GSM_DecodeNokiaProfile(), GSM_DecodeNokiaRTTLRingtone(), GSM_DecodeSMSStatusReportData(), GSM_EncodeMultiPartSMS(), GSM_GetCountryName(), GSM_GetNetworkName(), GSM_ReadBitmapFile(), GSM_ReadRingtoneFile(), GSM_TweakInternationalNumber(), GSM_UnpackSemiOctetNumber(), loadbin(), loadpuremidi(), loadre(), loadrttl(), N71_65_DecodePhonebook(), NOKIA_EncodeDateTime(), NOKIA_GetDefaultCallerGroupName(), PHONE_FindDataFile(), and PHONE_GetSMSFolders().

302 {
303  size_t i_len = 0, o_len;
304  wchar_t wc;
305 
306  for (o_len = 0; i_len < len; o_len++) {
307  i_len += EncodeWithUnicodeAlphabet(&src[i_len], &wc);
308  dest[o_len*2] = (wc >> 8) & 0xff;
309  dest[(o_len*2)+1] = wc & 0xff;
310  }
311  dest[o_len*2] = 0;
312  dest[(o_len*2)+1] = 0;
313 }
int EncodeWithUnicodeAlphabet(const unsigned char *src, wchar_t *dest)
Definition: coding.c:198

§ EncodeUTF8()

gboolean EncodeUTF8 ( char *  dest,
const unsigned char *  src 
)

Encode text to UTF-8.

Definition at line 1835 of file coding.c.

References EncodeWithUTF8Alphabet(), FALSE, TRUE, and UnicodeLength().

Referenced by DecodeUnicodeConsole(), and NOKIA_EncodeWAPBookmarkSMSText().

1836 {
1837  size_t i, j=0, z, len;
1838  unsigned char mychar[8];
1839  gboolean retval = FALSE;
1840  unsigned long value, second;
1841 
1842  len = UnicodeLength(src);
1843 
1844  for (i = 0; i < len; i++) {
1845  value = src[i * 2] * 256 + src[i * 2 + 1];
1846  /* Decode UTF-16 */
1847  if (value >= 0xD800 && value <= 0xDBFF && (i + 1) < len) {
1848  second = src[(i + 1) * 2] * 256 + src[(i + 1) * 2 + 1];
1849  if (second >= 0xDC00 && second <= 0xDFFF) {
1850  i++;
1851  value = ((value - 0xD800) << 10) + (second - 0xDC00) + 0x010000;
1852  }
1853  }
1854  z = EncodeWithUTF8Alphabet(value, mychar);
1855  memcpy(dest + j, mychar, z);
1856  j += z;
1857  if (z > 1) {
1858  retval = TRUE;
1859  }
1860  }
1861  dest[j] = 0;
1862  return retval;
1863 }
size_t UnicodeLength(const unsigned char *str)
Definition: coding.c:186
int gboolean
Definition: gammu-types.h:23
#define FALSE
Definition: gammu-types.h:25
#define TRUE
Definition: gammu-types.h:28
int EncodeWithUTF8Alphabet(unsigned long src, unsigned char *ret)
Definition: coding.c:1752

§ EncodeUTF8QuotedPrintable()

gboolean EncodeUTF8QuotedPrintable ( char *  dest,
const unsigned char *  src 
)

Encodes string to UTF-8 quoted printable.

Definition at line 1794 of file coding.c.

References EncodeWithUTF8Alphabet(), FALSE, TRUE, and UnicodeLength().

Referenced by VC_StoreText().

1795 {
1796  size_t i, j=0, z, w, len;
1797  unsigned char mychar[8];
1798  gboolean retval = FALSE;
1799  unsigned long value, second;
1800 
1801  len = UnicodeLength(src);
1802 
1803  for (i = 0; i < len; i++) {
1804  value = src[i * 2] * 256 + src[i * 2 + 1];
1805  /* Decode UTF-16 */
1806  if (value >= 0xD800 && value <= 0xDBFF && (i + 1) < len) {
1807  second = src[(i + 1) * 2] * 256 + src[(i + 1) * 2 + 1];
1808  if (second >= 0xDC00 && second <= 0xDFFF) {
1809  value = ((value - 0xD800) << 10) + (second - 0xDC00) + 0x010000;
1810  }
1811  }
1812  z = EncodeWithUTF8Alphabet(value, mychar);
1813  if (z == 1 && mychar[0] < 32) {
1814  /* Need quoted printable for chars < 32 */
1815  sprintf(dest + j, "=%02X", mychar[0]);
1816  j = j + 3;
1817  } else if (z == 1) {
1818  memcpy(dest + j, mychar, z);
1819  j += z;
1820  } else {
1821  /* Quoted printable unicode */
1822  for (w = 0; w < z; w++) {
1823  sprintf(dest + j, "=%02X", mychar[w]);
1824  j = j + 3;
1825  }
1826  if (z > 1) {
1827  retval = TRUE;
1828  }
1829  }
1830  }
1831  dest[j] = 0;
1832  return retval;
1833 }
size_t UnicodeLength(const unsigned char *str)
Definition: coding.c:186
int gboolean
Definition: gammu-types.h:23
#define FALSE
Definition: gammu-types.h:25
#define TRUE
Definition: gammu-types.h:28
int EncodeWithUTF8Alphabet(unsigned long src, unsigned char *ret)
Definition: coding.c:1752

§ EncodeWithUTF8Alphabet()

int EncodeWithUTF8Alphabet ( unsigned long  src,
unsigned char *  ret 
)

Encodes string to UTF-8.

Definition at line 1752 of file coding.c.

Referenced by DecodeXMLUTF8(), EncodeUTF8(), and EncodeUTF8QuotedPrintable().

1753 {
1754  if (src < 0x80) {
1755  ret[0] = src;
1756  return 1;
1757  } else if (src < 0x800) {
1758  ret[0] = 192 + (src / 64);
1759  ret[1] = 128 + (src % 64);
1760  return 2;
1761  } else if (src < 0x10000) {
1762  ret[0] = 224 + (src / (64 * 64));
1763  ret[1] = 128 + ((src / 64) % 64);
1764  ret[2] = 128 + (src % 64);
1765  return 3;
1766  } else if (src < 0x200000) {
1767  ret[0] = 240 + (src / (64 * 64 * 64));
1768  ret[1] = 128 + ((src / (64 * 64)) % 64);
1769  ret[2] = 128 + ((src / 64) % 64);
1770  ret[3] = 128 + (src % 64);
1771  return 4;
1772  } else if (src < 0x4000000) {
1773  ret[0] = 248 + (src / (64 * 64 * 64 * 64));
1774  ret[1] = 128 + ((src / (64 * 64 * 64)) % 64);
1775  ret[2] = 128 + ((src / (64 * 64)) % 64);
1776  ret[3] = 128 + ((src / 64) % 64);
1777  ret[4] = 128 + (src % 64);
1778  return 5;
1779  } else if (src < 0x80000000L) {
1780  ret[0] = 252 + (src / (64 * 64 * 64 * 64 * 64));
1781  ret[1] = 128 + ((src / (64 * 64 * 64 * 64)) % 64);
1782  ret[2] = 128 + ((src / (64 * 64 * 64)) % 64);
1783  ret[3] = 128 + ((src / (64 * 64)) % 64);
1784  ret[4] = 128 + ((src / 64) % 64);
1785  ret[5] = 128 + (src % 64);
1786  return 6;
1787  }
1788 
1789  ret[0] = src;
1790  return 1;
1791 }

§ mywstrncasecmp()

gboolean mywstrncasecmp ( unsigned const char *  a,
unsigned const char *  b,
int  num 
)

Compares two unicode strings case insensitive.

Definition at line 1437 of file coding.c.

References FALSE, and TRUE.

Referenced by GSM_DecodeVCALENDAR_VTODO(), INI_FindLastSectionEntry(), and INI_GetValue().

1438 {
1439  int i;
1440  wchar_t wc,wc2;
1441 
1442  if (a == NULL || b == NULL) return FALSE;
1443 
1444  if (num == 0) num = -1;
1445 
1446  for (i = 0; i != num; i++) {
1447  if ((a[i*2] == 0x00 && a[i*2+1] == 0x00) && (b[i*2] == 0x00 && b[i*2+1] == 0x00)) return TRUE;
1448  if ((a[i*2] == 0x00 && a[i*2+1] == 0x00) || (b[i*2] == 0x00 && b[i*2+1] == 0x00)) return FALSE;
1449  wc = a[i*2+1] | (a[i*2] << 8);
1450  wc2 = b[i*2+1] | (b[i*2] << 8);
1451  if (towlower(wc) != towlower(wc2)) return FALSE;
1452  }
1453  return TRUE;
1454 }
#define FALSE
Definition: gammu-types.h:25
#define TRUE
Definition: gammu-types.h:28

§ mywstrncmp()

gboolean mywstrncmp ( unsigned const char *  a,
unsigned const char *  b,
int  num 
)

Compares two unicode strings.

Definition at line 1457 of file coding.c.

References FALSE, and TRUE.

Referenced by N71_65_EncodePhonebookFrame().

1458 {
1459  int i=0;
1460 
1461  while (1) {
1462  if (a[i*2] != b[i*2] || a[i*2+1] != b[i*2+1]) return FALSE;
1463  if (a[i*2] == 0x00 && a[i*2+1] == 0x00) return TRUE;
1464  i++;
1465  if (num == i) return TRUE;
1466  }
1467 }
#define FALSE
Definition: gammu-types.h:25
#define TRUE
Definition: gammu-types.h:28

§ mywstrstr()

unsigned char* mywstrstr ( unsigned const char *  haystack,
unsigned const char *  needle 
)

Locates unicode substring.

Definition at line 1508 of file coding.c.

References tolowerwchar.

1509 {
1510 /* One crazy define to convert unicode used in Gammu to standard wchar_t */
1511 #define tolowerwchar(x) (towlower((wchar_t)( (((&(x))[0] & 0xff) << 8) | (((&(x))[1] & 0xff)) )))
1512  register wint_t a, b, c;
1513  register const unsigned char *rhaystack, *rneedle;
1514 
1515 
1516  if ((b = tolowerwchar(*needle)) != L'\0') {
1517  haystack -= 2; /* possible ANSI violation */
1518  do {
1519  haystack += 2;
1520  if ((c = tolowerwchar(*haystack)) == L'\0')
1521  goto ret0;
1522  } while (c != b);
1523 
1524  needle += 2;
1525  if ((c = tolowerwchar(*needle)) == L'\0')
1526  goto foundneedle;
1527  needle += 2;
1528  goto jin;
1529 
1530  for (;;) {
1531  do {
1532  haystack += 2;
1533  if ((a = tolowerwchar(*haystack)) == L'\0')
1534  goto ret0;
1535  if (a == b)
1536  break;
1537  haystack += 2;
1538  if ((a = tolowerwchar(*haystack)) == L'\0')
1539  goto ret0;
1540 shloop: ;
1541  } while (a != b);
1542 
1543 jin: haystack += 2;
1544  if ((a = tolowerwchar(*haystack)) == L'\0')
1545  goto ret0;
1546 
1547  if (a != c)
1548  goto shloop;
1549 
1550  rhaystack = haystack + 2;
1551  haystack -= 2;
1552  rneedle = needle;
1553  if (tolowerwchar(*rhaystack) == (a = tolowerwchar(*rneedle)))
1554  do {
1555  if (a == L'\0')
1556  goto foundneedle;
1557  rhaystack += 2;
1558  needle += 2;
1559  if (tolowerwchar(*rhaystack) != (a = tolowerwchar(*needle)))
1560  break ;
1561  if (a == L'\0')
1562  goto foundneedle;
1563  rhaystack += 2;
1564  needle += 2;
1565  } while (tolowerwchar(*rhaystack) == (a = tolowerwchar(*needle)));
1566 
1567  needle = rneedle; /* took the register-poor approach */
1568 
1569  if (a == L'\0')
1570  break;
1571  }
1572  }
1573 foundneedle:
1574  return (unsigned char *)haystack;
1575 ret0:
1576  return NULL;
1577 #undef tolowerwchar
1578 }
int wint_t
Definition: coding.h:27
#define tolowerwchar(x)

§ ReadUnicodeFile()

void ReadUnicodeFile ( unsigned char *  Dest,
const unsigned char *  Source 
)

Decodes unicode file data with byte order mark (BOM).

Definition at line 1227 of file coding.c.

1228 {
1229  int j = 0, current = 0;
1230 
1231  if (Source[0] == 0xFF && Source[1] == 0xFE) j = 2;
1232  if (Source[0] == 0xFE && Source[1] == 0xFF) j = 2;
1233 
1234  while (Source[j]!=0x00 || Source[j+1]!=0x00) {
1235  if (Source[0] == 0xFF) {
1236  Dest[current++] = Source[j+1];
1237  Dest[current++] = Source[j];
1238  } else {
1239  Dest[current++] = Source[j];
1240  Dest[current++] = Source[j+1];
1241  }
1242  j=j+2;
1243  }
1244  Dest[current++] = 0;
1245  Dest[current] = 0;
1246 }

§ UnicodeLength()