Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/simpleini.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrodie Thiesfield <brofield@users.noreply.github.com>2017-08-25 08:17:21 +0300
committerGitHub <noreply@github.com>2017-08-25 08:17:21 +0300
commit2af65fcc504f8242752755e836709762ef7ce062 (patch)
tree8a3224958812561afe3ced5d64c1d8115585ddb2
parent244c3f220ba3c73cf59b6b17bd2baeb2409693a8 (diff)
Enable unicode when data starts with UTF-8 BOM
Automatically enable the Unicode mode if the data being loaded starts with the UTF-8 BOM.
-rw-r--r--SimpleIni.h23
1 files changed, 14 insertions, 9 deletions
diff --git a/SimpleIni.h b/SimpleIni.h
index 6cf5ced..047c809 100644
--- a/SimpleIni.h
+++ b/SimpleIni.h
@@ -20,7 +20,7 @@
@section features FEATURES
- MIT Licence allows free use in all software (including GPL and commercial)
- - multi-platform (Windows 95/98/ME/NT/2K/XP/2003, Windows CE, Linux, Unix)
+ - multi-platform (Windows CE/9x/NT..10/etc, Linux, MacOSX, Unix)
- loading and saving of INI-style configuration files
- configuration files can have any newline format on all platforms
- liberal acceptance of file format
@@ -1414,14 +1414,18 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::LoadData(
size_t a_uDataLen
)
{
- SI_CONVERTER converter(m_bStoreIsUtf8);
-
- // consume the UTF-8 BOM if it exists
- if (m_bStoreIsUtf8 && a_uDataLen >= 3) {
- if (memcmp(a_pData, SI_UTF8_SIGNATURE, 3) == 0) {
- a_pData += 3;
- a_uDataLen -= 3;
- }
+ if (!a_pData) {
+ return SI_OK;
+ }
+
+ // if the UTF-8 BOM exists, consume it and set mode to unicode, if we have
+ // already loaded data and try to change mode half-way through then this will
+ // be ignored and we will assert in debug versions
+ if (a_uDataLen >= 3 && memcmp(a_pData, SI_UTF8_SIGNATURE, 3) == 0) {
+ a_pData += 3;
+ a_uDataLen -= 3;
+ SI_ASSERT(m_bStoreIsUtf8 || !m_pData); // we don't expect mixed mode data
+ SetUnicode();
}
if (a_uDataLen == 0) {
@@ -1429,6 +1433,7 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::LoadData(
}
// determine the length of the converted data
+ SI_CONVERTER converter(m_bStoreIsUtf8);
size_t uLen = converter.SizeFromStore(a_pData, a_uDataLen);
if (uLen == (size_t)(-1)) {
return SI_FAIL;