Revision: 44765
http://brlcad.svn.sourceforge.net/brlcad/?rev=44765&view=rev
Author: brlcad
Date: 2011-06-06 21:44:18 +0000 (Mon, 06 Jun 2011)
Log Message:
-----------
de-invent the wheel, refactor to common functionality in libbu. we could call
basename() directly, but bu_basename() is better reuse and has more safeguards.
keep the wrapper so callers can keep their pretty std::strings.
Modified Paths:
--------------
geomcore/trunk/src/utility/StringUtils.cxx
Modified: geomcore/trunk/src/utility/StringUtils.cxx
===================================================================
--- geomcore/trunk/src/utility/StringUtils.cxx 2011-06-06 21:41:20 UTC (rev
44764)
+++ geomcore/trunk/src/utility/StringUtils.cxx 2011-06-06 21:44:18 UTC (rev
44765)
@@ -22,11 +22,15 @@
*/
#include "StringUtils.h"
+
#include <sys/stat.h>
#include <sys/types.h>
#include <stdio.h>
#include <iostream>
+#include "bu.h"
+
+
const int
StringUtils::isFileOrDir(const std::string path)
{
@@ -235,22 +239,10 @@
std::string
StringUtils::basename(const std::string path)
{
- std::string out = "";
- 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 = copy.substr(found + 1);
- else
- /* no path, thus 'path' *is* the last step */
- out = copy;
- return out;
+ char *path_str = bu_basename(path.c_str());
+ std::string ret = std::string(path_str);
+ bu_free(path_str, "bu_basename");
+ return ret;
}
// Local Variables:
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits