Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/util/util_string.cpp
| Show First 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | void string_split(vector<string> &tokens, | ||||
| } | } | ||||
| /* Append token from the tail of the string if exists. */ | /* Append token from the tail of the string if exists. */ | ||||
| if (token_length) { | if (token_length) { | ||||
| string token = str.substr(token_start, token_length); | string token = str.substr(token_start, token_length); | ||||
| tokens.push_back(token); | tokens.push_back(token); | ||||
| } | } | ||||
| } | } | ||||
| bool string_startswith(const string &s, const char *start) | bool string_startswith(const string_view s, const string_view start) | ||||
| { | { | ||||
| size_t len = strlen(start); | const size_t len = start.size(); | ||||
| if (len > s.size()) | if (len > s.size()) { | ||||
| return 0; | return false; | ||||
| else | } | ||||
| return strncmp(s.c_str(), start, len) == 0; | |||||
| return strncmp(s.c_str(), start.data(), len) == 0; | |||||
| } | } | ||||
| bool string_endswith(const string &s, const string &end) | bool string_endswith(const string_view s, const string_view end) | ||||
| { | { | ||||
| size_t len = end.length(); | const size_t len = end.size(); | ||||
| if (len > s.size()) | if (len > s.size()) { | ||||
| return 0; | return false; | ||||
| else | } | ||||
| return s.compare(s.length() - len, len, end) == 0; | |||||
| return strncmp(s.c_str() + s.size() - len, end.data(), len) == 0; | |||||
| } | } | ||||
| string string_strip(const string &s) | string string_strip(const string &s) | ||||
| { | { | ||||
| string result = s; | string result = s; | ||||
| result.erase(0, result.find_first_not_of(' ')); | result.erase(0, result.find_first_not_of(' ')); | ||||
| result.erase(result.find_last_not_of(' ') + 1); | result.erase(result.find_last_not_of(' ') + 1); | ||||
| return result; | return result; | ||||
| ▲ Show 20 Lines • Show All 128 Lines • Show Last 20 Lines | |||||