From b381b149aa1fc5c50f8be8e853e682ce3824c910 Mon Sep 17 00:00:00 2001 From: Dave Goodwin Date: Tue, 27 Sep 2005 12:08:17 +0000 Subject: [PATCH] changed stripws to allow spaces in the middle of strings --- Cantera/src/stringUtils.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/Cantera/src/stringUtils.cpp b/Cantera/src/stringUtils.cpp index 6077d6f0f..51d345e2e 100755 --- a/Cantera/src/stringUtils.cpp +++ b/Cantera/src/stringUtils.cpp @@ -46,22 +46,29 @@ namespace Cantera { return lc; } + static int firstChar(string s) { + int i; + int n = static_cast(s.size()); + for (i = 0; i < n; i++) + if (s[i] != ' ' && isprint(s[i])) break; + return i; + } + + static int lastChar(string s) { + int i; + int n = static_cast(s.size()); + for (i = n-1; i >= 0; i--) + if (s[i] != ' ' && isprint(s[i])) break; + return i; + } + /** - * Strip white space. + * Strip leading and trailing white space. */ string stripws(string s) { - int i; - bool sempty = true; - int n = static_cast(s.size()); - string ss = ""; - for (i = 0; i < n; i++) { - if (s[i] != ' ' && isprint(s[i])) { - ss += s[i]; - sempty = false; - } - else if (!sempty) break; - } - return ss; + int ifirst = firstChar(s); + int ilast = lastChar(s); + return s.substr(ifirst, ilast - ifirst + 1); } /**