refactor(string_util): Use rvalue references for *trim()
This commit is contained in:
parent
eca870774f
commit
5077325044
@ -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<string>& strs, const string& delim);
|
||||
vector<string>& split_into(const string& s, char delim, vector<string>& container);
|
||||
vector<string> split(const string& s, char delim);
|
||||
|
@ -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>(string_util::trim(forward<string>(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));
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -45,7 +45,7 @@ namespace drawtypes {
|
||||
vector<icon_t> vec;
|
||||
vector<string> 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);
|
||||
|
||||
|
@ -124,7 +124,7 @@ namespace drawtypes {
|
||||
vector<token> 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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user