61 std::istringstream stream(content);
64 bool in_define_block =
false;
65 bool reading_description =
false;
67 bool has_param_attributes =
false;
69 while (std::getline(stream, line)) {
71 if (line.find(
";#PATCH_NAME=") != std::string::npos) {
72 size_t pos = line.find(
'=');
73 if (pos != std::string::npos) {
74 name_ = Trim(line.substr(pos + 1));
80 if (line.find(
";#PATCH_AUTHOR=") != std::string::npos) {
81 size_t pos = line.find(
'=');
82 if (pos != std::string::npos) {
83 author_ = Trim(line.substr(pos + 1));
89 if (line.find(
";#PATCH_VERSION=") != std::string::npos) {
90 size_t pos = line.find(
'=');
91 if (pos != std::string::npos) {
92 version_ = Trim(line.substr(pos + 1));
98 if (line.find(
";#PATCH_DESCRIPTION") != std::string::npos) {
99 reading_description =
true;
105 if (line.find(
";#ENDPATCH_DESCRIPTION") != std::string::npos) {
106 reading_description =
false;
111 if (reading_description) {
112 std::string desc_line = line;
114 while (!desc_line.empty() && desc_line[0] ==
';') {
115 desc_line = desc_line.substr(1);
122 if (line.find(
";#ENABLED=") != std::string::npos) {
123 size_t pos = line.find(
'=');
124 if (pos != std::string::npos) {
125 std::string value = absl::AsciiStrToLower(Trim(line.substr(pos + 1)));
126 enabled_ = (value ==
"true" || value ==
"1");
132 if (line.find(
";#DEFINE_START") != std::string::npos) {
133 in_define_block =
true;
135 has_param_attributes =
false;
140 if (line.find(
";#DEFINE_END") != std::string::npos) {
141 in_define_block =
false;
146 if (in_define_block) {
148 if (line.find(
";#") != std::string::npos) {
149 size_t hash_pos = line.find(
";#");
150 std::string attr_line = line.substr(hash_pos + 2);
151 size_t eq_pos = attr_line.find(
'=');
153 if (eq_pos != std::string::npos) {
154 std::string key = absl::AsciiStrToLower(Trim(attr_line.substr(0, eq_pos)));
155 std::string value = Trim(attr_line.substr(eq_pos + 1));
159 has_param_attributes =
true;
160 }
else if (key ==
"type") {
162 has_param_attributes =
true;
163 }
else if (key ==
"range") {
165 size_t comma_pos = value.find(
',');
166 if (comma_pos != std::string::npos) {
170 }
else if (key ==
"checkedvalue") {
172 }
else if (key ==
"uncheckedvalue") {
174 }
else if (key ==
"decimal") {
176 }
else if (key.starts_with(
"choice")) {
178 current_param.
choices.push_back(value);
179 }
else if (key.starts_with(
"bit")) {
183 if (key.size() > 3) {
184 bit_index = std::stoi(key.substr(3));
187 while (current_param.
choices.size() <=
static_cast<size_t>(bit_index)) {
188 current_param.
choices.push_back(
"");
190 current_param.
choices[bit_index] = value;
197 std::string trimmed = Trim(line);
198 if (!trimmed.empty() && trimmed[0] ==
'!') {
199 size_t eq_pos = trimmed.find(
'=');
200 if (eq_pos != std::string::npos) {
201 current_param.
define_name = Trim(trimmed.substr(0, eq_pos));
202 std::string value_str = Trim(trimmed.substr(eq_pos + 1));
207 switch (current_param.
type) {
226 has_param_attributes =
false;
248 std::string lower = absl::AsciiStrToLower(type_str);
250 if (lower.find(
"byte") != std::string::npos) {
252 }
else if (lower.find(
"word") != std::string::npos) {
254 }
else if (lower.find(
"long") != std::string::npos) {
256 }
else if (lower.find(
"bool") != std::string::npos) {
258 }
else if (lower.find(
"choice") != std::string::npos) {
260 }
else if (lower.find(
"bitfield") != std::string::npos) {
262 }
else if (lower.find(
"item") != std::string::npos) {
270 std::string trimmed = Trim(value_str);
271 if (trimmed.empty())
return 0;
274 if (trimmed[0] ==
'$') {
276 return std::stoi(trimmed.substr(1),
nullptr, 16);
283 if (trimmed.size() > 2 && trimmed[0] ==
'0' &&
284 (trimmed[1] ==
'x' || trimmed[1] ==
'X')) {
286 return std::stoi(trimmed.substr(2),
nullptr, 16);
294 return std::stoi(trimmed);
344 const std::string& new_value) {
345 size_t pos = content.find(prefix);
346 if (pos == std::string::npos)
return;
348 size_t line_end = content.find(
'\n', pos);
349 if (line_end == std::string::npos) {
350 line_end = content.size();
354 std::string new_line = prefix + new_value;
355 content.replace(pos, line_end - pos, new_line);
359 const std::string& define_name,
int value) {
361 size_t pos = content.find(define_name);
362 if (pos == std::string::npos)
return;
365 size_t line_end = content.find(
'\n', pos);
366 if (line_end == std::string::npos) {
367 line_end = content.size();
371 std::string new_line = absl::StrFormat(
"%s = $%02X", define_name, value);
372 content.replace(pos, line_end - pos, new_line);