foobar2000 SDK  2015-01-14
Data Structures | Typedefs | Enumerations | Functions
pfc::stringcvt Namespace Reference

Data Structures

class  char_buffer_t
 
class  string_ansi_from_utf8
 
class  string_ansi_from_wide
 
class  string_ascii_from_utf8
 
class  string_codepage_from_utf8
 
class  string_codepage_from_wide_t
 
class  string_utf8_from_ansi
 
class  string_utf8_from_codepage
 
class  string_utf8_from_os_ex
 
class  string_utf8_from_wide_t
 
class  string_utf8_from_win1252_t
 
class  string_wide_from_ansi
 
class  string_wide_from_codepage_t
 
class  string_wide_from_utf8_t
 
class  string_wide_from_win1252_t
 
class  string_win1252_from_utf8_t
 
class  string_win1252_from_wide_t
 

Typedefs

typedef string_win1252_from_utf8 string_ansi_from_utf8
 
typedef string_win1252_from_wide string_ansi_from_wide
 
typedef string_codepage_from_wide_t string_codepage_from_wide
 
typedef string_wide_from_utf8 string_os_from_utf8
 
typedef string_wide_from_utf8_fast string_os_from_utf8_fast
 
typedef string_utf8_from_win1252 string_utf8_from_ansi
 
typedef string_utf8_from_wide string_utf8_from_os
 
typedef string_utf8_from_wide_t string_utf8_from_wide
 
typedef string_utf8_from_win1252_t string_utf8_from_win1252
 
typedef string_wide_from_win1252 string_wide_from_ansi
 
typedef string_wide_from_codepage_t string_wide_from_codepage
 
typedef string_wide_from_utf8_t string_wide_from_utf8
 
typedef string_wide_from_utf8_t< alloc_fast_aggressivestring_wide_from_utf8_fast
 
typedef string_wide_from_win1252_t string_wide_from_win1252
 
typedef string_win1252_from_utf8_t string_win1252_from_utf8
 
typedef string_win1252_from_wide_t string_win1252_from_wide
 

Enumerations

enum  { codepage_system = CP_ACP, codepage_ascii = 20127, codepage_iso_8859_1 = 28591 }
 

Functions

char charToASCII (unsigned c)
 
t_size convert_ansi_to_wide (wchar_t *p_out, t_size p_out_size, const char *p_source, t_size p_source_size)
 
t_size convert_codepage_to_wide (unsigned p_codepage, wchar_t *p_out, t_size p_out_size, const char *p_source, t_size p_source_size)
 
t_size convert_utf8_to_ascii (char *p_out, t_size p_out_size, const char *p_in, t_size p_in_size)
 
t_size convert_utf8_to_wide (wchar_t *p_out, t_size p_out_size, const char *p_source, t_size p_source_size)
 
t_size convert_utf8_to_wide_unchecked (wchar_t *p_out, const char *p_in)
 
t_size convert_utf8_to_win1252 (char *p_out, t_size p_out_size, const char *p_in, t_size p_in_size)
 
t_size convert_wide_to_ansi (char *p_out, t_size p_out_size, const wchar_t *p_source, t_size p_source_size)
 
t_size convert_wide_to_codepage (unsigned p_codepage, char *p_out, t_size p_out_size, const wchar_t *p_source, t_size p_source_size)
 
t_size convert_wide_to_utf8 (char *p_out, t_size p_out_size, const wchar_t *p_source, t_size p_source_size)
 
t_size convert_wide_to_win1252 (char *p_out, t_size p_out_size, const wchar_t *p_in, t_size p_in_size)
 
t_size convert_win1252_to_utf8 (char *p_out, t_size p_out_size, const char *p_in, t_size p_in_size)
 
t_size convert_win1252_to_wide (wchar_t *p_out, t_size p_out_size, const char *p_in, t_size p_in_size)
 
t_size estimate_ansi_to_wide (const char *p_source, t_size p_source_size)
 
