From bb08cf0b2a2b3a8a9a52d53e6fb4813ac1fa487c Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 22 Aug 2019 13:30:15 +0300 Subject: Make use of butl::sanitize_identifier() --- bdep/new.cxx | 26 ++++++++++---------------- 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 (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 (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 " << 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; -- cgit v1.1