From 815b79a80a68c698b985fa01243881c2758daa66 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Fri, 4 Jan 2013 09:15:45 -0800 Subject: [PATCH] add specialized quote trimming functions (will be used in sql_utils.hpp) --- include/mapnik/util/trim.hpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/mapnik/util/trim.hpp b/include/mapnik/util/trim.hpp index 4803f2f31..48ec7e018 100644 --- a/include/mapnik/util/trim.hpp +++ b/include/mapnik/util/trim.hpp @@ -68,6 +68,29 @@ static inline std::string trim_copy(std::string s) return ltrim(rtrim(s)); } +static inline bool not_double_quote(int ch) +{ + if (ch == '"') return false; + return true; +} + +static inline void unquote_double(std::string & s) +{ + s.erase(s.begin(), std::find_if(s.begin(), s.end(), not_double_quote)); + s.erase(std::find_if(s.rbegin(), s.rend(), not_double_quote).base(), s.end()); +} + +static inline bool not_quoted(int ch) +{ + if (ch == '"' || ch == '\'') return false; + return true; +} + +static inline void unquote(std::string & s) +{ + s.erase(s.begin(), std::find_if(s.begin(), s.end(), not_quoted)); + s.erase(std::find_if(s.rbegin(), s.rend(), not_quoted).base(), s.end()); +} }} // end of namespace mapnik