t_size estimate_codepage_to_wide (unsigned p_codepage, const char *p_source, t_size p_source_size)
 
t_size estimate_utf8_to_ascii (const char *p_source, t_size p_source_size)
 
t_size estimate_utf8_to_wide (const char *p_in)
 
t_size estimate_utf8_to_wide (const char *p_source, t_size p_source_size)
 
t_size estimate_utf8_to_wide_quick (t_size sourceLen)
 
t_size estimate_utf8_to_wide_quick (const char *source)
 
t_size estimate_utf8_to_wide_quick (const char *source, t_size sourceLen)
 
t_size estimate_utf8_to_win1252 (const char *p_in, t_size p_in_size)
 
t_size estimate_wide_to_ansi (const wchar_t *p_source, t_size p_source_size)
 
t_size estimate_wide_to_codepage (unsigned p_codepage, const wchar_t *p_source, t_size p_source_size)
 
t_size estimate_wide_to_utf8 (const wchar_t *p_source, t_size p_source_size)
 
t_size estimate_wide_to_win1252 (const wchar_t *p_in, t_size p_in_size)
 
t_size estimate_win1252_to_utf8 (const char *p_in, t_size p_in_size)
 
t_size estimate_win1252_to_wide (const char *p_source, t_size p_source_size)
 
template<typename t_char >
const t_char * null_string_t ()
 
template<>
const char * null_string_t< char > ()
 
template<>
const wchar_t * null_string_t< wchar_t > ()
 
template<typename t_char >
bool string_is_empty_t (const t_char *p_string, t_size p_string_size=~0)
 
template<typename t_char >
t_size strlen_t (const t_char *p_string, t_size p_string_size=~0)
 

Typedef Documentation

Definition at line 552 of file string_conv.h.

Definition at line 550 of file string_conv.h.

Definition at line 402 of file string_conv.h.

Definition at line 516 of file string_conv.h.

Definition at line 518 of file string_conv.h.

Definition at line 553 of file string_conv.h.

Definition at line 517 of file string_conv.h.

Definition at line 113 of file string_conv.h.

Definition at line 230 of file string_conv.h.

Definition at line 551 of file string_conv.h.

Definition at line 378 of file string_conv.h.

Definition at line 160 of file string_conv.h.

Definition at line 161 of file string_conv.h.

Definition at line 184 of file string_conv.h.

Definition at line 253 of file string_conv.h.

Definition at line 207 of file string_conv.h.

Enumeration Type Documentation

anonymous enum
Enumerator
codepage_system 
codepage_ascii 
codepage_iso_8859_1 

Definition at line 279 of file string_conv.h.

Function Documentation

char pfc::stringcvt::charToASCII ( unsigned  c)

Definition at line 144 of file string_conv.cpp.

144  {
145  if (c < 128) return (char)c;
146  unsigned lo = 0, hi = PFC_TABSIZE(g_asciiMap);
147  while( lo < hi ) {
148  const unsigned mid = (lo + hi) / 2;
149  const asciiMap_t entry = g_asciiMap[mid];
150  if ( c > entry.from ) {
151  lo = mid + 1;
152  } else if (c < entry.from) {
153  hi = mid;
154  } else {
155  return (char)entry.to;
156  }
157  }
158  return '?';
159  }
t_size pfc::stringcvt::convert_ansi_to_wide ( wchar_t *  p_out,
t_size  p_out_size,
const char *  p_source,
t_size  p_source_size 
)
inline

Converts string from system codepage to wide character.

Parameters
p_outOutput buffer, receives converted string, with null terminator.
p_sourceString to convert.
p_source_sizeNumber of characters to read from p_source. If reading stops if null terminator is encountered earlier.
p_out_sizeSize of output buffer, in characters. If converted string is too long, it will be truncated. Null terminator is always written, unless p_out_size is zero.
Returns
Number of characters written, not counting null terminator.

Definition at line 326 of file string_conv.h.

326  {
327  return convert_codepage_to_wide(codepage_system,p_out,p_out_size,p_source,p_source_size);
328  }
t_size convert_codepage_to_wide(unsigned p_codepage, wchar_t *p_out, t_size p_out_size, const char *p_source, t_size p_source_size)
Converts string from specified codepage to wide character.
t_size pfc::stringcvt::convert_codepage_to_wide ( unsigned  p_codepage,
wchar_t *  p_out,
t_size  p_out_size,
const char *  p_source,
t_size  p_source_size 
)

Converts string from specified codepage to wide character.

Parameters
p_outOutput buffer, receives converted string, with null terminator.
p_codepageCodepage ID of source string.
p_sourceString to convert.
p_source_sizeNumber of characters to read from p_source. If reading stops if null terminator is encountered earlier.
p_out_sizeSize of output buffer, in characters. If converted string is too long, it will be truncated. Null terminator is always written, unless p_out_size is zero.
Returns
Number of characters written, not counting null terminator.

Definition at line 428 of file string_conv.cpp.

428  {
429  if (p_out_size == 0) return 0;
430  memset(p_out,0,p_out_size * sizeof(*p_out));
431  MultiByteToWideChar(p_codepage,0,p_source,p_source_size,p_out,p_out_size);
432  p_out[p_out_size-1] = 0;
433  return wcslen(p_out);
434  }
t_size pfc::stringcvt::convert_utf8_to_ascii ( char *  p_out,
t_size  p_out_size,
const char *  p_in,
t_size  p_in_size 
)

Definition at line 400 of file string_conv.cpp.

400  {
401  const t_size insize = p_in_size;
402  t_size inptr = 0;
403  string_writer_t<char> writer(p_out,p_out_size);
404 
405  while(inptr < insize && !writer.is_overrun()) {
406  unsigned newchar = 0;
407  t_size delta = utf8_decode_char(p_in + inptr,newchar,insize - inptr);
408  if (delta == 0 || newchar == 0) break;
409  PFC_ASSERT(inptr + delta <= insize);
410  inptr += delta;
411 
412  writer.write( charToASCII(newchar) );
413  }
414 
415  return writer.finalize();
416  }
size_t t_size
Definition: int_types.h:48
t_size utf8_decode_char(const char *src, unsigned &out, t_size src_bytes)
Definition: utf8.cpp:64
char charToASCII(unsigned c)
t_size pfc::stringcvt::convert_utf8_to_wide ( wchar_t *  p_out,
t_size  p_out_size,
const char *  p_source,
t_size  p_source_size 
)

Converts UTF-8 characters to wide character.

Parameters
p_outOutput buffer, receives converted string, with null terminator.
p_out_sizeSize of output buffer, in characters. If converted string is too long, it will be truncated. Null terminator is always written, unless p_out_size is zero.
p_sourceString to convert.
p_source_sizeNumber of characters to read from p_source. If reading stops if null terminator is encountered earlier.
Returns
Number of characters written, not counting null terminator.

Definition at line 161 of file string_conv.cpp.

161  {
162  const t_size insize = p_in_size;
163  t_size inptr = 0;
164  string_writer_t<wchar_t> writer(p_out,p_out_size);
165 
166  while(inptr < insize && !writer.is_overrun()) {
167  unsigned newchar = 0;
168  t_size delta = utf8_decode_char(p_in + inptr,newchar,insize - inptr);
169  if (delta == 0 || newchar == 0) break;
170  PFC_ASSERT(inptr + delta <= insize);
171  inptr += delta;
172  writer.write_as_wide(newchar);
173  }
174 
175  return writer.finalize();
176  }
size_t t_size
Definition: int_types.h:48
t_size utf8_decode_char(const char *src, unsigned &out, t_size src_bytes)
Definition: utf8.cpp:64
t_size pfc::stringcvt::convert_utf8_to_wide_unchecked ( wchar_t *  p_out,
const char *  p_in 
)

Definition at line 178 of file string_conv.cpp.

