63 std::istringstream stream(content);
66 bool in_define_block =
false;
67 bool reading_description =
false;
69 bool has_param_attributes =
false;
71 while (std::getline(stream, line)) {
73 if (line.find(
";#PATCH_NAME=") != std::string::npos) {
74 size_t pos = line.find(
'=');
75 if (pos != std::string::npos) {
76 name_ = Trim(line.substr(pos + 1));
82 if (line.find(
";#PATCH_AUTHOR=") != std::string::npos) {
83 size_t pos = line.find(
'=');
84 if (pos != std::string::npos) {
85 author_ = Trim(line.substr(pos + 1));
91 if (line.find(
";#PATCH_VERSION=") != std::string::npos) {
92 size_t pos = line.find(
'=');
93 if (pos != std::string::npos) {
94 version_ = Trim(line.substr(pos + 1));
100 if (line.find(
";#PATCH_DESCRIPTION") != std::string::npos) {
101 reading_description =
true;
107 if (line.find(
";#ENDPATCH_DESCRIPTION") != std::string::npos) {
108 reading_description =
false;
113 if (reading_description) {
114 std::string desc_line = line;
116 while (!desc_line.empty() && desc_line[0] ==
';') {
117 desc_line = desc_line.substr(1);
124 if (line.find(
";#ENABLED=") != std::string::npos) {
125 size_t pos = line.find(
'=');
126 if (pos != std::string::npos) {
127 std::string value = absl::AsciiStrToLower(Trim(line.substr(pos + 1)));
128 enabled_ = (value ==
"true" || value ==
"1");
134 if (line.find(
";#DEFINE_START") != std::string::npos) {
135 in_define_block =
true;
137 has_param_attributes =
false;
142 if (line.find(
";#DEFINE_END") != std::string::npos) {
143 in_define_block =
false;
148 if (in_define_block) {
150 if (line.find(
";#") != std::string::npos) {
151 size_t hash_pos = line.find(
";#");
152 std::string attr_line = line.substr(hash_pos + 2);
153 size_t eq_pos = attr_line.find(
'=');
155 if (eq_pos != std::string::npos) {
157 absl::AsciiStrToLower(Trim(attr_line.substr(0, eq_pos)));
158 std::string value = Trim(attr_line.substr(eq_pos + 1));
162 has_param_attributes =
true;
163 }
else if (key ==
"type") {
165 has_param_attributes =
true;
166 }
else if (key ==
"range") {
168 size_t comma_pos = value.find(
',');
169 if (comma_pos != std::string::npos) {
173 ParseValue(Trim(value.substr(comma_pos + 1)));
175 }
else if (key ==
"checkedvalue") {
177 }
else if (key ==
"uncheckedvalue") {
179 }
else if (key ==
"decimal") {
181 }
else if (key.starts_with(
"choice")) {
183 current_param.
choices.push_back(value);
184 }
else if (key.starts_with(
"bit")) {
188 if (key.size() > 3) {
189 bit_index = std::stoi(key.substr(3));
192 while (current_param.
choices.size() <=
193 static_cast<size_t>(bit_index)) {
194 current_param.
choices.push_back(
"");
196 current_param.
choices[bit_index] = value;
203 std::string trimmed = Trim(line);
204 if (!trimmed.empty() && trimmed[0] ==
'!') {
205 size_t eq_pos = trimmed.find(
'=');
206 if (eq_pos != std::string::npos) {
207 current_param.
define_name = Trim(trimmed.substr(0, eq_pos));
208 std::string value_str = Trim(trimmed.substr(eq_pos + 1));
213 switch (current_param.
type) {
232 has_param_attributes =
false;
254 std::string lower = absl::AsciiStrToLower(type_str);
256 if (lower.find(
"byte") != std::string::npos) {
258 }
else if (lower.find(
"word") != std::string::npos) {
260 }
else if (lower.find(
"long") != std::string::npos) {
262 }
else if (lower.find(
"bool") != std::string::npos) {
264 }
else if (lower.find(
"choice") != std::string::npos) {
266 }
else if (lower.find(
"bitfield") != std::string::npos) {
268 }
else if (lower.find(
"item") != std::string::npos) {
276 std::string trimmed = Trim(value_str);
281 if (trimmed[0] ==
'$') {
283 return std::stoi(trimmed.substr(1),
nullptr, 16);
290 if (trimmed.size() > 2 && trimmed[0] ==
'0' &&
291 (trimmed[1] ==
'x' || trimmed[1] ==
'X')) {
293 return std::stoi(trimmed.substr(2),
nullptr, 16);
301 return std::stoi(trimmed);
351 const std::string& new_value) {
352 size_t pos = content.find(prefix);
353 if (pos == std::string::npos)
356 size_t line_end = content.find(
'\n', pos);
357 if (line_end == std::string::npos) {
358 line_end = content.size();
362 std::string new_line = prefix + new_value;
363 content.replace(pos, line_end - pos, new_line);
367 const std::string& define_name,
int value) {
369 size_t pos = content.find(define_name);
370 if (pos == std::string::npos)
374 size_t line_end = content.find(
'\n', pos);
375 if (line_end == std::string::npos) {
376 line_end = content.size();
380 std::string new_line = absl::StrFormat(
"%s = $%02X", define_name, value);
381 content.replace(pos, line_end - pos, new_line);