summaryrefslogtreecommitdiff
path: root/src/helpers/MiscFunctions.cpp
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-10-03 14:36:56 +0100
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-10-03 14:36:56 +0100
commit174b59343817f18df73afa74f9b73c29cadbdeab (patch)
tree447193df78cc693c729b28dc8b98c79987a41e8d /src/helpers/MiscFunctions.cpp
parent0a08830375bb3a206e1b966a11bf069edea8b780 (diff)
optimize removing trailing spaces
Diffstat (limited to 'src/helpers/MiscFunctions.cpp')
-rw-r--r--src/helpers/MiscFunctions.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp
index e933d496..de2f8e74 100644
--- a/src/helpers/MiscFunctions.cpp
+++ b/src/helpers/MiscFunctions.cpp
@@ -120,14 +120,18 @@ void scaleBox(wlr_box* box, float scale) {
}
std::string removeBeginEndSpacesTabs(std::string str) {
- while (str[0] == ' ' || str[0] == '\t') {
- str = str.substr(1);
+ int countBefore = 0;
+ while (str[countBefore] == ' ' || str[countBefore] == '\t') {
+ countBefore++;
}
- while (str.length() != 0 && (str[str.length() - 1] == ' ' || str[str.length() - 1] == '\t')) {
- str = str.substr(0, str.length() - 1);
+ int countAfter = 0;
+ while (str.length() != 0 && (str[str.length() - countAfter - 1] == ' ' || str[str.length() - 1 - countAfter] == '\t')) {
+ countAfter++;
}
+ str = str.substr(countBefore, str.length() - countBefore - countAfter);
+
return str;
}