sources for 1.3

This commit is contained in:
Guenter Obiltschnig
2006-11-17 16:21:51 +00:00
parent 7ff71d107f
commit 768642ae98
744 changed files with 6781 additions and 1036 deletions

View File

@@ -1,7 +1,7 @@
//
// String.h
//
// $Id: //poco/1.2/Foundation/src/String.cpp#1 $
// $Id: //poco/1.3/Foundation/src/String.cpp#1 $
//
// Library: Foundation
// Package: Core
@@ -152,6 +152,71 @@ int icompare(const std::string& str, const std::string::value_type* ptr)
}
std::string replace(const std::string& str, const std::string& from, const std::string& to, std::string::size_type start)
{
std::string result(str);
replaceInPlace(result, from, to, start);
return result;
}
std::string replace(const std::string& str, const std::string::value_type* from, const std::string::value_type* to, std::string::size_type start)
{
std::string result(str);
replaceInPlace(result, from, to, start);
return result;
}
std::string& replaceInPlace(std::string& str, const std::string& from, const std::string& to, std::string::size_type start)
{
poco_assert (from.size() > 0);
std::string result;
std::string::size_type pos = 0;
result.append(str, 0, start);
do
{
pos = str.find(from, start);
if (pos != std::string::npos)
{
result.append(str, start, pos - start);
result.append(to);
start = pos + from.length();
}
else result.append(str, start, str.size() - start);
}
while (pos != std::string::npos);
str.swap(result);
return str;
}
std::string& replaceInPlace(std::string& str, const std::string::value_type* from, const std::string::value_type* to, std::string::size_type start)
{
poco_assert (*from);
std::string result;
std::string::size_type pos = 0;
std::string::size_type fromLen = strlen(from);
result.append(str, 0, start);
do
{
pos = str.find(from, start);
if (pos != std::string::npos)
{
result.append(str, start, pos - start);
result.append(to);
start = pos + fromLen;
}
else result.append(str, start, str.size() - start);
}
while (pos != std::string::npos);
str.swap(result);
return str;
}
#endif