diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2019-08-22 13:30:15 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2019-08-22 13:30:15 +0300 |
commit | bb08cf0b2a2b3a8a9a52d53e6fb4813ac1fa487c (patch) | |
tree | e38e874e825b9d95872667305931df9fff0ca560 | |
parent | a37431f8109cb67937ad5356e8209a7151ad5a61 (diff) |
Make use of butl::sanitize_identifier()
-rw-r--r-- | bdep/new.cxx | 26 | ||||
-rw-r--r-- | bdep/utility.hxx | 1 |
2 files changed, 11 insertions, 16 deletions
diff --git a/bdep/new.cxx b/bdep/new.cxx index 3a79486..681cc18 100644 --- a/bdep/new.cxx +++ b/bdep/new.cxx @@ -470,12 +470,7 @@ namespace bdep case lang::c: case lang::cxx: { - auto sanitize = [] (char c) - { - return (c == '-' || c == '+' || c == '.') ? '_' : c; - }; - - transform (s.begin (), s.end (), back_inserter (id), sanitize); + id = sanitize_identifier (const_cast<const string&> (s)); break; } } @@ -1380,15 +1375,14 @@ namespace bdep { string ip (d.posix_representation ()); // Include prefix. - string mp; // Macro prefix. - transform ( - ip.begin (), ip.end () - 1, back_inserter (mp), - [] (char c) - { - return (c == '-' || c == '+' || c == '.' || c == '/') - ? '_' - : ucase (c); - }); + // Macro prefix. + // + string mp ( + sanitize_identifier (ucase (const_cast<const string&> (ip)))); + + // Strip the trailing underscore (produced from slash). + // + mp.pop_back (); string apih; // API header name. string exph; // Export header name (empty if binless). @@ -1409,7 +1403,7 @@ namespace bdep << endl << "#include <stdio.h>" << endl << endl - << "#include <" << ip << exph << ">" << endl + << "#include <" << ip << exph << ">" << endl << endl << "// Print a greeting for the specified name into the specified" << endl << "// stream. On success, return the number of character printed." << endl diff --git a/bdep/utility.hxx b/bdep/utility.hxx index c4cdef5..6121593 100644 --- a/bdep/utility.hxx +++ b/bdep/utility.hxx @@ -49,6 +49,7 @@ namespace bdep using butl::trim; using butl::next_word; + using butl::sanitize_identifier; using butl::reverse_iterate; |