aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ClockTool.cc13
-rw-r--r--src/FbTk/StringUtil.cc9
-rw-r--r--src/FbTk/StringUtil.hh2
3 files changed, 18 insertions, 6 deletions
diff --git a/src/ClockTool.cc b/src/ClockTool.cc
index 893d32b..6192c5c 100644
--- a/src/ClockTool.cc
+++ b/src/ClockTool.cc
@@ -47,11 +47,13 @@ const char SWITCHES_SECONDS[] = "crsSTX+";
47const char SWITCHES_12_24H[] = "lIrkHT"; 47const char SWITCHES_12_24H[] = "lIrkHT";
48const char SWITCHES_24_12H[] = "kHTlIr"; 48const char SWITCHES_24_12H[] = "kHTlIr";
49const char SWITCH_AM_PM[] = "pP"; 49const char SWITCH_AM_PM[] = "pP";
50const char IGNORE_AFTER_TRIGGER[] = "0123456789";
50 51
51int showSeconds(const std::string& fmt) { 52int showSeconds(const std::string& fmt) {
52 53
53 return FbTk::StringUtil::findCharFromAlphabetAfterTrigger( 54 return FbTk::StringUtil::findCharFromAlphabetAfterTrigger(
54 fmt, '%', SWITCHES_SECONDS, sizeof(SWITCHES_SECONDS), 0) != std::string::npos; 55 fmt, '%', SWITCHES_SECONDS, sizeof(SWITCHES_SECONDS), 0,
56 IGNORE_AFTER_TRIGGER, sizeof(IGNORE_AFTER_TRIGGER)) != std::string::npos;
55} 57}
56 58
57uint64_t calcNextTimeout(const std::string& fmt) { 59uint64_t calcNextTimeout(const std::string& fmt) {
@@ -82,7 +84,8 @@ public:
82 // does the current format string contain something with 24/12h? 84 // does the current format string contain something with 24/12h?
83 size_t found; 85 size_t found;
84 size_t pos = FbTk::StringUtil::findCharFromAlphabetAfterTrigger( 86 size_t pos = FbTk::StringUtil::findCharFromAlphabetAfterTrigger(
85 m_tool.timeFormat(), '%', SWITCHES_24_12H, sizeof(SWITCHES_24_12H), &found); 87 m_tool.timeFormat(), '%', SWITCHES_24_12H, sizeof(SWITCHES_24_12H), &found,
88 IGNORE_AFTER_TRIGGER, sizeof(IGNORE_AFTER_TRIGGER));
86 89
87 if (pos != std::string::npos) { // if so, exchange it with 12/24h 90 if (pos != std::string::npos) { // if so, exchange it with 12/24h
88 std::string newformat = m_tool.timeFormat(); 91 std::string newformat = m_tool.timeFormat();
@@ -90,7 +93,8 @@ public:
90 93
91 if (found < 3) { // 24h? erase %P/%p (AM|PM / am|pm) 94 if (found < 3) { // 24h? erase %P/%p (AM|PM / am|pm)
92 pos = FbTk::StringUtil::findCharFromAlphabetAfterTrigger( 95 pos = FbTk::StringUtil::findCharFromAlphabetAfterTrigger(
93 newformat, '%', SWITCH_AM_PM, sizeof(SWITCH_AM_PM), 0); 96 newformat, '%', SWITCH_AM_PM, sizeof(SWITCH_AM_PM), 0,
97 IGNORE_AFTER_TRIGGER, sizeof(IGNORE_AFTER_TRIGGER));
94 if (pos != std::string::npos) { 98 if (pos != std::string::npos) {
95 newformat.erase(pos, 2); 99 newformat.erase(pos, 2);
96 } 100 }
@@ -107,7 +111,8 @@ private:
107 void setClockModeLabel() { 111 void setClockModeLabel() {
108 _FB_USES_NLS; 112 _FB_USES_NLS;
109 if (FbTk::StringUtil::findCharFromAlphabetAfterTrigger( 113 if (FbTk::StringUtil::findCharFromAlphabetAfterTrigger(
110 m_tool.timeFormat(), '%', SWITCHES_24_12H, 3, 0) != std::string::npos) { 114 m_tool.timeFormat(), '%', SWITCHES_24_12H, 3, 0,
115 IGNORE_AFTER_TRIGGER, sizeof(IGNORE_AFTER_TRIGGER)) != std::string::npos) {
111 setLabel( _FB_XTEXT(Toolbar, Clock24, "Clock: 24h", "set Clockmode to 24h") ); 116 setLabel( _FB_XTEXT(Toolbar, Clock24, "Clock: 24h", "set Clockmode to 24h") );
112 } else { 117 } else {
113 setLabel( _FB_XTEXT(Toolbar, Clock12, "Clock: 12h", "set Clockmode to 12h") ); 118 setLabel( _FB_XTEXT(Toolbar, Clock12, "Clock: 12h", "set Clockmode to 12h") );
diff --git a/src/FbTk/StringUtil.cc b/src/FbTk/StringUtil.cc
index 63da383..b5f373f 100644
--- a/src/FbTk/StringUtil.cc
+++ b/src/FbTk/StringUtil.cc
@@ -274,9 +274,16 @@ string findExtension(const string &filename) {
274 return filename.substr(start_pos + 1); 274 return filename.substr(start_pos + 1);
275} 275}
276 276
277string::size_type findCharFromAlphabetAfterTrigger(const std::string& in, char trigger, const char alphabet[], size_t len_alphabet, size_t* found) { 277 string::size_type findCharFromAlphabetAfterTrigger(const std::string& in, char trigger, const char alphabet[], size_t len_alphabet, size_t* found, const char ignore_after_trigger[], size_t len_ignore_after_trigger) {
278 for (const char* s = in.c_str(); *s != '\0'; ) { 278 for (const char* s = in.c_str(); *s != '\0'; ) {
279 if (*s++ == trigger && *s != '\0') { 279 if (*s++ == trigger && *s != '\0') {
280 auto end = ignore_after_trigger + len_ignore_after_trigger;
281 while (std::find(ignore_after_trigger, end, *s) != end)
282 s++;
283
284 if (*s == '\0')
285 return string::npos;
286
280 for (const char* a = alphabet; (a - alphabet) < static_cast<ssize_t>(len_alphabet); ++a) { 287 for (const char* a = alphabet; (a - alphabet) < static_cast<ssize_t>(len_alphabet); ++a) {
281 if (*s == *a) { 288 if (*s == *a) {
282 if (found) { 289 if (found) {
diff --git a/src/FbTk/StringUtil.hh b/src/FbTk/StringUtil.hh
index bfa3a5c..5e0d0d4 100644
--- a/src/FbTk/StringUtil.hh
+++ b/src/FbTk/StringUtil.hh
@@ -69,7 +69,7 @@ std::string findExtension(const std::string &filename);
69/// @return std::string::npos if nothing found 69/// @return std::string::npos if nothing found
70std::string::size_type findCharFromAlphabetAfterTrigger(const std::string& in, 70std::string::size_type findCharFromAlphabetAfterTrigger(const std::string& in,
71 char trigger, 71 char trigger,
72 const char alphabet[], size_t len_alphabet, size_t* found); 72 const char alphabet[], size_t len_alphabet, size_t* found, const char ignore_after_trigger[] = "", size_t len_ignore_after_trigger = 0);
73 73
74/// @return copy of original with find_string replaced with "replace" 74/// @return copy of original with find_string replaced with "replace"
75std::string replaceString(const std::string &original, 75std::string replaceString(const std::string &original,