Skip to content

Commit ad853dd

Browse files
committed
Fixed #16 saveToFile/saveToString will be has &sError parameter
1 parent 7ee46b9 commit ad853dd

12 files changed

+17
-16
lines changed

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ int main(int argc, char* argv[]) {
2222
return -1;
2323
}
2424

25-
if (!yaml.saveToFile(sFilePath)) {
26-
WsjcppLog::err(TAG, "Could not save data to file");
25+
if (!yaml.saveToFile(sFilePath, sError)) {
26+
WsjcppLog::err(TAG, "Could not save data to file: " + sError);
2727
return -1;
2828
}
2929

src/wsjcpp_yaml.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,9 +1246,10 @@ bool WsjcppYaml::loadFromFile(const std::string &sFileName, std::string &sError)
12461246

12471247
// ---------------------------------------------------------------------
12481248

1249-
bool WsjcppYaml::saveToFile(const std::string &sFileName) {
1249+
bool WsjcppYaml::saveToFile(const std::string &sFileName, std::string &sError) {
12501250
std::string sBuffer = m_pRoot->toString();
12511251
if (!WsjcppCore::writeFile(sFileName, sBuffer)) {
1252+
sError = "Could not save to file";
12521253
return false;
12531254
}
12541255
return true;
@@ -1262,7 +1263,7 @@ bool WsjcppYaml::loadFromString(const std::string &sBufferName, const std::strin
12621263

12631264
// ---------------------------------------------------------------------
12641265

1265-
bool WsjcppYaml::saveToString(std::string &sBuffer) {
1266+
bool WsjcppYaml::saveToString(std::string &sBuffer, std::string &sError) {
12661267
sBuffer = m_pRoot->toString();
12671268
return true;
12681269
}

src/wsjcpp_yaml.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ class WsjcppYaml {
255255
~WsjcppYaml();
256256
void clear();
257257
bool loadFromFile(const std::string &sFileName, std::string &sError);
258-
bool saveToFile(const std::string &sFileName);
258+
bool saveToFile(const std::string &sFileName, std::string &sError);
259259
bool loadFromString(const std::string &sBufferName, const std::string &sBuffer, std::string &sError);
260-
bool saveToString(std::string &sBuffer);
260+
bool saveToString(std::string &sBuffer, std::string &sError);
261261
WsjcppYamlNode *getRoot();
262262

263263
WsjcppYamlCursor getCursor() const;

unit-tests.wsjcpp/src/unit_test_cursor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void UnitTestCursor::executeTest() {
104104

105105
compare("map use as array", yaml["map1"][0].isNull(), true);
106106
compare("array use as map", yaml["arr1"]["0"].isNull(), true);
107-
compare("array use as map", yaml["arr1"][0].isNull(), false);
107+
compare("array use as array", yaml["arr1"][0].isNull(), false);
108108

109109
compare("array size", yaml["arr1"].comment(), "some comment array 1");
110110
compare("array size", yaml["arr1"].size(), 6);

unit-tests.wsjcpp/src/unit_test_read_write_file.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void UnitTestReadWriteFile::executeTest() {
4646

4747
compare("version-value", yaml.getRoot()->getElement("version")->getValue(), "3");
4848

49-
if (!compare("Error parsing", yaml.saveToFile(sFilepathOutput), true)) {
49+
if (!compare("Error parsing", yaml.saveToFile(sFilepathOutput, sError), true)) {
5050
WsjcppLog::err(TAG, sError);
5151
return;
5252
}

unit-tests.wsjcpp/src/unit_test_yaml_parser_all.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void UnitTestYamlParserAll::executeTest() {
6666
}
6767

6868
std::string sSaved1 = "";
69-
if (!compare("Error saving", yaml.saveToString(sSaved1), true)) {
69+
if (!compare("Error saving", yaml.saveToString(sSaved1, sError), true)) {
7070
compare("yaml_saved 2-test", sSaved1, sTestYaml);
7171
return;
7272
}
@@ -98,7 +98,7 @@ void UnitTestYamlParserAll::executeTest() {
9898
compare("test80_comment", pItem->getValue(), "opa2");
9999

100100
std::string sSaved2 = "";
101-
if (compare("saving yaml", yaml.saveToString(sSaved2), true)) {
101+
if (compare("saving yaml", yaml.saveToString(sSaved2, sError), true)) {
102102
compare("yaml_saved 1-2", sSaved1, sSaved2);
103103
}
104104
}

unit-tests.wsjcpp/src/unit_test_yaml_parser_array_included_map.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void UnitTestYamlParserArrayIncludedMap::executeTest() {
9090
compare("param2-value", yaml.getRoot()->getElement("param2")->getValue(), "v2");
9191

9292
std::string sSaved = "";
93-
if (compare("save yaml", yaml.saveToString(sSaved), true)) {
93+
if (compare("save yaml", yaml.saveToString(sSaved, sError), true)) {
9494
compare("yaml_save", sSaved,
9595
"# test array included map\n" // expected
9696
"param1: none value1 # it's value for something # olala\n"

unit-tests.wsjcpp/src/unit_test_yaml_parser_comments.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void UnitTestYamlParserComments::executeTest() {
8585
// compare("param2", yaml.getRoot()->getElement("param2")->getComment(), "some comment 2");
8686

8787
std::string sSaved = "";
88-
compare("save yaml", yaml.saveToString(sSaved), true);
88+
compare("save yaml", yaml.saveToString(sSaved, sError), true);
8989
compare("yaml_save", sSaved,
9090
"# Some comment 1\n"
9191
"param1: value1 # comment 2 # comment\n"

unit-tests.wsjcpp/src/unit_test_yaml_parser_hierarchical_map.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void UnitTestYamlParserHierarchicalMap::executeTest() {
8888
compare("param2", yaml.getRoot()->getElement("param2")->getComment(), "some comment 2");
8989

9090
std::string sSaved = "";
91-
bool bResult = yaml.saveToString(sSaved);
91+
bool bResult = yaml.saveToString(sSaved, sError);
9292
if (compare("save yaml", bResult, true)) {
9393
compare("yaml_save", sSaved,
9494
"# Some comment 1\n"

unit-tests.wsjcpp/src/unit_test_yaml_parser_quotes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void UnitTestYamlParserQuotes::executeTest() {
7676
compare("array-element0-value", yaml.getRoot()->getElement("array")->getElement(0)->getValue(), "https://github.com/wsjcpp/wsjcpp-core:v0.0.1");
7777

7878
std::string sSaved = "";
79-
compare("save yaml", yaml.saveToString(sSaved), true);
79+
compare("save yaml", yaml.saveToString(sSaved, sError), true);
8080
compare("yaml_save", sSaved,
8181
"# Some comment 1\n"
8282
"param1: \"value1\" # v1\n"

0 commit comments

Comments
 (0)