-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_settings.cpp
104 lines (91 loc) · 4.51 KB
/
parse_settings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "parse_settings.h"
#include <iostream>
#include "utilities.h"
using json = nlohmann::json;
namespace fs = std::filesystem;
FileSettings::FileSettings(fs::path settingsPath) {
fileExtension = '.' + settingsPath.stem().string();
json settingsJson = fetchJson(settingsPath);
if (settingsJson.contains("addPatchMakersComment")) {
addPatchMakersComment = settingsJson["addPatchMakersComment"];
}
if (settingsJson.contains("valuesContainNewlines")) {
valuesContainNewlines = settingsJson["valuesContainNewlines"];
}
if (settingsJson.contains("values")) {
//TODO: Handle invalid types more gracefully.
json valuesArrayJson = settingsJson["values"];
for (json::iterator iteration = valuesArrayJson.begin(); iteration != valuesArrayJson.end(); ++iteration) {
json valuesJson = iteration.value();
PointerSettings pointerSettings;
if (valuesJson.contains("path")) {
pointerSettings.path = valuesJson["path"];
if (valuesJson.contains("from")) {
pointerSettings.from = valuesJson["from"];
}
if (valuesJson.contains("numericIteratorMarker")) {
pointerSettings.numericIteratorMarker = valuesJson["numericIteratorMarker"];
}
if (valuesJson.contains("reference")) {
pointerSettings.reference = valuesJson["reference"];
}
if (valuesJson.contains("convertBreakoutNewlines")) {
pointerSettings.convertBreakoutNewlines = valuesJson["convertBreakoutNewlines"];
}
if (valuesJson.contains("intermediaryPlaceholderCondition")) {
std::string value = valuesJson["intermediaryPlaceholderCondition"];
if (value == "never") {
pointerSettings.intermediaryPlaceholderCondition = never;
} else if (value == "when possible") {
pointerSettings.intermediaryPlaceholderCondition = whenPossible;
} else if (value == "from exists") {
pointerSettings.intermediaryPlaceholderCondition = fromExists;
} else {
std::cout << "parse_settings \"" << value << "\" is not a valid value for intermediaryPlaceholderCondition.\n";
}
}
if (valuesJson.contains("intermediaryLabel")) {
pointerSettings.intermediaryLabel = valuesJson["intermediaryLabel"];
}
if (valuesJson.contains("patchTestOperation")) {
pointerSettings.patchTestOperation = valuesJson["patchTestOperation"];
}
if (valuesJson.contains("patchOperationIfPlaceholder")) {
std::string value = valuesJson["patchOperationIfPlaceholder"];
if (value == "none") {
pointerSettings.patchOperationIfPlaceholder = none;
} else if (value == "copy") {
pointerSettings.patchOperationIfPlaceholder = copy;
} else if (value == "move") {
pointerSettings.patchOperationIfPlaceholder = move;
} else {
std::cout << "parse_settings \"" << value << "\" is not a valid value for patchOperationIfPlaceholder.\n";
}
}
if (valuesJson.contains("patchRemoveIfEquals")) {
pointerSettings.patchRemoveIfEquals = valuesJson["patchRemoveIfEquals"].dump();
}
allPointerSettings.push_back(pointerSettings);
}
}
}
}
/**
* Writes example settings to a string stream.
*
* @param settingsText The std::stringstream that will be written to.
*/
void FileSettings::writeExampleSettings(std::stringstream & settingsText) {
//TODO: Write example settings.
}
/**
* @return If there are any pointerSettings in allPointerSettings.
*/
const bool FileSettings::hasPointerSettings() {
return allPointerSettings.size() >= 1;
}
//Getters
const std::string FileSettings::getFileExtension() { return fileExtension; }
const bool FileSettings::getAddPatchMakersComment() { return addPatchMakersComment; }
const bool FileSettings::getValuesContainNewlines() { return valuesContainNewlines; }
std::vector<PointerSettings> FileSettings::getAllPointerSettings() { return allPointerSettings; }