aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authorMathias Gumz <akira at fluxbox dot org>2010-08-24 15:30:24 (GMT)
committerMathias Gumz <akira at fluxbox dot org>2010-08-24 15:30:24 (GMT)
commitb8987fc6238a747285b3aeac6f3b206a74e0d36a (patch)
treef8826582a15deec69942310e4405aac3b412b4c0 /src/FbTk
parent874eb67297cd63999730d1e779ff00581dcbb89d (diff)
downloadfluxbox-b8987fc6238a747285b3aeac6f3b206a74e0d36a.zip
fluxbox-b8987fc6238a747285b3aeac6f3b206a74e0d36a.tar.bz2
code simplification / deduplication
* parse the string only once for a bunch of chars to check instead of starting over again and again from the beginning, created a helper function to do this (FbTk::StringUtil::findCharFromAlphabetAfterTrigger) * put same code into a function (setClockModeLabel()) * use much simpler code to switch between 12h and 24h mode and replace the fmt-switches
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/StringUtil.cc18
-rw-r--r--src/FbTk/StringUtil.hh12
2 files changed, 30 insertions, 0 deletions
diff --git a/src/FbTk/StringUtil.cc b/src/FbTk/StringUtil.cc
index 602211e..4678f03 100644
--- a/src/FbTk/StringUtil.cc
+++ b/src/FbTk/StringUtil.cc
@@ -164,6 +164,24 @@ string findExtension(const string &filename) {
164 return filename.substr(start_pos + 1); 164 return filename.substr(start_pos + 1);
165} 165}
166 166
167string::size_type findCharFromAlphabetAfterTrigger(const std::string& in, char trigger, const char alphabet[], size_t len_alphabet, size_t* found) {
168 for (const char* s = in.c_str(); *s != '\0'; ) {
169 if (*s++ == trigger && *s != '\0') {
170 for (const char* a = alphabet; (a - alphabet) < len_alphabet; ++a) {
171 if (*s == *a) {
172 if (found) {
173 *found = a - alphabet;
174 }
175 return s - in.c_str() - 1;
176 }
177 }
178 s++;
179 }
180 }
181 return string::npos;
182}
183
184
167string replaceString(const string &original, 185string replaceString(const string &original,
168 const char *findthis, 186 const char *findthis,
169 const char *replace) { 187 const char *replace) {
diff --git a/src/FbTk/StringUtil.hh b/src/FbTk/StringUtil.hh
index 7bc8f80..a16e709 100644
--- a/src/FbTk/StringUtil.hh
+++ b/src/FbTk/StringUtil.hh
@@ -50,6 +50,18 @@ std::string expandFilename(const std::string &filename);
50/// @return extension of filename (ex: filename.txt will return txt) 50/// @return extension of filename (ex: filename.txt will return txt)
51std::string findExtension(const std::string &filename); 51std::string findExtension(const std::string &filename);
52 52
53/// is the char after a 'trigger' part of an alphabet?
54/// @param in - string to analyze
55/// @param trigger - check for char after trigger
56/// @param alphabet - contains chars to search for
57/// @param len_alphabet - length of alphabet
58/// @param found - position of found char in alphabet (optional)
59/// @return position of trigger if found
60/// @return std::string::npos if nothing found
61std::string::size_type findCharFromAlphabetAfterTrigger(const std::string& in,
62 char trigger,
63 const char alphabet[], size_t len_alphabet, size_t* found);
64
53/// @return copy of original with find_string replaced with "replace" 65/// @return copy of original with find_string replaced with "replace"
54std::string replaceString(const std::string &original, 66std::string replaceString(const std::string &original,
55 const char *find_string, 67 const char *find_string,