/[winpt]/trunk/Src/wptUTF8.cpp
ViewVC logotype

Diff of /trunk/Src/wptUTF8.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 187 by twoaday, Wed Mar 22 11:04:20 2006 UTC revision 201 by twoaday, Sat Apr 22 18:30:24 2006 UTC
# Line 1  Line 1 
1  /* wptUTF8.cpp - UTF8 conversation  /* wptUTF8.cpp - UTF8 conversation
2   *      Copyright (C) 2002, 2004, 2005, 2006 Timo Schulz   *      Copyright (C) 2002, 2004, 2005, 2006 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
# Line 43  native_to_utf8 (const char *string) Line 43  native_to_utf8 (const char *string)
43      if (n < 0)      if (n < 0)
44          return NULL;          return NULL;
45    
46      result = (wchar_t*)malloc ((n+1) * sizeof *result);      result = new wchar_t[n+1];
47      if (!result)      if (!result)
48          BUG (0);          BUG (0);
49    
50      n = MultiByteToWideChar (GetACP (), 0, string, -1, result, n);      n = MultiByteToWideChar (GetACP (), 0, string, -1, result, n);
51      if (n < 0) {      if (n < 0) {
52          free (result);          free_if_alloc (result);
53          return NULL;          return NULL;
54      }      }
55    
# Line 57  native_to_utf8 (const char *string) Line 57  native_to_utf8 (const char *string)
57      if (n < 0)      if (n < 0)
58          return NULL;          return NULL;
59    
60      native = (char*)malloc (n+1);      native = new char[n+1];
61      if (!native)      if (!native)
62          BUG (0);          BUG (0);
63    
64      n = WideCharToMultiByte (CP_UTF8, 0, result, -1, native, n, NULL, NULL);      n = WideCharToMultiByte (CP_UTF8, 0, result, -1, native, n, NULL, NULL);
65      if (n < 0) {      if (n < 0) {
66          free (result);          free_if_alloc (result);
67          return NULL;          return NULL;
68      }      }
69    
70      free (result);      free_if_alloc (result);
71      return native;      return native;
72  }  }
73    
# Line 113  utf8_to_native (const char *string) Line 113  utf8_to_native (const char *string)
113  }  }
114    
115    
116    /* Return -1 if the string contains any 8-bit characters. */
117  int  int
118  is_8bit_string (const char * str)  is_8bit_string (const char *str)
119  {  {
120      size_t i;      size_t i;
121    

Legend:
Removed from v.187  
changed lines
  Added in v.201

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26