Skip to content

Handling $ in multiline mode #334

@ashvardanian

Description

@ashvardanian

I'm facing an issue with the ^\s*([^#:\s]+)\s*:\s*([^#:\s]+)\s*$ pattern in the multiline mode of operation. Here is my code snippet and example input:

static constexpr std::string_view short_config_text =    //
    "# This is a comment line\r\n"                       // Windows newline
    "host : example.com\n"                               // Posix newline
    "\n"                                                 // ... and a typical empty line
    "port: 8080\r"                                       // Commodore newline
    " # Tricky comment with a : colon in the middle\n\r" // Accorn newline
    "\tpath :/api/v1";                                   // No trailing newline!


void config_parse_ctre(std::string_view config_text, std::vector<std::pair<std::string, std::string>> &settings) {
    for (auto match : ctre::multiline_search_all<R"(^\s*([^#:\s]+)\s*:\s*([^#:\s]+)\s*$)">(config_text)) {
        std::string_view key = match.get<1>().to_view();
        std::string_view value = match.get<2>().to_view();
        settings.emplace_back(key, value);
    }
}

Using std::regex, I get 3 key-value pairs, as expected. With ctre::multiline_search_all I am getting only the last one. I suspect it treats the $ as the "end of file", rather than the "end of line". I'm happy to help with the patch 🤗

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions