aboutsummaryrefslogtreecommitdiff
path: root/libbutl/utility.ixx
diff options
context:
space:
mode:
Diffstat (limited to 'libbutl/utility.ixx')
-rw-r--r--libbutl/utility.ixx25
1 files changed, 25 insertions, 0 deletions
diff --git a/libbutl/utility.ixx b/libbutl/utility.ixx
index 04fb161..8f37242 100644
--- a/libbutl/utility.ixx
+++ b/libbutl/utility.ixx
@@ -4,6 +4,7 @@
#ifndef __cpp_lib_modules_ts
#include <cstdlib> // getenv()
+#include <algorithm>
#endif
namespace butl
@@ -192,6 +193,30 @@ namespace butl
return e - b;
}
+ inline std::string&
+ sanitize_identifier (std::string& s)
+ {
+ std::for_each (s.begin (), s.end (), [] (char& c)
+ {
+ if (!alnum (c) && c != '_')
+ c = '_';
+ });
+ return s;
+ }
+
+ inline std::string
+ sanitize_identifier (std::string&& s)
+ {
+ sanitize_identifier (s);
+ return std::move (s);
+ }
+
+ inline std::string
+ sanitize_identifier (const std::string& s)
+ {
+ return sanitize_identifier (std::string (s));
+ }
+
inline bool
eof (std::istream& is)
{