Revision: 44686
http://brlcad.svn.sourceforge.net/brlcad/?rev=44686&view=rev
Author: davidloman
Date: 2011-05-25 18:15:27 +0000 (Wed, 25 May 2011)
Log Message:
-----------
getLastStepOfPath was failing in certain cases. Created unit tests and fixed
bugs.
Modified Paths:
--------------
geomcore/trunk/src/utility/StringUtils.cxx
geomcore/trunk/tests/unit/utility/StringUtilsUTest.cxx
Modified: geomcore/trunk/src/utility/StringUtils.cxx
===================================================================
--- geomcore/trunk/src/utility/StringUtils.cxx 2011-05-25 17:46:23 UTC (rev
44685)
+++ geomcore/trunk/src/utility/StringUtils.cxx 2011-05-25 18:15:27 UTC (rev
44686)
@@ -129,7 +129,7 @@
/* build left hand side string */
for (; it != strStack.end(); ++it)
{
- pathSoFar += (std::string)*it;;
+ pathSoFar += (std::string)*it;
ford = StringUtils::isFileOrDir(pathSoFar.c_str());
/* 2 == FILE, 1 == DIR, 0 == NOTEXIST */
@@ -137,6 +137,7 @@
++step;
break;
} else if (ford == 1) {
+ pathSoFar += PATH_DELIM;
++step;
continue;
} else if (ford == 0) return step * -1; /* Failed */
@@ -235,13 +236,20 @@
StringUtils::getLastStepOfPath(const std::string path)
{
std::string out = "";
- size_t found = path.rfind(PATH_DELIM);
- if (found == std::string::npos)
+ std::string copy = path;
+ StringUtils::cleanString(©);
+
+ while (copy[copy.length()-1] == '/')
+ copy.erase(copy.length()-1);
+
+ size_t found = copy.rfind(PATH_DELIM);
+
+ if (found != std::string::npos)
/* Path, so get last step */
- out = path.substr(found + 1);
+ out = copy.substr(found + 1);
else
/* no path, thus 'path' *is* the last step */
- out = path;
+ out = copy;
return out;
}
Modified: geomcore/trunk/tests/unit/utility/StringUtilsUTest.cxx
===================================================================
--- geomcore/trunk/tests/unit/utility/StringUtilsUTest.cxx 2011-05-25
17:46:23 UTC (rev 44685)
+++ geomcore/trunk/tests/unit/utility/StringUtilsUTest.cxx 2011-05-25
18:15:27 UTC (rev 44686)
@@ -30,6 +30,7 @@
class StringUtilsUTest : public CPPUNIT_NS::TestFixture {
CPPUNIT_TEST_SUITE( StringUtilsUTest );
+ CPPUNIT_TEST( testGetLastStepOfPath );
CPPUNIT_TEST( testSplitPathAtStep01 );
CPPUNIT_TEST( testSplitPathAtStep01a );
CPPUNIT_TEST( testSplitPathAtStep01b );
@@ -50,6 +51,23 @@
public:
void
+ testGetLastStepOfPath()
+ {
+ std::string name;
+ //std::cout << "\n\nname " << name << "\n\n";
+
+ name = StringUtils::getLastStepOfPath(testPath01);
+ CPPUNIT_ASSERT(name == "duder");
+ name = StringUtils::getLastStepOfPath(testPath02);
+ CPPUNIT_ASSERT(name == "duder");
+ name = StringUtils::getLastStepOfPath(testPath03);
+ CPPUNIT_ASSERT(name == "duder");
+ name = StringUtils::getLastStepOfPath(testPath04);
+ CPPUNIT_ASSERT(name == "duder");
+ }
+
+
+ void
testSplitPathAtStep01()
{
std::string rPath = "";
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery,
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now.
http://p.sf.net/sfu/quest-d2dcopy1
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits