\func{static wxString }{FromAscii}{\param{const char*}{ s}}
+\func{static wxString }{FromAscii}{\param{const char*}{ s}, \param{size\_t}{ len}}
+
\func{static wxString }{FromAscii}{\param{const char}{ c}}
Converts the string or character from an ASCII, 7-bit form
\constfunc{wxWritableWCharBuffer}{wchar\_str}{\void}
Returns an object with string data that is implicitly convertible to
-{\tt char*} pointer. Note that any change to the returned buffer is lost and so
-this function is only usable for passing strings to legacy libraries that
-don't have const-correct API. Use \helpref{wxStringBuffer}{wxstringbuffer} if
-you want to modify the string.
+{\tt char*} pointer. Note that changes to the returned buffer may or may
+not be lost (depending on the build) and so this function is only usable for
+passing strings to legacy libraries that don't have const-correct API. Use
+\helpref{wxStringBuffer}{wxstringbuffer} if you want to modify the string.
\wxheading{See also}
// the behaviour of these functions with the strings containing anything
// else than 7 bit ASCII characters is undefined, use at your own risk.
#if wxUSE_UNICODE
+ static wxString FromAscii(const char *ascii, size_t len); // string
static wxString FromAscii(const char *ascii); // string
static wxString FromAscii(const char ascii); // char
const wxCharBuffer ToAscii() const;
#else // ANSI
static wxString FromAscii(const char *ascii) { return wxString( ascii ); }
+ static wxString FromAscii(const char *ascii, size_t len)
+ { return wxString( ascii, len ); }
static wxString FromAscii(const char ascii) { return wxString( ascii ); }
const char *ToAscii() const { return c_str(); }
#endif // Unicode/!Unicode
#endif
#endif
-wxString wxString::FromAscii(const char *ascii)
+wxString wxString::FromAscii(const char *ascii, size_t len)
{
- if (!ascii)
+ if (!ascii || len == 0)
return wxEmptyString;
- size_t len = strlen(ascii);
wxString res;
- if ( len )
- {
- wxImplStringBuffer buf(res, len);
- wxStringCharType *dest = buf;
+ wxImplStringBuffer buf(res, len);
+ wxStringCharType *dest = buf;
- for ( ;; )
- {
- unsigned char c = (unsigned char)*ascii++;
- wxASSERT_MSG( c < 0x80,
- _T("Non-ASCII value passed to FromAscii().") );
+ for ( ;; )
+ {
+ unsigned char c = (unsigned char)*ascii++;
+ wxASSERT_MSG( c < 0x80,
+ _T("Non-ASCII value passed to FromAscii().") );
- *dest++ = (wchar_t)c;
+ *dest++ = (wchar_t)c;
- if ( c == '\0' )
- break;
- }
+ if ( c == '\0' )
+ break;
}
return res;
}
+wxString wxString::FromAscii(const char *ascii)
+{
+ return FromAscii(ascii, strlen(ascii));
+}
+
wxString wxString::FromAscii(const char ascii)
{
// What do we do with '\0' ?