added wxUniChar::AsUTF8() for easy conversion in UTF8 build
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46376 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -140,15 +140,10 @@ struct WXDLLIMPEXP_BASE wxStringOperationsUtf8
|
|||||||
return dist;
|
return dist;
|
||||||
}
|
}
|
||||||
|
|
||||||
// buffer for single UTF-8 character
|
|
||||||
struct Utf8CharBuffer
|
|
||||||
{
|
|
||||||
char data[5];
|
|
||||||
operator const char*() const { return data; }
|
|
||||||
};
|
|
||||||
|
|
||||||
// encodes the character as UTF-8:
|
// encodes the character as UTF-8:
|
||||||
static Utf8CharBuffer EncodeChar(const wxUniChar& ch);
|
typedef wxUniChar::Utf8CharBuffer Utf8CharBuffer;
|
||||||
|
static Utf8CharBuffer EncodeChar(const wxUniChar& ch)
|
||||||
|
{ return ch.AsUTF8(); }
|
||||||
|
|
||||||
// returns n copies of ch encoded in UTF-8 string
|
// returns n copies of ch encoded in UTF-8 string
|
||||||
static wxCharBuffer EncodeNChars(size_t n, const wxUniChar& ch);
|
static wxCharBuffer EncodeNChars(size_t n, const wxUniChar& ch);
|
||||||
|
@@ -71,6 +71,19 @@ public:
|
|||||||
// Returns Unicode code point value of the character
|
// Returns Unicode code point value of the character
|
||||||
value_type GetValue() const { return m_value; }
|
value_type GetValue() const { return m_value; }
|
||||||
|
|
||||||
|
#if wxUSE_UNICODE_UTF8
|
||||||
|
// buffer for single UTF-8 character
|
||||||
|
struct Utf8CharBuffer
|
||||||
|
{
|
||||||
|
char data[5];
|
||||||
|
operator const char*() const { return data; }
|
||||||
|
};
|
||||||
|
|
||||||
|
// returns the character encoded as UTF-8
|
||||||
|
// (NB: implemented in stringops.cpp)
|
||||||
|
Utf8CharBuffer AsUTF8() const;
|
||||||
|
#endif // wxUSE_UNICODE_UTF8
|
||||||
|
|
||||||
// Returns true if the character is an ASCII character:
|
// Returns true if the character is an ASCII character:
|
||||||
bool IsAscii() const { return m_value < 0x80; }
|
bool IsAscii() const { return m_value < 0x80; }
|
||||||
|
|
||||||
@@ -182,6 +195,11 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxUniChar::value_type GetValue() const { return UniChar().GetValue(); }
|
wxUniChar::value_type GetValue() const { return UniChar().GetValue(); }
|
||||||
|
|
||||||
|
#if wxUSE_UNICODE_UTF8
|
||||||
|
wxUniChar::Utf8CharBuffer AsUTF8() const { return UniChar().AsUTF8(); }
|
||||||
|
#endif // wxUSE_UNICODE_UTF8
|
||||||
|
|
||||||
bool IsAscii() const { return UniChar().IsAscii(); }
|
bool IsAscii() const { return UniChar().IsAscii(); }
|
||||||
|
|
||||||
// Assignment operators:
|
// Assignment operators:
|
||||||
|
@@ -190,13 +190,14 @@ bool wxStringOperationsUtf8::IsValidUtf8LeadByte(unsigned char c)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
wxStringOperationsUtf8::Utf8CharBuffer
|
// NB: this is in this file and not unichar.cpp to keep all UTF-8 encoding
|
||||||
wxStringOperationsUtf8::EncodeChar(const wxUniChar& ch)
|
// code in single place
|
||||||
|
wxUniChar::Utf8CharBuffer wxUniChar::AsUTF8() const
|
||||||
{
|
{
|
||||||
Utf8CharBuffer buf;
|
Utf8CharBuffer buf;
|
||||||
char *out = buf.data;
|
char *out = buf.data;
|
||||||
|
|
||||||
wxUniChar::value_type code = ch.GetValue();
|
value_type code = GetValue();
|
||||||
|
|
||||||
// Char. number range | UTF-8 octet sequence
|
// Char. number range | UTF-8 octet sequence
|
||||||
// (hexadecimal) | (binary)
|
// (hexadecimal) | (binary)
|
||||||
|
Reference in New Issue
Block a user