Skip to content

Commit 7e49789

Browse files
authored
Merge pull request #42 from botanicvelious/main
add newline after each section
2 parents 7bb1ec3 + 183f7d0 commit 7e49789

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

include/inicpp.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,10 @@ namespace ini
754754
os.put(fieldSep_);
755755
writeEscaped(os, secPair.second.template as<std::string>());
756756
os.put('\n');
757-
}
757+
}
758+
759+
// Add a newline after each section
760+
os.put('\n');
758761
}
759762
}
760763

test/test_inifile.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -349,14 +349,14 @@ TEST_CASE("escape comment when writing", "IniFile")
349349

350350
REQUIRE(str == "[Fo\\#o]\n"
351351
"he\\#llo=world\n"
352-
"world=he\\#llo\n");
352+
"world=he\\#llo\n\n");
353353
}
354354

355355
TEST_CASE("decode what we encoded", "IniFile")
356356
{
357357
std::string content = "[Fo\\#o]\n"
358358
"he\\REMllo=worl\\REMd\n"
359-
"world=he\\//llo\n";
359+
"world=he\\//llo\n\n";
360360

361361
ini::IniFile inif('=', {"#", "REM", "//"});
362362

@@ -397,7 +397,7 @@ TEST_CASE("save with bool fields", "IniFile")
397397
inif["Foo"]["bar2"] = false;
398398

399399
std::string result = inif.encode();
400-
REQUIRE(result == "[Foo]\nbar1=true\nbar2=false\n");
400+
REQUIRE(result == "[Foo]\nbar1=true\nbar2=false\n\n");
401401
}
402402

403403
TEST_CASE("save with char fields", "IniFile")
@@ -407,7 +407,7 @@ TEST_CASE("save with char fields", "IniFile")
407407
inif["Foo"]["bar2"] = static_cast<char>('q');
408408

409409
std::string result = inif.encode();
410-
REQUIRE(result == "[Foo]\nbar1=c\nbar2=q\n");
410+
REQUIRE(result == "[Foo]\nbar1=c\nbar2=q\n\n");
411411
}
412412

413413
TEST_CASE("save with unsigned char fields", "IniFile")
@@ -417,7 +417,7 @@ TEST_CASE("save with unsigned char fields", "IniFile")
417417
inif["Foo"]["bar2"] = static_cast<unsigned char>('q');
418418

419419
std::string result = inif.encode();
420-
REQUIRE(result == "[Foo]\nbar1=c\nbar2=q\n");
420+
REQUIRE(result == "[Foo]\nbar1=c\nbar2=q\n\n");
421421
}
422422

423423
TEST_CASE("save with short fields", "IniFile")
@@ -427,7 +427,7 @@ TEST_CASE("save with short fields", "IniFile")
427427
inif["Foo"]["bar2"] = static_cast<short>(-2);
428428

429429
std::string result = inif.encode();
430-
REQUIRE(result == "[Foo]\nbar1=1\nbar2=-2\n");
430+
REQUIRE(result == "[Foo]\nbar1=1\nbar2=-2\n\n");
431431
}
432432

433433
TEST_CASE("save with unsigned short fields", "IniFile")
@@ -437,7 +437,7 @@ TEST_CASE("save with unsigned short fields", "IniFile")
437437
inif["Foo"]["bar2"] = static_cast<unsigned short>(13);
438438

439439
std::string result = inif.encode();
440-
REQUIRE(result == "[Foo]\nbar1=1\nbar2=13\n");
440+
REQUIRE(result == "[Foo]\nbar1=1\nbar2=13\n\n");
441441
}
442442

443443
TEST_CASE("save with int fields", "IniFile")
@@ -447,7 +447,7 @@ TEST_CASE("save with int fields", "IniFile")
447447
inif["Foo"]["bar2"] = static_cast<int>(-2);
448448

449449
std::string result = inif.encode();
450-
REQUIRE(result == "[Foo]\nbar1=1\nbar2=-2\n");
450+
REQUIRE(result == "[Foo]\nbar1=1\nbar2=-2\n\n");
451451
}
452452

453453
TEST_CASE("save with unsigned int fields", "IniFile")
@@ -457,7 +457,7 @@ TEST_CASE("save with unsigned int fields", "IniFile")
457457
inif["Foo"]["bar2"] = static_cast<unsigned int>(13);
458458

459459
std::string result = inif.encode();
460-
REQUIRE(result == "[Foo]\nbar1=1\nbar2=13\n");
460+
REQUIRE(result == "[Foo]\nbar1=1\nbar2=13\n\n");
461461
}
462462

463463
TEST_CASE("save with long fields", "IniFile")
@@ -467,7 +467,7 @@ TEST_CASE("save with long fields", "IniFile")
467467
inif["Foo"]["bar2"] = static_cast<long>(-2);
468468

469469
std::string result = inif.encode();
470-
REQUIRE(result == "[Foo]\nbar1=1\nbar2=-2\n");
470+
REQUIRE(result == "[Foo]\nbar1=1\nbar2=-2\n\n");
471471
}
472472

