#pragma once #include #include #include #include #include /// Just enough of CMake's syntax to find and edit a command call in a CMakeLists.txt or a settings /// file without disturbing anything else in it: comments, layout and line endings stay as they /// were. namespace breeze::cmake { /// One argument of a call. begin/end are byte offsets of the argument as written (quotes /// included); text is its value without the quotes. struct Token { std::size_t begin = 0; std::size_t end = 0; std::string text; bool quoted = false; }; /// A command call: name(args...). begin/end span the whole call, "name(" through ")". struct Call { std::string name; std::size_t begin = 0; std::size_t end = 0; std::vector args; }; /// Every call in `text`, in order, whose name `wanted` accepts. Comments, quoted strings and /// the arguments of other calls are never mistaken for calls. std::vector findCalls(const std::string& text, const std::function& wanted); /// The first set( ...) call. std::optional findSet(const std::string& text, const std::string& variable); /// `value` as a quoted CMake argument. std::string quote(const std::string& value); /// Replaces the token's text in `text` (offsets of later tokens are stale afterwards). void replaceToken(std::string& text, const Token& token, const std::string& replacement); }