178  {
179  t_size inptr = 0;
180  string_writer_t<wchar_t,false> writer(p_out,~0);
181 
182  while(!writer.is_overrun()) {
183  unsigned newchar = 0;
184  t_size delta = utf8_decode_char(p_in + inptr,newchar);
185  if (delta == 0 || newchar == 0) break;
186  inptr += delta;
187  writer.write_as_wide(newchar);
188  }
189 
190  return writer.finalize();
191  }
size_t t_size
Definition: int_types.h:48
t_size utf8_decode_char(const char *src, unsigned &out, t_size src_bytes)
Definition: utf8.cpp:64
t_size pfc::stringcvt::convert_utf8_to_win1252 ( char *  p_out,
t_size  p_out_size,
const char *  p_in,
t_size  p_in_size 
)

Definition at line 342 of file string_conv.cpp.

342  {
343  const t_size insize = p_in_size;
344  t_size inptr = 0;
345  string_writer_t<char> writer(p_out,p_out_size);
346 
347  while(inptr < insize && !writer.is_overrun()) {
348  unsigned newchar = 0;
349  t_size delta = utf8_decode_char(p_in + inptr,newchar,insize - inptr);
350  if (delta == 0 || newchar == 0) break;
351  PFC_ASSERT(inptr + delta <= insize);
352  inptr += delta;
353 
354  char temp;
355  if (!charExport1252( temp, newchar )) temp = '?';
356  writer.write( temp );
357  }
358 
359  return writer.finalize();
360  }
size_t t_size
Definition: int_types.h:48
t_size utf8_decode_char(const char *src, unsigned &out, t_size src_bytes)
Definition: utf8.cpp:64
t_size pfc::stringcvt::convert_wide_to_ansi ( char *  p_out,
t_size  p_out_size,
const wchar_t *  p_source,
t_size  p_source_size 
)
inline

Converts string from wide character to system codepage.

Parameters
p_outOutput buffer, receives converted string, with null terminator.
p_out_sizeSize of output buffer, in characters. If converted string is too long, it will be truncated. Null terminator is always written, unless p_out_size is zero.
p_sourceString to convert.
p_source_sizeNumber of characters to read from p_source. If reading stops if null terminator is encountered earlier.
Returns
Number of characters written, not counting null terminator.

Definition at line 344 of file string_conv.h.

344  {
345  return convert_wide_to_codepage(codepage_system,p_out,p_out_size,p_source,p_source_size);
346  }
t_size convert_wide_to_codepage(unsigned p_codepage, char *p_out, t_size p_out_size, const wchar_t *p_source, t_size p_source_size)
Converts string from wide character to specified codepage.
t_size pfc::stringcvt::convert_wide_to_codepage ( unsigned  p_codepage,
char *  p_out,
t_size  p_out_size,
const wchar_t *  p_source,
t_size  p_source_size 
)

Converts string from wide character to specified codepage.

Parameters
p_codepageCodepage ID of source string.
p_outOutput buffer, receives converted string, with null terminator.
p_out_sizeSize of output buffer, in characters. If converted string is too long, it will be truncated. Null terminator is always written, unless p_out_size is zero.
p_sourceString to convert.
p_source_sizeNumber of characters to read from p_source. If reading stops if null terminator is encountered earlier.
Returns
Number of characters written, not counting null terminator.

Definition at line 436 of file string_conv.cpp.

436  {
437  if (p_out_size == 0) return 0;
438  memset(p_out,0,p_out_size * sizeof(*p_out));
439  WideCharToMultiByte(p_codepage,0,p_source,p_source_size,p_out,p_out_size,0,FALSE);
440  p_out[p_out_size-1] = 0;
441  return strlen(p_out);
442  }
t_size pfc::stringcvt::convert_wide_to_utf8 ( char *  p_out,
t_size  p_out_size,
const wchar_t *  p_source,
t_size  p_source_size 
)

Converts wide character string to UTF-8.

