diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2019-08-21 12:10:34 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2019-08-21 12:10:34 +0200 |
commit | 44b929bb1611ce98e926b2f4846565338f344d48 (patch) | |
tree | 73f9a7acc91b569dfa8ae70710b1ea4af93bac9f /libbutl/utility.mxx | |
parent | 94e98b452130115fd76aea12b978d9e0bfd77a88 (diff) |
Add sanitize_identifier() utility function
Diffstat (limited to 'libbutl/utility.mxx')
-rw-r--r-- | libbutl/utility.mxx | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/libbutl/utility.mxx b/libbutl/utility.mxx index 8085e79..03fb89e 100644 --- a/libbutl/utility.mxx +++ b/libbutl/utility.mxx @@ -186,6 +186,15 @@ LIBBUTL_MODEXPORT namespace butl next_word (const std::string&, std::size_t n, std::size_t& b, std::size_t& e, char d1 = ' ', char d2 = '\0'); + // Sanitize a string to only contain characters valid in an identifier + // (ASCII alphanumeric plus `_`) replacing all others with `_`. + // + // Note that it doesn't make sure the first character is not a digit. + // + std::string& sanitize_identifier (std::string&); + std::string sanitize_identifier (std::string&&); + std::string sanitize_identifier (const std::string&); + // If an input stream is in a failed state, then return true if this is // because of the eof and throw istream::failure otherwise. If the stream // is not in a failed state, return false. This helper function is normally |