1 /* Wide char wrapper for strtof
3 * 25 Aug 2006 Initial version.
5 * Contributor: Danny Smith <dannysmith@users.sourceforege.net>
8 /* This routine has been placed in the public domain.*/
10 #define WIN32_LEAN_AND_MEAN
18 #include "mb_wc_common.h"
20 float wcstof (const wchar_t * __restrict__ wcs, wchar_t ** __restrict__ wcse)
26 const unsigned int cp = get_codepage ();
28 /* Allocate enough room for (possibly) mb chars */
29 cs = (char *) malloc ((wcslen(wcs)+1) * MB_CUR_MAX);
31 if (cp == 0) /* C locale */
33 for (i = 0; (wcs[i] != 0) && wcs[i] <= 255; i++)
34 cs[i] = (char) wcs[i];
41 /* loop through till we hit null or invalid character */
42 for (i = 0; (wcs[i] != 0) && (nbytes != 0); i++)
44 nbytes = WideCharToMultiByte(cp, WC_COMPOSITECHECK | WC_SEPCHARS,
45 wcs + i, 1, cs + mb_len, MB_CUR_MAX,
52 ret = strtof (cs, &cse);
56 /* Make sure temp mbstring cs has 0 at cse. */
58 i = _mbslen ((unsigned char*) cs); /* Number of chars, not bytes */
59 *wcse = (wchar_t *) wcs + i;