From fa45b822bb8cdcd3fb3654ee099bdeddd2290a5c Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 28 Jul 2008 22:12:28 +0000 Subject: label protection --- src/auxiliary/functions.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/auxiliary/functions.cc') diff --git a/src/auxiliary/functions.cc b/src/auxiliary/functions.cc index dbfc799..a6187af 100644 --- a/src/auxiliary/functions.cc +++ b/src/auxiliary/functions.cc @@ -143,4 +143,26 @@ void trim(std::string &text) } } +void to_label(std::string &text) +{ + trim(text); + size_t pos = 0; + + while (pos < text.size()) { + if ((text[pos] == ' ') || (text[pos] == '-')) { + text[pos] = '_'; + pos++; + } else if ((text[pos] >= 'A') && (text[pos] <= 'Z')) { + text[pos] = text[pos] + 'a' - 'A'; + pos++; + } else if ((text[pos] >= 'a') && (text[pos] <= 'z')) { + pos++; + } else if ((text[pos] >= '0') && (text[pos] <= '9')) { + pos++; + } else { + text.erase(pos, 1); + } + } +} + } -- cgit v1.2.3