Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmtroffaes committed May 16, 2017
2 parents 09bb5f0 + aa46ee8 commit 0f2b5e5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
16 changes: 15 additions & 1 deletion inipp/inipp.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ SOFTWARE.
#include <functional>
#include <cctype>
#include <locale>
#include <codecvt>

namespace inipp {

Expand Down Expand Up @@ -76,8 +77,21 @@ static inline std::basic_string<CharT> literal(const char *value)

template <typename CharT, typename T>
static inline bool extract(const std::basic_string<CharT> & value, T & dst) {
CharT c;
std::basic_istringstream<CharT> is{ value };
return bool{ is >> std::boolalpha >> dst };
return bool{ is >> std::boolalpha >> dst && !(is >> c) };
}

template <>
static inline bool extract(const std::string & value, std::string & dst) {
dst = value;
return true;
}

template <>
static inline bool extract(const std::wstring & value, std::wstring & dst) {
dst = value;
return true;
}

template<class CharT>
Expand Down
4 changes: 2 additions & 2 deletions nuget/IniPP.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<package>
<metadata>
<id>IniPP</id>
<version>1.0.3</version>
<version>1.0.4</version>
<authors>Matthias C. M. Troffaes</authors>
<owners>Matthias C. M. Troffaes</owners>
<projectUrl>https://github.com/mcmtroffaes/inipp</projectUrl>
<licenseUrl>https://raw.githubusercontent.com/mcmtroffaes/inipp/master/LICENSE.txt</licenseUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Simple header-only C++ ini parser, with support for interpolation similar to Python's configparser.</description>
<summary>Simple C++ ini parser.</summary>
<releaseNotes>New extract function for converting strings to values.</releaseNotes>
<releaseNotes>Fix extract function for strings containing whitespace or trailing content.</releaseNotes>
<copyright>Copyright 2017</copyright>
<tags>ini parser native nativepackage</tags>
</metadata>
Expand Down
8 changes: 5 additions & 3 deletions unittest/unittest-msvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ namespace unittest
int16_t i16{ 0 };
int32_t i32{ 0 };
bool bool_{ true };
Assert::IsFalse(extract(std::string(), str));
Assert::AreEqual(std::string{ "oops" }, str);
Assert::IsTrue(extract(std::string(), str));
Assert::AreEqual(std::string{ }, str);
Assert::IsTrue(extract(std::string{ "hello" }, str));
Assert::AreEqual(std::string{ "hello" }, str);
Assert::IsTrue(extract(std::string{ "hello world" }, str));
Assert::AreEqual(std::string{ "hello world" }, str);
Assert::IsTrue(extract(std::string{ "-10" }, i16));
Assert::AreEqual(int16_t{ -10 }, i16);
Assert::IsTrue(extract(std::string{ "false" }, bool_));
Expand All @@ -37,7 +39,7 @@ namespace unittest
Assert::AreEqual(int16_t{ -10 }, i16);
Assert::IsFalse(extract(std::string{ "1000000" }, i16));
Assert::AreEqual(int16_t{ -10 }, i16);
Assert::IsTrue(extract(std::string{ "-20 xxx" }, i16));
Assert::IsFalse(extract(std::string{ "-20 xxx" }, i16));
Assert::AreEqual(int16_t{ -20 }, i16);
Assert::IsTrue(extract(std::string{ "1000000" }, i32));
Assert::AreEqual(int32_t{ 1000000 }, i32);
Expand Down

0 comments on commit 0f2b5e5

Please sign in to comment.