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 d6df816 + 1eb998a commit 09bb5f0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
16 changes: 11 additions & 5 deletions inipp/inipp.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/*
MIT License
Copyright(c) 2017 Matthias C.M.Troffaes
Copyright (c) 2017 Matthias C. M. Troffaes
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Expand Down Expand Up @@ -74,6 +74,12 @@ static inline std::basic_string<CharT> literal(const char *value)
return result;
}

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

template<class CharT>
class Ini
{
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.2</version>
<version>1.0.3</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></releaseNotes>
<releaseNotes>New extract function for converting strings to values.</releaseNotes>
<copyright>Copyright 2017</copyright>
<tags>ini parser native nativepackage</tags>
</metadata>
Expand Down
27 changes: 26 additions & 1 deletion unittest/unittest-msvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,38 @@ namespace unittest
{
public:

TEST_METHOD(TestMethod)
TEST_METHOD(TestParseGenerate)
{
Assert::IsTrue(runtest<char>("test1.ini", "test1.output", std::cout));
Assert::IsTrue(runtest<wchar_t>("test1.ini", "test1.output", std::wcout));
Assert::IsTrue(runtest<char>("test2.ini", "test2.output", std::cout));
Assert::IsTrue(runtest<wchar_t>("test2.ini", "test2.output", std::wcout));
}

TEST_METHOD(TestExtract)
{
std::string str{ "oops" };
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{ "hello" }, str));
Assert::AreEqual(std::string{ "hello" }, str);
Assert::IsTrue(extract(std::string{ "-10" }, i16));
Assert::AreEqual(int16_t{ -10 }, i16);
Assert::IsTrue(extract(std::string{ "false" }, bool_));
Assert::AreEqual(false, bool_);
Assert::IsTrue(extract(std::string{ "-10" }, i16));
Assert::AreEqual(int16_t{ -10 }, i16);
Assert::IsFalse(extract(std::string{ "xxx" }, i16));
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::AreEqual(int16_t{ -20 }, i16);
Assert::IsTrue(extract(std::string{ "1000000" }, i32));
Assert::AreEqual(int32_t{ 1000000 }, i32);
}
};
}

0 comments on commit 09bb5f0

Please sign in to comment.