Parameters
p_outOutput buffer, receives converted string, with null terminator.
p_out_sizeSize of output buffer, in characters. If converted string is too long, it will be truncated. Null terminator is always written, unless p_out_size is zero.
p_sourceString to convert.
p_source_sizeNumber of characters to read from p_source. If reading stops if null terminator is encountered earlier.
Returns
Number of characters written, not counting null terminator.

Definition at line 193 of file string_conv.cpp.

193  {
194  const t_size insize = p_in_size;
195  t_size inptr = 0;
196  string_writer_t<char> writer(p_out,p_out_size);
197 
198  while(inptr < insize && !writer.is_overrun()) {
199  unsigned newchar = 0;
200  t_size delta = wide_decode_char(p_in + inptr,&newchar,insize - inptr);
201  if (delta == 0 || newchar == 0) break;
202  PFC_ASSERT(inptr + delta <= insize);
203  inptr += delta;
204  writer.write_as_utf8(newchar);
205  }
206 
207  return writer.finalize();
208  }
t_size wide_decode_char(const wchar_t *p_source, unsigned *p_out, t_size p_source_length=~0)
Definition: utf8.cpp:217
size_t t_size
Definition: int_types.h:48
t_size pfc::stringcvt::convert_wide_to_win1252 ( char *  p_out,
t_size  p_out_size,
const wchar_t *  p_in,
t_size  p_in_size 
)

Definition at line 284 of file string_conv.cpp.

284  {
285  const t_size insize = p_in_size;
286  t_size inptr = 0;
287  string_writer_t<char> writer(p_out,p_out_size);
288 
289  while(inptr < insize && !writer.is_overrun()) {
290  unsigned newchar = 0;
291  t_size delta = wide_decode_char(p_in + inptr,&newchar,insize - inptr);
292  if (delta == 0 || newchar == 0) break;
293  PFC_ASSERT(inptr + delta <= insize);
294  inptr += delta;
295 
296  char temp;
297  if (!charExport1252( temp, newchar )) temp = '?';
298  writer.write( temp );
299  }
300 
301  return writer.finalize();
302 
303  }
t_size wide_decode_char(const wchar_t *p_source, unsigned *p_out, t_size p_source_length=~0)
Definition: utf8.cpp:217
size_t t_size
Definition: int_types.h:48
t_size pfc::stringcvt::convert_win1252_to_utf8 ( char *  p_out,
t_size  p_out_size,
const char *  p_in,
t_size  p_in_size 
)

Definition at line 379 of file string_conv.cpp.

379  {
380  const t_size insize = p_in_size;
381  t_size inptr = 0;
382  string_writer_t<char> writer(p_out,p_out_size);
383 
384  while(inptr < insize && !writer.is_overrun()) {
385  char inChar = p_in[inptr];
386  if (inChar == 0) break;
387  ++inptr;
388 
389  unsigned out;
390  if (!charImport1252( out , inChar )) out = '?';
391  writer.write_as_utf8( out );
392  }
393 
394  return writer.finalize();
395  }
size_t t_size
Definition: int_types.h:48
t_size pfc::stringcvt::convert_win1252_to_wide ( wchar_t *  p_out,
t_size  p_out_size,
const char *  p_in,
t_size  p_in_size 
)

Definition at line 309 of file string_conv.cpp.

309  {
310  const t_size insize = p_in_size;
311  t_size inptr = 0;
312  string_writer_t<wchar_t> writer(p_out,p_out_size);
313 
314  while(inptr < insize && !writer.is_overrun()) {
315  char inChar = p_in[inptr];
316  if (inChar == 0) break;
317  ++inptr;
318 
319  unsigned out;
320  if (!charImport1252( out , inChar )) out = '?';
321  writer.write_as_wide( out );
322  }
323 
324  return writer.finalize();
325  }
size_t t_size
Definition: int_types.h:48
t_size pfc::stringcvt::estimate_ansi_to_wide ( const char *  p_source,
t_size  p_source_size 
)
inline

Estimates buffer size required to convert specified system codepage string to wide character.

