Add wxConvAuto::GetEncoding()

This commit is contained in:
Pavel Tyunin
2020-09-22 17:42:07 +03:00
parent 307a97dadf
commit 28823424e9
3 changed files with 42 additions and 0 deletions

View File

@@ -93,6 +93,8 @@ public:
return m_bomType;
}
wxFontEncoding GetEncoding() const;
// Return true if the fall-back encoding is used
bool IsFallbackEncoding() const
{

View File

@@ -146,6 +146,15 @@ public:
*/
wxBOM GetBOM() const;
/**
Return the detected encoding
Returns @c wxFONTENCODING_MAX if called before the first use.
@since 3.1.5
*/
wxBOM GetEncoding() const;
/**
Check if the fall-back encoding is used.

View File

@@ -351,3 +351,34 @@ wxConvAuto::FromWChar(char *dst, size_t dstLen,
return m_conv->FromWChar(dst, dstLen, src, srcLen);
}
wxFontEncoding wxConvAuto::GetEncoding() const
{
switch ( m_bomType )
{
case wxBOM_UTF32BE:
return wxFONTENCODING_UTF32BE;
case wxBOM_UTF32LE:
return wxFONTENCODING_UTF32LE;
case wxBOM_UTF16BE:
return wxFONTENCODING_UTF16BE;
case wxBOM_UTF16LE:
return wxFONTENCODING_UTF16LE;
case wxBOM_UTF8:
return wxFONTENCODING_UTF8;
case wxBOM_Unknown:
case wxBOM_None:
if ( !m_conv )
return wxFONTENCODING_MAX;
else if ( !m_ownsConv )
return wxFONTENCODING_UTF8;
else if ( m_encDefault != wxFONTENCODING_DEFAULT )
return m_encDefault;
else
return GetFallbackEncoding();
}
wxFAIL_MSG( "unknown BOM type" );
return wxFONTENCODING_MAX;
}