473473
TEST_CASE("save with unsigned long fields", "IniFile")
@@ -477,7 +477,7 @@ TEST_CASE("save with unsigned long fields", "IniFile")
477477
inif["Foo"]["bar2"] = static_cast<unsigned long>(13);
478478

479479
std::string result = inif.encode();
480-
REQUIRE(result == "[Foo]\nbar1=1\nbar2=13\n");
480+
REQUIRE(result == "[Foo]\nbar1=1\nbar2=13\n\n");
481481
}
482482

483483
TEST_CASE("save with double fields", "IniFile")
@@ -487,7 +487,7 @@ TEST_CASE("save with double fields", "IniFile")
487487
inif["Foo"]["bar2"] = static_cast<double>(-2.4);
488488

489489
std::string result = inif.encode();
490-
REQUIRE(result == "[Foo]\nbar1=1.2\nbar2=-2.4\n");
490+
REQUIRE(result == "[Foo]\nbar1=1.2\nbar2=-2.4\n\n");
491491
}
492492

493493
TEST_CASE("save with float fields", "IniFile")
@@ -497,7 +497,7 @@ TEST_CASE("save with float fields", "IniFile")
497497
inif["Foo"]["bar2"] = static_cast<float>(-2.4f);
498498

499499
std::string result = inif.encode();
500-
REQUIRE(result == "[Foo]\nbar1=1.2\nbar2=-2.4\n");
500+
REQUIRE(result == "[Foo]\nbar1=1.2\nbar2=-2.4\n\n");
501501
}
502502

503503
TEST_CASE("save with std::string fields", "IniFile")
@@ -507,7 +507,7 @@ TEST_CASE("save with std::string fields", "IniFile")
507507
inif["Foo"]["bar2"] = static_cast<std::string>("world");
508508

509509
std::string result = inif.encode();
510-
REQUIRE(result == "[Foo]\nbar1=hello\nbar2=world\n");
510+
REQUIRE(result == "[Foo]\nbar1=hello\nbar2=world\n\n");
511511
}
512512

513513
TEST_CASE("save with const char* fields", "IniFile")
@@ -517,7 +517,7 @@ TEST_CASE("save with const char* fields", "IniFile")
517517
inif["Foo"]["bar2"] = static_cast<const char *>("world");
518518

519519
std::string result = inif.encode();
520-
REQUIRE(result == "[Foo]\nbar1=hello\nbar2=world\n");
520+
REQUIRE(result == "[Foo]\nbar1=hello\nbar2=world\n\n");
521521
}
522522

523523
TEST_CASE("save with char* fields", "IniFile")
@@ -529,7 +529,7 @@ TEST_CASE("save with char* fields", "IniFile")
529529
inif["Foo"]["bar2"] = static_cast<char *>(bar2);
530530

531531
std::string result = inif.encode();
532-
REQUIRE(result == "[Foo]\nbar1=hello\nbar2=world\n");
532+
REQUIRE(result == "[Foo]\nbar1=hello\nbar2=world\n\n");
533533
}
534534

535535
TEST_CASE("save with string literal fields", "IniFile")
@@ -539,7 +539,7 @@ TEST_CASE("save with string literal fields", "IniFile")
539539
inif["Foo"]["bar2"] = "world";
540540

541541
std::string result = inif.encode();
542-
REQUIRE(result == "[Foo]\nbar1=hello\nbar2=world\n");
542+
REQUIRE(result == "[Foo]\nbar1=hello\nbar2=world\n\n");
543543
}
544544

545545
#ifdef __cpp_lib_string_view
@@ -550,7 +550,7 @@ TEST_CASE("save with std::string_view fields", "IniFile")
550550
inif["Foo"]["bar2"] = std::string_view("world");
551551

552552
std::string result = inif.encode();
553-
REQUIRE(result == "[Foo]\nbar1=hello\nbar2=world\n");
553+
REQUIRE(result == "[Foo]\nbar1=hello\nbar2=world\n\n");
554554
}
555555
#endif
556556

@@ -561,7 +561,7 @@ TEST_CASE("save with custom field sep", "IniFile")
561561
inif["Foo"]["bar2"] = false;
562562

563563
std::string result = inif.encode();
564-
REQUIRE(result == "[Foo]\nbar1:true\nbar2:false\n");
564+
REQUIRE(result == "[Foo]\nbar1:true\nbar2:false\n\n");
565565
}
566566

567567
TEST_CASE("inline comments in sections are discarded", "IniFile")
@@ -686,7 +686,7 @@ TEST_CASE("when multi-line values are enabled, write newlines as multi-line valu
686686

687687
REQUIRE(str == "[Foo]\n"
688688
"bar=Hello\n"
689-
"\tworld!\n");
689+
"\tworld!\n\n");
690690
}
691691

692692
TEST_CASE("stringInsensitiveLess operator() returns true if and only if first parameter is less than the second "
@@ -902,4 +902,4 @@ TEST_CASE("parse section with duplicate field and overwriteDuplicateFields_ set
902902
ini::IniFile inif;
903903
inif.allowOverwriteDuplicateFields(false);
904904
REQUIRE_THROWS(inif.decode("[Foo]\nbar=hello\nbar=world"));
905-
}
905+
}

0 commit comments

Comments
 (0)