Parameters
p_sourceString to be converted.
p_source_sizeNumber of characters to read from p_source. If reading stops if null terminator is encountered earlier.
Returns
Number of characters to allocate, including space for null terminator.

Definition at line 334 of file string_conv.h.

334  {
335  return estimate_codepage_to_wide(codepage_system,p_source,p_source_size);
336  }
t_size estimate_codepage_to_wide(unsigned p_codepage, const char *p_source, t_size p_source_size)
Estimates buffer size required to convert specified string from specified codepage to wide character...
t_size pfc::stringcvt::estimate_codepage_to_wide ( unsigned  p_codepage,
const char *  p_source,
t_size  p_source_size 
)

Estimates buffer size required to convert specified string from specified codepage to wide character.

Parameters
p_codepageCodepage ID of source string.
p_sourceString to be converted.
p_source_sizeNumber of characters to read from p_source. If reading stops if null terminator is encountered earlier.
Returns
Number of characters to allocate, including space for null terminator.

Definition at line 444 of file string_conv.cpp.

444  {
445  return MultiByteToWideChar(p_codepage,0,p_source,strlen_max(p_source,p_source_size),0,0) + 1;
446  }
t_size strlen_max(const char *ptr, t_size max)
Definition: string_base.h:91
t_size pfc::stringcvt::estimate_utf8_to_ascii ( const char *  p_source,
t_size  p_source_size 
)

Definition at line 397 of file string_conv.cpp.

397  {
398  return estimate_utf8_to_win1252( p_source, p_source_size );
399  }
t_size estimate_utf8_to_win1252(const char *p_in, t_size p_in_size)
t_size pfc::stringcvt::estimate_utf8_to_wide ( const char *  p_in)

Definition at line 210 of file string_conv.cpp.

210  {
211  t_size inptr = 0;
212  t_size retval = 1;//1 for null terminator
213  for(;;) {
214  unsigned newchar = 0;
215  t_size delta = utf8_decode_char(p_in + inptr,newchar);
216  if (delta == 0 || newchar == 0) break;
217  inptr += delta;
218 
219  {
220  wchar_t temp[2];
221  retval += wide_encode_char(newchar,temp);
222  }
223  }
224  return retval;
225  }
size_t t_size
Definition: int_types.h:48
t_size utf8_decode_char(const char *src, unsigned &out, t_size src_bytes)
Definition: utf8.cpp:64
t_size wide_encode_char(unsigned c, wchar_t *out)
Definition: utf8.cpp:227
t_size pfc::stringcvt::estimate_utf8_to_wide ( const char *  p_source,
t_size  p_source_size 
)

Estimates buffer size required to convert specified UTF-8 string to widechar.

Parameters
p_sourceString to be converted.
p_source_sizeNumber of characters to read from p_source. If reading stops if null terminator is encountered earlier.
Returns
Number of characters to allocate, including space for null terminator.

Definition at line 227 of file string_conv.cpp.

227  {
228  const t_size insize = p_in_size;
229  t_size inptr = 0;
230  t_size retval = 1;//1 for null terminator
231  while(inptr < insize) {
232  unsigned newchar = 0;
233  t_size delta = utf8_decode_char(p_in + inptr,newchar,insize - inptr);
234  if (delta == 0 || newchar == 0) break;
235  PFC_ASSERT(inptr + delta <= insize);
236  inptr += delta;
237 
238  {
239  wchar_t temp[2];
240  retval += wide_encode_char(newchar,temp);
241  }
242  }
243  return retval;
244  }
size_t t_size
Definition: int_types.h:48
t_size utf8_decode_char(const char *src, unsigned &out, t_size src_bytes)
Definition: utf8.cpp:64
t_size wide_encode_char(unsigned c, wchar_t *out)
Definition: utf8.cpp:227
t_size pfc::stringcvt::estimate_utf8_to_wide_quick ( t_size  sourceLen)
inline

