mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-14 05:55:13 +01:00
string_util: Remove unnecessary std::string instance in TabsToSpaces()
We can just use the variant of std::string's replace() function that can replace an occurrence with N copies of the same character, eliminating the need to allocate a std::string containing a buffer of spaces.
This commit is contained in:
parent
71729fd47a
commit
841bb4e5bd
@ -236,15 +236,14 @@ void SplitString(const std::string& str, const char delim, std::vector<std::stri
|
|||||||
output.pop_back();
|
output.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TabsToSpaces(int tab_size, const std::string& in) {
|
std::string TabsToSpaces(int tab_size, std::string in) {
|
||||||
const std::string spaces(tab_size, ' ');
|
|
||||||
std::string out(in);
|
|
||||||
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
while (out.npos != (i = out.find('\t')))
|
|
||||||
out.replace(i, 1, spaces);
|
|
||||||
|
|
||||||
return out;
|
while ((i = in.find('\t')) != std::string::npos) {
|
||||||
|
in.replace(i, 1, tab_size, ' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest) {
|
std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest) {
|
||||||
|
@ -69,7 +69,7 @@ static bool TryParse(const std::string& str, N* const output) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string TabsToSpaces(int tab_size, const std::string& in);
|
std::string TabsToSpaces(int tab_size, std::string in);
|
||||||
|
|
||||||
void SplitString(const std::string& str, char delim, std::vector<std::string>& output);
|
void SplitString(const std::string& str, char delim, std::vector<std::string>& output);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user