* Parse a single entry via a template and output this. * @param item The template to use for the output. * @param grp Group current being used for template rendering. * @param default_grp Default values for items not set in @grp. * @param output Output to use for result. */
| 220 | * @param output Output to use for result. |
| 221 | */ |
| 222 | static void DumpLine(const IniItem *item, const IniGroup *grp, const IniGroup *default_grp, OutputStore &output) |
| 223 | { |
| 224 | /* Prefix with #if/#ifdef/#ifndef */ |
| 225 | static const auto pp_lines = {"if", "ifdef", "ifndef"}; |
| 226 | int count = 0; |
| 227 | for (const auto &name : pp_lines) { |
| 228 | auto condition = FindItemValue(name, grp, default_grp); |
| 229 | if (condition.has_value()) { |
| 230 | output.Add("#"); |
| 231 | output.Add(name); |
| 232 | output.Add(" "); |
| 233 | output.Add(*condition); |
| 234 | output.Add("\n"); |
| 235 | count++; |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | /* Output text of the template, except template variables of the form '$[_a-z0-9]+' which get replaced by their value. */ |
| 240 | static const std::string_view variable_name_characters = "_abcdefghijklmnopqrstuvwxyz0123456789"; |
| 241 | StringConsumer consumer{*item->value}; |
| 242 | while (consumer.AnyBytesLeft()) { |
| 243 | char c = consumer.ReadChar(); |
| 244 | if (c != '$' || consumer.ReadIf("$")) { |
| 245 | /* No $ or $$ (literal $). */ |
| 246 | output.Add(std::string_view{&c, 1}); |
| 247 | continue; |
| 248 | } |
| 249 | |
| 250 | std::string_view variable = consumer.ReadUntilCharNotIn(variable_name_characters); |
| 251 | if (!variable.empty()) { |
| 252 | /* Find the text to output. */ |
| 253 | auto valitem = FindItemValue(variable, grp, default_grp); |
| 254 | if (valitem.has_value()) output.Add(*valitem); |
| 255 | } else { |
| 256 | output.Add("$"); |
| 257 | } |
| 258 | } |
| 259 | output.Add("\n"); // \n after the expanded template. |
| 260 | while (count > 0) { |
| 261 | output.Add("#endif\n"); |
| 262 | count--; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * Output all non-special sections through the template / template variable expansion system. |
no test coverage detected