diff options
Diffstat (limited to 'tools/utils.c')
-rw-r--r-- | tools/utils.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tools/utils.c b/tools/utils.c index aecbfda..c544f20 100644 --- a/tools/utils.c +++ b/tools/utils.c @@ -3,6 +3,7 @@ #include <iomanip> //#include <stdlib.h> /* for abs() */ #include <cmath> +#include <ctype.h> /* for isalnum() */ // strip off the directory part of a path, leaving just // the basic filename @@ -58,3 +59,18 @@ std::string ltrim(const std::string foo){ if (where == foo.npos) return foo; return foo.substr(where); } + +static const std::string Pure_Enough("+-_.,@%~"); + +std::string purify(const std::string arg){ + using namespace std; + string rslt(arg); + for (string::iterator ptr = rslt.begin(); + ptr != rslt.end(); ptr++){ + char ch = *ptr; + if (isalnum(ch)) continue; + if (Pure_Enough.find(ch) != string::npos) continue; + *ptr = '~'; + } + return rslt; +} |