trunk/branch integration: refactoring

This commit is contained in:
Marian Krivos
2011-08-23 07:13:42 +00:00
parent 8bc1691e16
commit 35f44e5a2d

View File

@@ -1,7 +1,7 @@
// //
// UTF8String.cpp // UTF8String.cpp
// //
// $Id: //poco/svn/Foundation/src/UTF8String.cpp#2 $ // $Id: //poco/1.4/Foundation/src/UTF8String.cpp#1 $
// //
// Library: Foundation // Library: Foundation
// Package: Text // Package: Text
@@ -45,13 +45,17 @@
namespace Poco { namespace Poco {
int UTF8::icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, std::string::const_iterator it2, std::string::const_iterator end2) namespace
{ {
static UTF8Encoding utf8; static UTF8Encoding utf8;
}
std::string::size_type sz = str.size();
if (pos > sz) pos = sz;
if (pos + n > sz) n = sz - pos; int UTF8::icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, std::string::const_iterator it2, std::string::const_iterator end2)
{
std::string::size_type sz = str.size();
if (pos > sz) pos = sz;
if (pos + n > sz) n = sz - pos;
TextIterator uit1(str.begin() + pos, str.begin() + pos + n, utf8); TextIterator uit1(str.begin() + pos, str.begin() + pos + n, utf8);
TextIterator uend1(str.begin() + pos + n); TextIterator uend1(str.begin() + pos + n);
TextIterator uit2(it2, end2, utf8); TextIterator uit2(it2, end2, utf8);
@@ -120,11 +124,9 @@ int UTF8::icompare(const std::string& str1, std::string::size_type pos1, std::st
int UTF8::icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, const std::string::value_type* ptr) int UTF8::icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, const std::string::value_type* ptr)
{ {
static UTF8Encoding utf8; poco_check_ptr (ptr);
std::string::size_type sz = str.size();
poco_check_ptr (ptr); if (pos > sz) pos = sz;
std::string::size_type sz = str.size();
if (pos > sz) pos = sz;
if (pos + n > sz) n = sz - pos; if (pos + n > sz) n = sz - pos;
TextIterator uit(str.begin() + pos, str.begin() + pos + n, utf8); TextIterator uit(str.begin() + pos, str.begin() + pos + n, utf8);
TextIterator uend(str.begin() + pos + n); TextIterator uend(str.begin() + pos + n);
@@ -160,20 +162,18 @@ int UTF8::icompare(const std::string& str, const std::string::value_type* ptr)
std::string UTF8::toUpper(const std::string& str) std::string UTF8::toUpper(const std::string& str)
{ {
static UTF8Encoding utf8; std::string result;
std::string result; TextConverter converter(utf8, utf8);
TextConverter converter(utf8, utf8); converter.convert(str, result, Unicode::toUpper);
converter.convert(str, result, Unicode::toUpper);
return result; return result;
} }
std::string& UTF8::toUpperInPlace(std::string& str) std::string& UTF8::toUpperInPlace(std::string& str)
{ {
static UTF8Encoding utf8; std::string result;
std::string result; TextConverter converter(utf8, utf8);
TextConverter converter(utf8, utf8); converter.convert(str, result, Unicode::toUpper);
converter.convert(str, result, Unicode::toUpper);
std::swap(str, result); std::swap(str, result);
return str; return str;
} }
@@ -181,20 +181,18 @@ std::string& UTF8::toUpperInPlace(std::string& str)
std::string UTF8::toLower(const std::string& str) std::string UTF8::toLower(const std::string& str)
{ {
static UTF8Encoding utf8; std::string result;
std::string result; TextConverter converter(utf8, utf8);
TextConverter converter(utf8, utf8); converter.convert(str, result, Unicode::toLower);
converter.convert(str, result, Unicode::toLower);
return result; return result;
} }
std::string& UTF8::toLowerInPlace(std::string& str) std::string& UTF8::toLowerInPlace(std::string& str)
{ {
static UTF8Encoding utf8; std::string result;
std::string result; TextConverter converter(utf8, utf8);
TextConverter converter(utf8, utf8); converter.convert(str, result, Unicode::toLower);
converter.convert(str, result, Unicode::toLower);
std::swap(str, result); std::swap(str, result);
return str; return str;
} }