Skip to content

Commit

Permalink
fixed GH #1425: Workaround bug in SolarisStudio 12.4 on RVO-ed objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
obiltschnig committed Nov 8, 2017
1 parent 079c9a6 commit 47043e0
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions Foundation/include/Poco/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ S trimLeft(const S& str)
{
typename S::const_iterator it = str.begin();
typename S::const_iterator end = str.end();

while (it != end && Ascii::isSpace(*it)) ++it;
return S(it, end);
}
Expand All @@ -46,7 +46,7 @@ S& trimLeftInPlace(S& str)
{
typename S::iterator it = str.begin();
typename S::iterator end = str.end();

while (it != end && Ascii::isSpace(*it)) ++it;
str.erase(str.begin(), it);
return str;
Expand All @@ -59,7 +59,7 @@ S trimRight(const S& str)
/// whitespace removed.
{
int pos = int(str.size()) - 1;

while (pos >= 0 && Ascii::isSpace(str[pos])) --pos;
return S(str, 0, pos + 1);
}
Expand All @@ -70,7 +70,7 @@ S& trimRightInPlace(S& str)
/// Removes all trailing whitespace in str.
{
int pos = int(str.size()) - 1;

while (pos >= 0 && Ascii::isSpace(str[pos])) --pos;
str.resize(pos + 1);

Expand All @@ -85,7 +85,7 @@ S trim(const S& str)
{
int first = 0;
int last = int(str.size()) - 1;

while (first <= last && Ascii::isSpace(str[first])) ++first;
while (last >= first && Ascii::isSpace(str[last])) --last;

Expand All @@ -99,7 +99,7 @@ S& trimInPlace(S& str)
{
int first = 0;
int last = int(str.size()) - 1;

while (first <= last && Ascii::isSpace(str[first])) ++first;
while (last >= first && Ascii::isSpace(str[last])) --last;

Expand Down Expand Up @@ -168,16 +168,16 @@ S& toLowerInPlace(S& str)
template <class S, class It>
int icompare(
const S& str,
typename S::size_type pos,
typename S::size_type pos,
typename S::size_type n,
It it2,
It it2,
It end2)
/// Case-insensitive string comparison
{
typename S::size_type sz = str.size();
if (pos > sz) pos = sz;
if (pos + n > sz) n = sz - pos;
It it1 = str.begin() + pos;
It it1 = str.begin() + pos;
It end1 = str.begin() + pos + n;
while (it1 != end1 && it2 != end2)
{
Expand Down Expand Up @@ -215,7 +215,7 @@ int icompare(const S& str1, const S& str2)
return 1;
++it1; ++it2;
}

if (it1 == end1)
return it2 == end2 ? 0 : -1;
else
Expand Down Expand Up @@ -248,9 +248,9 @@ int icompare(const S& str1, typename S::size_type pos, typename S::size_type n,

template <class S>
int icompare(
const S& str1,
typename S::size_type pos1,
typename S::size_type n1,
const S& str1,
typename S::size_type pos1,
typename S::size_type n1,
const S& str2,
typename S::size_type pos2,
typename S::size_type n2)
Expand All @@ -264,9 +264,9 @@ int icompare(

template <class S>
int icompare(
const S& str1,
typename S::size_type pos1,
typename S::size_type n,
const S& str1,
typename S::size_type pos1,
typename S::size_type n,
const S& str2,
typename S::size_type pos2)
{
Expand All @@ -288,7 +288,7 @@ int icompare(
typename S::size_type sz = str.size();
if (pos > sz) pos = sz;
if (pos + n > sz) n = sz - pos;
typename S::const_iterator it = str.begin() + pos;
typename S::const_iterator it = str.begin() + pos;
typename S::const_iterator end = str.begin() + pos + n;
while (it != end && *ptr)
{
Expand All @@ -300,7 +300,7 @@ int icompare(
return 1;
++it; ++ptr;
}

if (it == end)
return *ptr == 0 ? 0 : -1;
else
Expand Down Expand Up @@ -351,7 +351,7 @@ S translate(const S& str, const S& from, const S& to)
/// from replaced by the corresponding (by position)
/// characters in to. If there is no corresponding
/// character in to, the character is removed from
/// the copy.
/// the copy.
{
S result;
result.reserve(str.size());
Expand Down Expand Up @@ -386,7 +386,7 @@ S translate(const S& str, const typename S::value_type* from, const typename S::

template <class S>
S& translateInPlace(S& str, const S& from, const S& to)
/// Replaces in str all occurences of characters in from
/// Replaces in str all occurrences of characters in from
/// with the corresponding (by position) characters in to.
/// If there is no corresponding character, the character
/// is removed.
Expand All @@ -402,7 +402,13 @@ S translateInPlace(S& str, const typename S::value_type* from, const typename S:
poco_check_ptr (from);
poco_check_ptr (to);
str = translate(str, S(from), S(to));
#if defined(__SUNPRO_CC)
// Fix around the RVO bug in SunStudio 12.4
S ret(str);
return ret;
#else
return str;
#endif
}


Expand All @@ -413,7 +419,7 @@ template <class S>
S& replaceInPlace(S& str, const S& from, const S& to, typename S::size_type start = 0)
{
poco_assert (from.size() > 0);

S result;
typename S::size_type pos = 0;
result.append(str, 0, start);
Expand Down Expand Up @@ -489,7 +495,7 @@ S& removeInPlace(S& str, const typename S::value_type ch, typename S::size_type

template <class S>
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)
/// Replace all occurrences of from (which must not be the empty string)
/// in str with to, starting at position start.
{
S result(str);
Expand Down Expand Up @@ -538,7 +544,7 @@ Foundation_API std::string& replaceInPlace(std::string& str, const std::string::
Foundation_API std::string& removeInPlace(std::string& str, const std::string::value_type ch, std::string::size_type start = 0);


#endif
#endif


template <class S>
Expand Down Expand Up @@ -674,7 +680,7 @@ std::size_t isubstr(const T& str, const T& sought)
/// without regards to case.
{
typename T::const_iterator it = std::search(str.begin(), str.end(),
sought.begin(), sought.end(),
sought.begin(), sought.end(),
i_char_traits<typename T::value_type>::eq);

if (it != str.end()) return it - str.begin();
Expand Down

0 comments on commit 47043e0

Please sign in to comment.