From 66a7ead100f7f41c14afc0ab528a46f928a9f3d8 Mon Sep 17 00:00:00 2001 From: Leo Koppel Date: Fri, 22 Jul 2016 12:32:02 -0400 Subject: [PATCH 1/5] Fix failure on loading empty file Re: brofield/simpleini#19 The Windows, Unicode, UTF-8 version of SizeFromStore returns failure when given zero-length data. Fix by moving a_uDataLen == 0 check to after the UTF-8 BOM removal. --- SimpleIni.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SimpleIni.h b/SimpleIni.h index aee5bee..b0cad33 100644 --- a/SimpleIni.h +++ b/SimpleIni.h @@ -1416,10 +1416,6 @@ CSimpleIniTempl::LoadData( { SI_CONVERTER converter(m_bStoreIsUtf8); - if (a_uDataLen == 0) { - return SI_OK; - } - // consume the UTF-8 BOM if it exists if (m_bStoreIsUtf8 && a_uDataLen >= 3) { if (memcmp(a_pData, SI_UTF8_SIGNATURE, 3) == 0) { @@ -1428,6 +1424,10 @@ CSimpleIniTempl::LoadData( } } + if (a_uDataLen == 0) { + return SI_OK; + } + // determine the length of the converted data size_t uLen = converter.SizeFromStore(a_pData, a_uDataLen); if (uLen == (size_t)(-1)) { From b414bb2708aa573890aa8afc039bb17561915173 Mon Sep 17 00:00:00 2001 From: Ian Dunn Date: Thu, 24 Aug 2017 19:09:43 -0700 Subject: [PATCH 2/5] Replace std::binary_function with std::function (#31) * std::binary_function is deprecated in C++11, removed in C++17 - replace with std::function * Remove inheritance of std::function<...> that is not necessary. See #31 --- SimpleIni.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SimpleIni.h b/SimpleIni.h index b0cad33..6cf5ced 100644 --- a/SimpleIni.h +++ b/SimpleIni.h @@ -328,7 +328,7 @@ class CSimpleIniTempl #endif /** Strict less ordering by name of key only */ - struct KeyOrder : std::binary_function { + struct KeyOrder { bool operator()(const Entry & lhs, const Entry & rhs) const { const static SI_STRLESS isLess = SI_STRLESS(); return isLess(lhs.pItem, rhs.pItem); @@ -336,7 +336,7 @@ class CSimpleIniTempl }; /** Strict less ordering by order, and then name of key */ - struct LoadOrder : std::binary_function { + struct LoadOrder { bool operator()(const Entry & lhs, const Entry & rhs) const { if (lhs.nOrder != rhs.nOrder) { return lhs.nOrder < rhs.nOrder; From 244c3f220ba3c73cf59b6b17bd2baeb2409693a8 Mon Sep 17 00:00:00 2001 From: Mike Tzou Date: Fri, 25 Aug 2017 10:19:31 +0800 Subject: [PATCH 3/5] Hookup with TravisCI (#30) Add TravisCI --- .travis.yml | 13 +++++++++++++ README.md | 2 ++ 2 files changed, 15 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c1f1852 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,13 @@ +language: cpp + +os: + - linux + - osx + +compiler: + - gcc + - clang + +script: + - make all + - make test diff --git a/README.md b/README.md index 2e0d25e..6e74bdf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ simpleini ========= +[![TravisCI Status](https://travis-ci.org/brofield/simpleini.svg?branch=master)](https://travis-ci.org/brofield/simpleini) + A cross-platform library that provides a simple API to read and write INI-style configuration files. It supports data files in ASCII, MBCS and Unicode. It is designed explicitly to be portable to any platform and has been tested on Windows, WinCE and Linux. Released as open-source and free using the MIT licence. # Feature Summary From 2af65fcc504f8242752755e836709762ef7ce062 Mon Sep 17 00:00:00 2001 From: Brodie Thiesfield Date: Fri, 25 Aug 2017 15:17:21 +1000 Subject: [PATCH 4/5] 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. --- SimpleIni.h | 23 ++++++++++++++--------- 1 file 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::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::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; From fe082fa81f4a55ddceb55056622136be616b3c6f Mon Sep 17 00:00:00 2001 From: csware Date: Fri, 31 Aug 2018 15:30:08 +0200 Subject: [PATCH 5/5] Make compile with C++17 (#37) binary_function was deprecated in C++11 and removed in C++17. Signed-off-by: Sven Strickroth