From: <man...@us...> - 2013-05-30 16:15:12
|
Revision: 2230 http://sourceforge.net/p/modplug/code/2230 Author: manxorist Date: 2013-05-30 16:15:05 +0000 (Thu, 30 May 2013) Log Message: ----------- [Fix] mpt::String::RTrim, mpt::String::LTrim and mpt::String::Trim would not remove whitespace at all if the string contained only whitespace. Fix it. Modified Paths: -------------- trunk/OpenMPT/common/mptString.h trunk/OpenMPT/test/test.cpp Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2013-05-29 21:17:57 UTC (rev 2229) +++ trunk/OpenMPT/common/mptString.h 2013-05-30 16:15:05 UTC (rev 2230) @@ -60,6 +60,9 @@ if(pos != std::string::npos) { str.erase(str.begin(), str.begin() + pos); + } else if(pos == std::string::npos && str.length() > 0 && str.find_last_of(whitespace) == str.length() - 1) + { + return std::string(); } return str; } @@ -72,6 +75,9 @@ if(pos != std::string::npos) { str.erase(str.begin() + pos + 1, str.end()); + } else if(pos == std::string::npos && str.length() > 0 && str.find_first_of(whitespace) == 0) + { + return std::string(); } return str; } Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2013-05-29 21:17:57 UTC (rev 2229) +++ trunk/OpenMPT/test/test.cpp 2013-05-30 16:15:05 UTC (rev 2230) @@ -415,7 +415,11 @@ VERIFY_EQUAL( mpt::saturate_cast<uint16>(std::numeric_limits<int16>::max() + 1), (uint16)std::numeric_limits<int16>::max() + 1 ); VERIFY_EQUAL( mpt::saturate_cast<uint32>(std::numeric_limits<int32>::min() - int64(1)), std::numeric_limits<uint32>::min() ); VERIFY_EQUAL( mpt::saturate_cast<uint32>(std::numeric_limits<int32>::max() + int64(1)), (uint32)std::numeric_limits<int32>::max() + 1 ); - + + VERIFY_EQUAL( mpt::String::LTrim(" "), "" ); + VERIFY_EQUAL( mpt::String::RTrim(" "), "" ); + VERIFY_EQUAL( mpt::String::Trim(" "), "" ); + // These should fail to compile //Util::Round<std::string>(1.0); //Util::Round<int64>(1.0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |