From 724158c74ce29ca95bae4236c2073f0eb6574716 Mon Sep 17 00:00:00 2001 From: ulukyn Date: Fri, 29 Jun 2018 16:02:49 +0200 Subject: [PATCH] Added: trimSeparators function to prevent trim of utf8 special chars. Currently trimSeparators only trim spaces and tabs. --HG-- branch : patches-from-atys --- code/nel/include/nel/misc/common.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/code/nel/include/nel/misc/common.h b/code/nel/include/nel/misc/common.h index 6d261ff8d..416b0545c 100644 --- a/code/nel/include/nel/misc/common.h +++ b/code/nel/include/nel/misc/common.h @@ -276,6 +276,19 @@ template T trimRightWhiteSpaces (const T &str) return str.substr (0, end); } +// remove spaces and tabs at the begin and end of the string +template T trimSeparators (const T &str) +{ + typename T::size_type start = 0; + typename T::size_type size = str.size(); + while (start < size && str[start] == ' ' && str[start] == '\t') + start++; + typename T::size_type end = size; + while (end > start && str[end-1] == ' ' && str[end-1] == '\t') + end--; + return str.substr (start, end-start); +} + // if both first and last char are quotes (' or "), then remove them template T trimQuotes (const T &str) {