Skip to content

Commit

Permalink
common/str_map: better trim() impl using boost
Browse files Browse the repository at this point in the history
Thanks Kefu!

Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit 6154874)

Conflicts:
	src/common/str_map.cc : Resolved in trim
  • Loading branch information
liewegas authored and Prashant D committed Mar 11, 2019
1 parent 9ae76f1 commit 5ec1c19
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/common/str_map.cc
Expand Up @@ -17,6 +17,8 @@
#include "include/str_map.h"
#include "include/str_list.h"

#include <boost/algorithm/string.hpp>

#include "json_spirit/json_spirit.h"

using namespace std;
Expand Down Expand Up @@ -56,22 +58,13 @@ int get_json_str_map(
}
return 0;
}

string trim(const string& str) {
if (str.empty()) {
return str;
}
size_t start = 0;
size_t end = str.size() - 1;
while (isspace(str[start]) != 0 && start <= end) {
++start;
}
while (isspace(str[end]) != 0 && start <= end) {
--end;
}
if (start <= end) {
return str.substr(start, end - start + 1);
}
return string();
return boost::algorithm::trim_copy_if(
str,
[](unsigned char c) {
return std::isspace(c);
});
}

int get_str_map(
Expand Down

0 comments on commit 5ec1c19

Please sign in to comment.