Skip to content

Commit

Permalink
Fix a bug in the parser
Browse files Browse the repository at this point in the history
  • Loading branch information
fredyw committed May 15, 2015
1 parent 06474f7 commit 3bdf6a6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ On Windows, you need to install MinGW.
waf build --shared

### Running unit tests ###
cpp-iniparses uses GoogleTest (http://code.google.com/p/googletest/)

waf build --test

Alternatively, we can also explicitly specify the gtest headers and libraries location

waf build --test --gtest_include=/gtest/include --gtest_lib=/gtest/lib
./run_tests.sh

### Installing cppiniparser ###
waf install
Expand Down
8 changes: 8 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

cd gtest-1.7.0/make
make
cp gtest_main.a libgtest_main.a
cd -
./waf clean
./waf build --test --gtest_include=gtest-1.7.0/include --gtest_lib=gtest-1.7.0/make
6 changes: 3 additions & 3 deletions src/INIParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ INIConfig INIParser::Read(const std::string& filename) {
try {
std::string line;
while (getline(is, line)) {
if (utils::IsSection(line)) {
if (utils::IsEmptyLine(line) || utils::IsComment(line)) {
// ignore it
} else if (utils::IsSection(line)) {
section = utils::ParseSection(line);
config.AddSection(section);
} else if (utils::IsOption(line)) {
std::pair<std::string, std::string> option = utils::ParseOption(line);
config.AddOption(section, option.first, option.second);
} else if (utils::IsEmptyLine(line) || utils::IsComment(line)) {
// ignore it
} else {
std::string msg = "Invalid line: " + line;
throw INIReaderException(msg.c_str());
Expand Down
4 changes: 4 additions & 0 deletions test/test1.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
;=========================================================================
; foo section
;=========================================================================
[foo]
name=foo
msg=hello

;=========================================================================
; bar section
;=========================================================================
[bar]
name=bar
msg=bye
Expand Down

0 comments on commit 3bdf6a6

Please sign in to comment.