|
cli11
|
Low-level string manipulation shared across the library. More...
#include <cstdlib>import std;Functions | |
| template<typename T> requires std::is_enum_v<T> | |
| auto | cli::enums::operator<< (std::ostream &in, const T &item) -> std::ostream & |
| Streams any enumeration as its underlying integer value. | |
| constexpr auto | cli::detail::hex_convert (char hc) -> std::uint32_t |
| Converts a single hexadecimal digit to its value. | |
| constexpr auto | cli::detail::make_char (std::uint32_t code) -> char |
| Truncates a code unit to a char without sign-extension surprises. | |
| constexpr auto | cli::detail::append_codepoint (std::string &str, std::uint32_t code) -> void |
| Appends a Unicode code point to a string as UTF-8. | |
| constexpr auto | cli::detail::remove_outer (std::string &str, char key) -> std::string & |
Strips a matched pair of key characters from both ends. | |
| constexpr auto | cli::detail::close_string_quote (const std::string &str, std::size_t start, char closure_char) -> std::size_t |
| Finds the closing quote of a string literal, honouring backslash escapes. | |
| constexpr auto | cli::detail::close_literal_quote (const std::string &str, std::size_t start, char closure_char) -> std::size_t |
| Finds the closing quote of a literal string, ignoring escapes. | |
| constexpr auto | cli::detail::handle_secondary_array (std::string &str) -> void |
| Doubles every character of a bracketed sequence, marking it as nested. | |
| auto | cli::detail::split (const std::string &s, char delim) -> std::vector< std::string > |
| Splits a string on a delimiter. | |
| template<typename T> | |
| auto | cli::detail::join (const T &v, std::string_view delim=",") -> std::string |
| Joins a range into a delimited string. | |
| template<typename T, typename callable_t> requires (!std::is_constructible_v<std::string, callable_t>) | |
| auto | cli::detail::join (const T &v, callable_t func, std::string_view delim=",") -> std::string |
| Joins a range into a delimited string, transforming each element. | |
| template<typename T> | |
| auto | cli::detail::rjoin (const T &v, std::string_view delim=",") -> std::string |
| Joins a range into a delimited string in reverse order. | |
| auto | cli::detail::ltrim (std::string &str) -> std::string & |
| Removes leading whitespace in place. | |
| constexpr auto | cli::detail::ltrim (std::string &str, std::string_view filter) -> std::string & |
Removes leading characters that appear in filter, in place. | |
| auto | cli::detail::rtrim (std::string &str) -> std::string & |
| Removes trailing whitespace in place. | |
| constexpr auto | cli::detail::rtrim (std::string &str, std::string_view filter) -> std::string & |
Removes trailing characters that appear in filter, in place. | |
| auto | cli::detail::trim (std::string &str) -> std::string & |
| Removes whitespace from both ends, in place. | |
| constexpr auto | cli::detail::trim (std::string &str, std::string_view filter) -> std::string & |
Removes characters in filter from both ends, in place. | |
| auto | cli::detail::trim_copy (const std::string &str) -> std::string |
| Returns a copy with whitespace removed from both ends. | |
| constexpr auto | cli::detail::trim_copy (const std::string &str, std::string_view filter) -> std::string |
Returns a copy with characters in filter removed from both ends. | |
| constexpr auto | cli::detail::remove_quotes (std::string &str) -> std::string & |
| Strips one matched pair of surrounding quotes, in place. | |
| auto | cli::detail::fix_newlines (const std::string &leader, std::string input) -> std::string |
Inserts leader after every newline. | |
| auto | cli::detail::format_aliases (std::ostream &out, const std::vector< std::string > &aliases, std::size_t wid) -> std::ostream & |
| Writes an indented, comma-separated alias list. | |
| template<typename T> | |
| constexpr auto | cli::detail::valid_first_char (T c) -> bool |
| Tests whether a character may begin an option name. | |
| template<typename T> | |
| constexpr auto | cli::detail::valid_later_char (T c) -> bool |
| Tests whether a character may appear after the first in an option name. | |
| constexpr auto | cli::detail::valid_name_string (const std::string &str) -> bool |
| Tests whether a string is a usable option or subcommand name. | |
| constexpr auto | cli::detail::valid_alias_name_string (const std::string &str) -> bool |
| Tests whether a string is usable as an alias. | |
| constexpr auto | cli::detail::is_separator (const std::string &str) -> bool |
| Tests whether an argument is a group separator. | |
| auto | cli::detail::isalpha (const std::string &str) -> bool |
| Tests whether every character is alphabetic in the current locale. | |
| auto | cli::detail::to_lower (std::string str) -> std::string |
| Returns a lowercased copy, using the current locale. | |
| constexpr auto | cli::detail::remove_underscore (std::string str) -> std::string |
| Returns a copy with every underscore removed. | |
| auto | cli::detail::get_group_separators () -> std::string |
| Returns the characters treated as digit-group separators. | |
| constexpr auto | cli::detail::find_and_replace (std::string str, std::string_view from, std::string_view to) -> std::string |
Replaces every occurrence of from with to. | |
| constexpr auto | cli::detail::has_default_flag_values (const std::string &flags) -> bool |
| Tests whether a flag specification carries default values. | |
| constexpr auto | cli::detail::remove_default_flag_values (std::string &flags) -> void |
| Strips {...} default values and ! negation markers, in place. | |
| auto | cli::detail::find_member (std::string name, const std::vector< std::string > &names, bool ignore_case=false, bool ignore_underscore=false) -> std::optional< std::size_t > |
| Finds a name in a list, optionally ignoring case and underscores. | |
| template<typename callable_t> | |
| auto | cli::detail::find_and_modify (std::string str, std::string_view trigger, callable_t modify) -> std::string |
Repeatedly applies modify at each occurrence of trigger. | |
| constexpr auto | cli::detail::has_escapable_character (const std::string &str) -> bool |
| Tests whether a string contains a character needing an escape. | |
| constexpr auto | cli::detail::add_escaped_characters (const std::string &str) -> std::string |
| Returns a copy with backslash escapes applied. | |
| constexpr auto | cli::detail::remove_escaped_characters (const std::string &str) -> std::string |
| Returns a copy with backslash escapes resolved. | |
| constexpr auto | cli::detail::remove_quotes (std::vector< std::string > &args) -> void |
| Strips surrounding quotes from every argument, in place. | |
| constexpr auto | cli::detail::close_sequence (const std::string &str, std::size_t start, char closure_char) -> std::size_t |
| Finds the index closing a quoted or bracketed sequence. | |
| auto | cli::detail::split_up (std::string str, char delimiter='\0') -> std::vector< std::string > |
| Splits a command line into arguments, respecting quotes and brackets. | |
| constexpr auto | cli::detail::escape_detect (std::string &str, std::size_t offset) -> std::size_t |
| Neutralises a separator that begins a quoted value. | |
| auto | cli::detail::binary_escape_string (const std::string &string_to_escape, bool force=false) -> std::string |
| Encodes non-printable characters as a binary-escaped string. | |
| constexpr auto | cli::detail::is_binary_escaped_string (const std::string &escaped_string) -> bool |
| Tests whether a string carries the binary-escape wrapper. | |
| constexpr auto | cli::detail::extract_binary_string (const std::string &escaped_string) -> std::string |
| Decodes a binary-escaped string. | |
| constexpr auto | cli::detail::process_quoted_string (std::string &str, char string_char='\"', char literal_char = '\'', bool disable_secondary_array_processing = false) -> bool |
| Unwraps a quoted, literal, or binary-escaped string in place. | |
| auto | cli::detail::get_environment_value (const std::string &env_name) -> std::string |
| Reads an environment variable. | |
| auto | cli::detail::stream_out_as_paragraph (std::ostream &out, const std::string &text, std::size_t paragraph_width, const std::string &line_prefix="", bool skip_prefix_on_first_line=false) -> std::ostream & |
| Writes text word-wrapped to a fixed width, prefixing each line. | |
| template<typename T> requires std::is_enum_v<T> | |
| auto | cli::operator<< (std::ostream &in, const T &item) -> std::ostream & |
| Streams any enumeration as its underlying integer value. | |
Variables | |
| constexpr std::string_view | cli::detail::escaped_chars = "\b\t\n\f\r\"\\" |
| Characters that require a backslash escape. | |
| constexpr std::string_view | cli::detail::escaped_chars_code = "btnfr\"\\" |
| Escape codes, index-aligned with escaped_chars. | |
| constexpr std::string_view | cli::detail::bracket_chars = "\"'`[(<{" |
| Characters that open a quoted or bracketed sequence. | |
| constexpr std::string_view | cli::detail::match_bracket_chars = "\"'`])>}" |
| Closing characters, index-aligned with bracket_chars. | |
| constexpr int | cli::detail::expected_max_vector_size {1 << 29} |
| Upper bound on how many values a vector-like option may consume. | |
Low-level string manipulation shared across the library.
Everything here is free-standing text processing: splitting, joining, trimming, quote handling, escape encoding and decoding, and the paragraph wrapper used by the help formatter. Nothing in this partition knows about options or applications.
Most helpers are constexpr. The ones that are not depend on std::locale or std::format, neither of which is usable during constant evaluation.
|
constexprexport |
Returns a copy with backslash escapes applied.
| str | The string to escape. |
|
constexpr |
Appends a Unicode code point to a string as UTF-8.
| [in,out] | str | The string to append to. |
| [in] | code | The code point to encode. |
| std::invalid_argument | If code is a surrogate. |
|
export |
Encodes non-printable characters as a binary-escaped string.
When anything is escaped, or when force is set, the result is wrapped as 'B"(...)"'.
| string_to_escape | The string to encode. |
| force | Wrap the result even when nothing needed escaping. |
|
constexpr |
Finds the closing quote of a literal string, ignoring escapes.
| str | The text to scan. |
| start | Index of the opening quote. |
| closure_char | The quote character to match. |
|
constexprexport |
Finds the index closing a quoted or bracketed sequence.
Nested brackets and quotes are tracked, so the returned index matches the opener at start rather than the first candidate encountered.
| str | The text to scan. |
| start | Index of the opening character. |
| closure_char | The character that closes the sequence. |
|
constexpr |
Finds the closing quote of a string literal, honouring backslash escapes.
| str | The text to scan. |
| start | Index of the opening quote. |
| closure_char | The quote character to match. |
|
constexprexport |
Neutralises a separator that begins a quoted value.
| [in,out] | str | The text being scanned. |
| [in] | offset | Index of the candidate separator. |
|
constexprexport |
Decodes a binary-escaped string.
| escaped_string | The string to decode. |
escaped_string unchanged if it is not wrapped.
|
export |
Repeatedly applies modify at each occurrence of trigger.
| callable_t | Callable taking the string and a position, returning the position to resume searching from. |
| str | The string to rewrite. |
| trigger | The text to search for. |
| modify | Applied at each occurrence. |
|
constexprexport |
Replaces every occurrence of from with to.
| str | The string to rewrite. |
| from | The text to search for. |
| to | The replacement text. |
|
export |
Finds a name in a list, optionally ignoring case and underscores.
| name | The name to search for. |
| names | The list to search. |
| ignore_case | Compare case-insensitively. |
| ignore_underscore | Ignore underscores on both sides of the comparison. |
|
export |
Inserts leader after every newline.
| leader | The text to insert after each line break. |
| input | The text to reflow. |
|
export |
Writes an indented, comma-separated alias list.
Writes nothing when aliases is empty.
| out | The stream to write to. |
| aliases | The aliases to list. |
| wid | Field width for the leading label. |
out, for chaining.
|
export |
Reads an environment variable.
| env_name | The variable to read. |
|
export |
Returns the characters treated as digit-group separators.
Always includes _ and ', plus the locale's thousands separator.
|
constexpr |
Doubles every character of a bracketed sequence, marking it as nested.
| [in,out] | str | The string to rewrite in place; left alone unless it is bracketed with [ and ]. |
|
constexprexport |
Tests whether a flag specification carries default values.
| flags | The flag specification. |
flags contains { or !.
|
constexprexport |
Tests whether a string contains a character needing an escape.
| str | The string to test. |
|
constexpr |
Converts a single hexadecimal digit to its value.
| hc | A hexadecimal digit, in either case. |
hc is not a hexadecimal digit.
|
constexprexport |
Tests whether a string carries the binary-escape wrapper.
| escaped_string | The string to test. |
escaped_string is wrapped as B"(...)" or 'B"(...)"'.
|
constexprexport |
Tests whether an argument is a group separator.
| str | The argument to test. |
|
export |
Tests whether every character is alphabetic in the current locale.
| str | The string to test. |
str is entirely alphabetic.
|
export |
Joins a range into a delimited string, transforming each element.
| T | Any range. |
| callable_t | Any callable mapping an element to something streamable. |
| v | The range to join. |
| func | Applied to each element before it is written. |
| delim | The separator placed between elements. |
|
export |
Joins a range into a delimited string.
A single trailing delimiter is stripped from the result.
| T | Any range whose elements are streamable. |
| v | The range to join. |
| delim | The separator placed between elements. |
|
export |
Removes leading whitespace in place.
| [in,out] | str | The string to trim. |
str.
|
constexprexport |
Removes leading characters that appear in filter, in place.
| [in,out] | str | The string to trim. |
| [in] | filter | The set of characters to strip. |
str.
|
constexpr |
Truncates a code unit to a char without sign-extension surprises.
| code | The value to narrow. |
code, as a char.
|
export |
Streams any enumeration as its underlying integer value.
| T | Any enumeration type. |
| in | The stream to write to. |
| item | The enumerator to write. |
in, for chaining. | auto cli::enums::operator<< | ( | std::ostream & | in, |
| const T & | item ) -> std::ostream & |
Streams any enumeration as its underlying integer value.
| T | Any enumeration type. |
| in | The stream to write to. |
| item | The enumerator to write. |
in, for chaining.
|
constexprexport |
Unwraps a quoted, literal, or binary-escaped string in place.
| [in,out] | str | The string to unwrap. |
| [in] | string_char | The character delimiting escaped strings. |
| [in] | literal_char | The character delimiting literal strings. |
| [in] | disable_secondary_array_processing | Skip the nested-array rewrite. |
str was wrapped and has been unwrapped.
|
constexprexport |
Strips {...} default values and ! negation markers, in place.
| [in,out] | flags | The flag specification to rewrite. |
|
constexprexport |
Returns a copy with backslash escapes resolved.
Understands the codes in escaped_chars_code, \\0, and the \\uXXXX and \\UXXXXXXXX Unicode forms.
| str | The string to unescape. |
| std::invalid_argument | If an escape sequence is truncated or unknown. |
|
constexpr |
Strips a matched pair of key characters from both ends.
| [in,out] | str | The string to strip in place. |
| [in] | key | The character to remove. |
str.
|
constexprexport |
Strips one matched pair of surrounding quotes, in place.
Recognises ", ' and ` .
| [in,out] | str | The string to unquote. |
str.
|
constexprexport |
Strips surrounding quotes from every argument, in place.
Double-quoted arguments additionally have their escapes resolved.
| [in,out] | args | The arguments to unquote. |
|
constexprexport |
Returns a copy with every underscore removed.
| str | The string to strip. |
|
export |
Joins a range into a delimited string in reverse order.
| T | Any bidirectional range whose elements are streamable. |
| v | The range to join. |
| delim | The separator placed between elements. |
|
export |
Removes trailing whitespace in place.
| [in,out] | str | The string to trim. |
str.
|
constexprexport |
Removes trailing characters that appear in filter, in place.
| [in,out] | str | The string to trim. |
| [in] | filter | The set of characters to strip. |
str.
|
export |
Splits a string on a delimiter.
An empty input yields a single empty element.
| s | The string to split. |
| delim | The delimiter to split on. |
|
export |
Splits a command line into arguments, respecting quotes and brackets.
| str | The text to split. |
| delimiter | Separator to split on; '\0' splits on whitespace. |
|
export |
Writes text word-wrapped to a fixed width, prefixing each line.
Existing line breaks in text are preserved; each resulting line is then wrapped independently.
| out | The stream to write to. |
| text | The text to wrap. |
| paragraph_width | Maximum characters per line, excluding the prefix. |
| line_prefix | Written at the start of each line. |
| skip_prefix_on_first_line | Omit the prefix on the first line. |
out, for chaining.
|
export |
Returns a lowercased copy, using the current locale.
| str | The string to convert. |
|
export |
Removes whitespace from both ends, in place.
| [in,out] | str | The string to trim. |
str.
|
constexprexport |
Removes characters in filter from both ends, in place.
| [in,out] | str | The string to trim. |
| [in] | filter | The set of characters to strip. |
str.
|
export |
Returns a copy with whitespace removed from both ends.
| str | The string to trim. |
|
constexprexport |
Returns a copy with characters in filter removed from both ends.
| str | The string to trim. |
| filter | The set of characters to strip. |
|
constexprexport |
Tests whether a string is usable as an alias.
Aliases are unrestricted apart from newlines and embedded nulls.
| str | The candidate alias. |
str contains neither a newline nor a null.
|
constexprexport |
Tests whether a character may begin an option name.
| T | A character type. |
| c | The character to test. |
c is a valid leading character.
|
constexprexport |
Tests whether a character may appear after the first in an option name.
| T | A character type. |
| c | The character to test. |
c is a valid subsequent character.
|
constexprexport |
Tests whether a string is a usable option or subcommand name.
| str | The candidate name. |
|
constexpr |
Characters that open a quoted or bracketed sequence.
Index-aligned with match_bracket_chars: the closing character for bracket_chars[i] is match_bracket_chars[i].
|
constexpr |
Characters that require a backslash escape.
Index-aligned with escaped_chars_code: the escape code for escaped_chars[i] is escaped_chars_code[i].