estimate_utf8_to_wide_quick() functions use simple math to determine buffer size required for the conversion. The result is not accurate length of output string - it's just a safe estimate of required buffer size, possibly bigger than what's really needed.
These functions are meant for scenarios when speed is more important than memory usage.

Definition at line 52 of file string_conv.h.

52  {
53  return sourceLen + 1;
54  }
t_size pfc::stringcvt::estimate_utf8_to_wide_quick ( const char *  source)
inline

Definition at line 55 of file string_conv.h.

55  {
56  return estimate_utf8_to_wide_quick(strlen(source));
57  }
t_size estimate_utf8_to_wide_quick(const char *source, t_size sourceLen)
Definition: string_conv.h:58
t_size pfc::stringcvt::estimate_utf8_to_wide_quick ( const char *  source,
t_size  sourceLen 
)
inline

Definition at line 58 of file string_conv.h.

58  {
59  return estimate_utf8_to_wide_quick(strlen_max(source, sourceLen));
60  }
t_size estimate_utf8_to_wide_quick(const char *source, t_size sourceLen)
Definition: string_conv.h:58
t_size strlen_max(const char *ptr, t_size max)
Definition: string_base.h:91
t_size pfc::stringcvt::estimate_utf8_to_win1252 ( const char *  p_in,
t_size  p_in_size 
)

Definition at line 327 of file string_conv.cpp.

327  {
328  const t_size insize = p_in_size;
329  t_size inptr = 0;
330  t_size retval = 1;//1 for null terminator
331  while(inptr < insize) {
332  unsigned newchar = 0;
333  t_size delta = utf8_decode_char(p_in + inptr,newchar,insize - inptr);
334  if (delta == 0 || newchar == 0) break;
335  PFC_ASSERT(inptr + delta <= insize);
336  inptr += delta;
337 
338  ++retval;
339  }
340  return retval;
341  }
size_t t_size
Definition: int_types.h:48
t_size utf8_decode_char(const char *src, unsigned &out, t_size src_bytes)
Definition: utf8.cpp:64
t_size pfc::stringcvt::estimate_wide_to_ansi ( const wchar_t *  p_source,
t_size  p_source_size 
)
inline

Estimates buffer size required to convert specified wide character string to system codepage.

Parameters
p_sourceString to be converted.
p_source_sizeNumber of characters to read from p_source. If reading stops if null terminator is encountered earlier.
Returns
Number of characters to allocate, including space for null terminator.

Definition at line 352 of file string_conv.h.

352  {
353  return estimate_wide_to_codepage(codepage_system,p_source,p_source_size);
354  }
t_size estimate_wide_to_codepage(unsigned p_codepage, const wchar_t *p_source, t_size p_source_size)
Estimates buffer size required to convert specified wide character string to specified codepage...
t_size pfc::stringcvt::estimate_wide_to_codepage ( unsigned  p_codepage,
const wchar_t *  p_source,
t_size  p_source_size 
)

Estimates buffer size required to convert specified wide character string to specified codepage.

Parameters
p_codepageCodepage ID of source string.
p_sourceString to be converted.
p_source_sizeNumber of characters to read from p_source. If reading stops if null terminator is encountered earlier.
Returns
Number of characters to allocate, including space for null terminator.

Definition at line 447 of file string_conv.cpp.

447  {
448  return WideCharToMultiByte(p_codepage,0,p_source,wcslen_max(p_source,p_source_size),0,0,0,FALSE) + 1;
449  }
t_size wcslen_max(const wchar_t *ptr, t_size max)
Definition: string_base.h:92
t_size pfc::stringcvt::estimate_wide_to_utf8 ( const wchar_t *  p_source,
t_size  p_source_size 
)

Estimates buffer size required to convert specified wide character string to UTF-8.

Parameters
p_sourceString to be converted.
p_source_sizeNumber of characters to read from p_source. If reading stops if null terminator is encountered earlier.
Returns
Number of characters to allocate, including space for null terminator.

Definition at line 246 of file string_conv.cpp.

