From 78fe398a2f3a7fe46eea7049505fe02e7761a7b4 Mon Sep 17 00:00:00 2001 From: Steve Beattie Date: Fri, 24 Jan 2014 10:30:08 -0800 Subject: [PATCH] parser: replace reverse iterator As suggested by Seth Arnold, we can use string::find_last_not_of() instead of using C++'s hideous reverse iterators. Signed-off-by: Steve Beattie Acked-by: John Johansen --- parser/parser_variable.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/parser/parser_variable.c b/parser/parser_variable.c index 8d50a264d..83e35d51a 100644 --- a/parser/parser_variable.c +++ b/parser/parser_variable.c @@ -137,11 +137,11 @@ void free_var_string(struct var_string *var) static void trim_trailing_slash(std::string& str) { - for (std::string::reverse_iterator rit = str.rbegin(); - rit != str.rend() && *rit == '/'; ++rit) { - /* yuck, reverse_iterators are ugly */ - str.erase(--rit.base()); - } + std::size_t found = str.find_last_not_of('/'); + if (found != std::string::npos) + str.erase(found + 1); + else + str.clear(); // str is all '/' } static void write_replacement(const char separator, const char* value,