diff --git a/include/utils/string.hpp b/include/utils/string.hpp index 99e07f73..060f0fa5 100644 --- a/include/utils/string.hpp +++ b/include/utils/string.hpp @@ -23,9 +23,9 @@ namespace string_util { string squeeze(const string& haystack, char needle); string strip(const string& haystack, char needle); string strip_trailing_newline(const string& haystack); - string ltrim(const string& haystack, char needle); - string rtrim(const string& haystack, char needle); - string trim(const string& haystack, char needle); + string ltrim(string&& value, const char& needle); + string rtrim(string&& value, const char& needle); + string trim(string&& value, const char& needle); string join(const vector& strs, const string& delim); vector& split_into(const string& s, char delim, vector& container); vector split(const string& s, char delim); diff --git a/src/components/config.cpp b/src/components/config.cpp index ef3e4aeb..6d66742c 100644 --- a/src/components/config.cpp +++ b/src/components/config.cpp @@ -95,6 +95,8 @@ void config::parse_file() { if (line[0] == '[' && line[line.length() - 1] == ']') { section = line.substr(1, line.length() - 2); continue; + } else if (section.empty()) { + continue; } size_t equal_pos; @@ -104,14 +106,19 @@ void config::parse_file() { continue; } - string key{string_util::trim(line.substr(0, equal_pos), ' ')}; - string value{string_util::trim(string_util::trim(line.substr(equal_pos + 1), ' '), '"')}; + string key{forward(string_util::trim(forward(line.substr(0, equal_pos)), ' '))}; auto it = m_sections[section].find(key); if (it != m_sections[section].end()) { throw key_error("Duplicate key name \"" + key + "\" defined on line " + to_string(lineno)); } + if (line.size() > equal_pos + 1) { + line.erase(0, equal_pos + 1); + } + + string value{string_util::trim(string_util::trim(move(line), ' '), '"')}; + m_sections[section].emplace_hint(it, move(key), move(value)); } diff --git a/src/components/parser.cpp b/src/components/parser.cpp index a7620176..438b4a94 100644 --- a/src/components/parser.cpp +++ b/src/components/parser.cpp @@ -46,7 +46,7 @@ void parser::codeblock(string&& data) { size_t pos; while (data.length()) { - data = string_util::ltrim(data, ' '); + data = string_util::ltrim(move(data), ' '); if (data.empty()) { break; diff --git a/src/drawtypes/animation.cpp b/src/drawtypes/animation.cpp index d4eb0b90..f25eacc9 100644 --- a/src/drawtypes/animation.cpp +++ b/src/drawtypes/animation.cpp @@ -45,7 +45,7 @@ namespace drawtypes { vector vec; vector frames; - name = string_util::ltrim(string_util::rtrim(name, '>'), '<'); + name = string_util::ltrim(string_util::rtrim(move(name), '>'), '<'); auto anim_defaults = load_optional_icon(conf, section, name); diff --git a/src/drawtypes/label.cpp b/src/drawtypes/label.cpp index 21a28f36..1ba559e1 100644 --- a/src/drawtypes/label.cpp +++ b/src/drawtypes/label.cpp @@ -124,7 +124,7 @@ namespace drawtypes { vector tokens; size_t start, end, pos; - name = string_util::ltrim(string_util::rtrim(name, '>'), '<'); + name = string_util::ltrim(string_util::rtrim(move(name), '>'), '<'); string text; diff --git a/src/drawtypes/progressbar.cpp b/src/drawtypes/progressbar.cpp index 0c87f07a..52eb2640 100644 --- a/src/drawtypes/progressbar.cpp +++ b/src/drawtypes/progressbar.cpp @@ -87,7 +87,7 @@ namespace drawtypes { */ progressbar_t load_progressbar(const bar_settings& bar, const config& conf, const string& section, string name) { // Remove the start and end tag from the name in case a format tag is passed - name = string_util::ltrim(string_util::rtrim(name, '>'), '<'); + name = string_util::ltrim(string_util::rtrim(move(name), '>'), '<'); string format = "%fill%%indicator%%empty%"; unsigned int width; diff --git a/src/drawtypes/ramp.cpp b/src/drawtypes/ramp.cpp index 5781b9fb..d533e651 100644 --- a/src/drawtypes/ramp.cpp +++ b/src/drawtypes/ramp.cpp @@ -27,7 +27,7 @@ namespace drawtypes { * from the configuration */ ramp_t load_ramp(const config& conf, const string& section, string name, bool required) { - name = string_util::ltrim(string_util::rtrim(name, '>'), '<'); + name = string_util::ltrim(string_util::rtrim(move(name), '>'), '<'); auto ramp_defaults = load_optional_icon(conf, section, name); diff --git a/src/modules/i3.cpp b/src/modules/i3.cpp index ff62a530..d66f7068 100644 --- a/src/modules/i3.cpp +++ b/src/modules/i3.cpp @@ -142,7 +142,7 @@ namespace modules { } // Trim leading and trailing whitespace - ws_name = string_util::trim(ws_name, ' '); + ws_name = string_util::trim(move(ws_name), ' '); auto icon = m_icons->get(ws->name, DEFAULT_WS_ICON); auto label = m_statelabels.find(ws_state)->second->clone(); diff --git a/src/utils/string.cpp b/src/utils/string.cpp index 09eb8692..e94154b5 100644 --- a/src/utils/string.cpp +++ b/src/utils/string.cpp @@ -122,7 +122,7 @@ namespace string_util { /** * Remove needle from the start of the string */ - string ltrim(const string& haystack, char needle) { + string ltrim(string&& haystack, const char& needle) { string str(haystack); while (str[0] == needle) { str.erase(0, 1); @@ -133,7 +133,7 @@ namespace string_util { /** * Remove needle from the end of the string */ - string rtrim(const string& haystack, char needle) { + string rtrim(string&& haystack, const char& needle) { string str(haystack); while (str[str.length() - 1] == needle) { str.erase(str.length() - 1, 1); @@ -144,8 +144,8 @@ namespace string_util { /** * Remove needle from the start and end of the string */ - string trim(const string& haystack, char needle) { - return rtrim(ltrim(haystack, needle), needle); + string trim(string&& value, const char& needle) { + return rtrim(ltrim(move(value), needle), needle); } /**