246  {
247  const t_size insize = p_in_size;
248  t_size inptr = 0;
249  t_size retval = 1;//1 for null terminator
250  while(inptr < insize) {
251  unsigned newchar = 0;
252  t_size delta = wide_decode_char(p_in + inptr,&newchar,insize - inptr);
253  if (delta == 0 || newchar == 0) break;
254  PFC_ASSERT(inptr + delta <= insize);
255  inptr += delta;
256 
257  {
258  char temp[6];
259  delta = utf8_encode_char(newchar,temp);
260  if (delta == 0) break;
261  retval += delta;
262  }
263  }
264  return retval;
265  }
t_size utf8_encode_char(unsigned c, char *out)
Definition: utf8.cpp:113
t_size wide_decode_char(const wchar_t *p_source, unsigned *p_out, t_size p_source_length=~0)
Definition: utf8.cpp:217
size_t t_size
Definition: int_types.h:48
t_size pfc::stringcvt::estimate_wide_to_win1252 ( const wchar_t *  p_in,
t_size  p_in_size 
)

Definition at line 267 of file string_conv.cpp.

267  {
268  const t_size insize = p_in_size;
269  t_size inptr = 0;
270  t_size retval = 1;//1 for null terminator
271  while(inptr < insize) {
272  unsigned newchar = 0;
273  t_size delta = wide_decode_char(p_in + inptr,&newchar,insize - inptr);
274  if (delta == 0 || newchar == 0) break;
275  PFC_ASSERT(inptr + delta <= insize);
276  inptr += delta;
277 
278  ++retval;
279  }
280  return retval;
281 
282  }
t_size wide_decode_char(const wchar_t *p_source, unsigned *p_out, t_size p_source_length=~0)
Definition: utf8.cpp:217
size_t t_size
Definition: int_types.h:48
t_size pfc::stringcvt::estimate_win1252_to_utf8 ( const char *  p_in,
t_size  p_in_size 
)

Definition at line 362 of file string_conv.cpp.

362  {
363  const size_t insize = p_in_size;
364  t_size inptr = 0;
365  t_size retval = 1; // 1 for null terminator
366  while(inptr < insize) {
367  unsigned newchar;
368  char c = p_in[inptr];
369  if (c == 0) break;
370  ++inptr;
371  if (!charImport1252( newchar, c)) newchar = '?';
372 
373  char temp[6];
374  retval += pfc::utf8_encode_char( newchar, temp );
375  }
376  return retval;
377  }
t_size utf8_encode_char(unsigned c, char *out)
Definition: utf8.cpp:113
size_t t_size
Definition: int_types.h:48
t_size pfc::stringcvt::estimate_win1252_to_wide ( const char *  p_source,
t_size  p_source_size 
)

Definition at line 305 of file string_conv.cpp.

305  {
306  return strlen_max_t( p_source, p_source_size ) + 1;
307  }
t_size strlen_max_t(const t_char *ptr, t_size max)
Definition: string_base.h:84
template<typename t_char >
const t_char* pfc::stringcvt::null_string_t ( )
template<>
const char* pfc::stringcvt::null_string_t< char > ( )
inline

Definition at line 64 of file string_conv.h.

64 {return "";}
template<>
const wchar_t* pfc::stringcvt::null_string_t< wchar_t > ( )
inline

Definition at line 65 of file string_conv.h.

65 {return L"";}
template<typename t_char >
bool pfc::stringcvt::string_is_empty_t ( const t_char *  p_string,
t_size  p_string_size = ~0 
)

Definition at line 74 of file string_conv.h.

74  {
75  if (p_string_size == 0) return true;
76  return p_string[0] == 0;
77  }
template<typename t_char >
t_size pfc::stringcvt::strlen_t ( const t_char *  p_string,
t_size  p_string_size = ~0 
)

Definition at line 67 of file string_conv.h.

67  {
68  for(t_size n=0;n<p_string_size;n++) {
69  if (p_string[n] == 0) return n;
70  }
71  return p_string_size;
72  }
size_t t_size
Definition: int_types.h:48