From ba5fe67963e6f4ef8812fbd5544f261b3914859b Mon Sep 17 00:00:00 2001 From: Marian Krivos Date: Mon, 22 Aug 2011 18:27:20 +0000 Subject: [PATCH] trunk/branch integration: using Poco::Ascii --- Foundation/include/Poco/String.h | 80 ++++++++++++++++---------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/Foundation/include/Poco/String.h b/Foundation/include/Poco/String.h index bf789a1ce..98f75a91b 100644 --- a/Foundation/include/Poco/String.h +++ b/Foundation/include/Poco/String.h @@ -1,7 +1,7 @@ // // String.h // -// $Id: //poco/svn/Foundation/include/Poco/String.h#2 $ +// $Id: //poco/1.4/Foundation/include/Poco/String.h#1 $ // // Library: Foundation // Package: Core @@ -41,8 +41,8 @@ #include "Poco/Foundation.h" +#include "Poco/Ascii.h" #include -#include namespace Poco { @@ -56,7 +56,7 @@ S trimLeft(const S& str) typename S::const_iterator it = str.begin(); typename S::const_iterator end = str.end(); - while (it != end && std::isspace(*it)) ++it; + while (it != end && Ascii::isSpace(*it)) ++it; return S(it, end); } @@ -68,7 +68,7 @@ S& trimLeftInPlace(S& str) typename S::iterator it = str.begin(); typename S::iterator end = str.end(); - while (it != end && std::isspace(*it)) ++it; + while (it != end && Ascii::isSpace(*it)) ++it; str.erase(str.begin(), it); return str; } @@ -81,7 +81,7 @@ S trimRight(const S& str) { int pos = int(str.size()) - 1; - while (pos >= 0 && std::isspace(str[pos])) --pos; + while (pos >= 0 && Ascii::isSpace(str[pos])) --pos; return S(str, 0, pos + 1); } @@ -92,7 +92,7 @@ S& trimRightInPlace(S& str) { int pos = int(str.size()) - 1; - while (pos >= 0 && std::isspace(str[pos])) --pos; + while (pos >= 0 && Ascii::isSpace(str[pos])) --pos; str.resize(pos + 1); return str; @@ -107,8 +107,8 @@ S trim(const S& str) int first = 0; int last = int(str.size()) - 1; - while (first <= last && std::isspace(str[first])) ++first; - while (last >= first && std::isspace(str[last])) --last; + while (first <= last && Ascii::isSpace(str[first])) ++first; + while (last >= first && Ascii::isSpace(str[last])) --last; return S(str, first, last - first + 1); } @@ -121,8 +121,8 @@ S& trimInPlace(S& str) int first = 0; int last = int(str.size()) - 1; - while (first <= last && std::isspace(str[first])) ++first; - while (last >= first && std::isspace(str[last])) --last; + while (first <= last && Ascii::isSpace(str[first])) ++first; + while (last >= first && Ascii::isSpace(str[last])) --last; str.resize(last + 1); str.erase(0, first); @@ -140,7 +140,7 @@ S toUpper(const S& str) S result; result.reserve(str.size()); - while (it != end) result += std::toupper(*it++); + while (it != end) result += Ascii::toUpper(*it++); return result; } @@ -152,7 +152,7 @@ S& toUpperInPlace(S& str) typename S::iterator it = str.begin(); typename S::iterator end = str.end(); - while (it != end) { *it = std::toupper(*it); ++it; } + while (it != end) { *it = Ascii::toUpper(*it); ++it; } return str; } @@ -166,7 +166,7 @@ S toLower(const S& str) S result; result.reserve(str.size()); - while (it != end) result += std::tolower(*it++); + while (it != end) result += Ascii::toLower(*it++); return result; } @@ -178,7 +178,7 @@ S& toLowerInPlace(S& str) typename S::iterator it = str.begin(); typename S::iterator end = str.end(); - while (it != end) { *it = std::tolower(*it); ++it; } + while (it != end) { *it = Ascii::toLower(*it); ++it; } return str; } @@ -202,8 +202,8 @@ int icompare( It end1 = str.begin() + pos + n; while (it1 != end1 && it2 != end2) { - typename S::value_type c1(std::tolower(*it1)); - typename S::value_type c2(std::tolower(*it2)); + typename S::value_type c1(Ascii::toLower(*it1)); + typename S::value_type c2(Ascii::toLower(*it2)); if (c1 < c2) return -1; else if (c1 > c2) @@ -228,8 +228,8 @@ int icompare(const S& str1, const S& str2) typename S::const_iterator end2(str2.end()); while (it1 != end1 && it2 != end2) { - typename S::value_type c1(std::tolower(*it1)); - typename S::value_type c2(std::tolower(*it2)); + typename S::value_type c1(Ascii::toLower(*it1)); + typename S::value_type c2(Ascii::toLower(*it2)); if (c1 < c2) return -1; else if (c1 > c2) @@ -313,8 +313,8 @@ int icompare( typename S::const_iterator end = str.begin() + pos + n; while (it != end && *ptr) { - typename S::value_type c1(std::tolower(*it)); - typename S::value_type c2(std::tolower(*ptr)); + typename S::value_type c1(Ascii::toLower(*it)); + typename S::value_type c2(Ascii::toLower(*ptr)); if (c1 < c2) return -1; else if (c1 > c2) @@ -430,26 +430,6 @@ S translateInPlace(S& str, const typename S::value_type* from, const typename S: #if !defined(POCO_NO_TEMPLATE_ICOMPARE) -template -S replace(const S& str, const S& from, const S& to, typename S::size_type start = 0) - /// Replace all occurences of from (which must not be the empty string) - /// in str with to, starting at position start. -{ - S result(str); - replaceInPlace(result, from, to, start); - return result; -} - - -template -S replace(const S& str, const typename S::value_type* from, const typename S::value_type* to, typename S::size_type start = 0) -{ - S result(str); - replaceInPlace(result, from, to, start); - return result; -} - - template S& replaceInPlace(S& str, const S& from, const S& to, typename S::size_type start = 0) { @@ -501,6 +481,26 @@ S& replaceInPlace(S& str, const typename S::value_type* from, const typename S:: } +template +S replace(const S& str, const S& from, const S& to, typename S::size_type start = 0) + /// Replace all occurences of from (which must not be the empty string) + /// in str with to, starting at position start. +{ + S result(str); + replaceInPlace(result, from, to, start); + return result; +} + + +template +S replace(const S& str, const typename S::value_type* from, const typename S::value_type* to, typename S::size_type start = 0) +{ + S result(str); + replaceInPlace(result, from, to, start); + return result; +} + + #else