From 28823424e9c3d0a56aff76057c00b023ea04500a Mon Sep 17 00:00:00 2001 From: Pavel Tyunin Date: Tue, 22 Sep 2020 17:42:07 +0300 Subject: [PATCH] Add wxConvAuto::GetEncoding() --- include/wx/convauto.h | 2 ++ interface/wx/convauto.h | 9 +++++++++ src/common/convauto.cpp | 31 +++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/include/wx/convauto.h b/include/wx/convauto.h index 23b21dc41c..57212ab1ad 100644 --- a/include/wx/convauto.h +++ b/include/wx/convauto.h @@ -93,6 +93,8 @@ public: return m_bomType; } + wxFontEncoding GetEncoding() const; + // Return true if the fall-back encoding is used bool IsFallbackEncoding() const { diff --git a/interface/wx/convauto.h b/interface/wx/convauto.h index 90e769c32a..788d6ec2b9 100644 --- a/interface/wx/convauto.h +++ b/interface/wx/convauto.h @@ -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. diff --git a/src/common/convauto.cpp b/src/common/convauto.cpp index 952b4455f5..dca91eb59b 100644 --- a/src/common/convauto.cpp +++ b/src/common/convauto.cpp @@ -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; +}