diff options
author | Jens Heuschkel <heuschkel@tk.tu-darmstadt.de> | 2016-11-22 13:39:42 (GMT) |
---|---|---|
committer | Jens Heuschkel <heuschkel@tk.tu-darmstadt.de> | 2016-11-22 13:39:42 (GMT) |
commit | 212ec100f9296f5e23d929619f6cf06669de71f4 (patch) | |
tree | 60f98cb9deb0a20eee532ad9a7e9b2bddf90fc5f /src/uscxml/util/String.cpp | |
parent | 037c084255be481f94b039fb787bab37b0e82c75 (diff) | |
download | uscxml-212ec100f9296f5e23d929619f6cf06669de71f4.zip uscxml-212ec100f9296f5e23d929619f6cf06669de71f4.tar.gz uscxml-212ec100f9296f5e23d929619f6cf06669de71f4.tar.bz2 |
improved excapeMacro to produce vhdl supported names
Diffstat (limited to 'src/uscxml/util/String.cpp')
-rw-r--r-- | src/uscxml/util/String.cpp | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/src/uscxml/util/String.cpp b/src/uscxml/util/String.cpp index f189140..ae1aa68 100644 --- a/src/uscxml/util/String.cpp +++ b/src/uscxml/util/String.cpp @@ -25,31 +25,26 @@ namespace uscxml { #define ISWHITESPACE(char) (isspace(char)) -std::string escapedMacro(std::string const& s) { +std::string escapeMacro(std::string const &s) { // inspired by http://stackoverflow.com/questions/2417588/escaping-a-c-string std::string returnValue=""; + std::string specialChars=""; for (std::string::const_iterator iter = s.begin(), end = s.end(); iter != end; ++iter) { char c = *iter; - if (' ' <= c && c <= '~' && c != '\\' && c != '"') { + if (('0' <= c && c <= '9') || ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') || c == '_') { returnValue += c; } else { - returnValue += "_"; - switch(c) { - case '"': returnValue += "COLON"; break; - case '\\': returnValue += "BACHSLASH"; break; - case '\t': returnValue += "TAB"; break; - case '\r': returnValue += "RETURN"; break; - case '\n': returnValue += "NEWLINE"; break; - default: - char const* const hexdig = "0123456789ABCDEF"; - returnValue += 'x'; - returnValue += hexdig[c >> 4]; - returnValue += hexdig[c & 0xF]; - } - returnValue += "_"; + specialChars += c; } } + if (!specialChars.empty()){ + // http://www.cplusplus.com/reference/functional/hash/ + // returns the same result for a given string within one execution + std::hash<std::string> strHash; + returnValue += "_"; + returnValue += strHash(specialChars); + } return returnValue; } |