From 7b059d2399956a7d9753c92d8df00f9b7b508201 Mon Sep 17 00:00:00 2001
From: fluxgen <fluxgen>
Date: Fri, 22 Aug 2003 19:38:00 +0000
Subject: cleaning, added toUpper and findExtension

---
 src/FbTk/StringUtil.cc | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/src/FbTk/StringUtil.cc b/src/FbTk/StringUtil.cc
index 8532662..26dbb84 100644
--- a/src/FbTk/StringUtil.cc
+++ b/src/FbTk/StringUtil.cc
@@ -19,7 +19,7 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-//�$Id: StringUtil.cc,v 1.4 2003/08/10 12:50:04 rathnor Exp $
+//�$Id: StringUtil.cc,v 1.5 2003/08/22 19:38:00 fluxgen Exp $
 
 #include "StringUtil.hh"
 
@@ -29,6 +29,7 @@
 #include <cctype>
 #include <cassert>
 #include <memory>
+#include <algorithm>
 
 using namespace std;
 
@@ -88,6 +89,18 @@ string expandFilename(const std::string &filename) {
 }
 
 /**
+@return string from last "." to end of string
+*/
+string findExtension(const std::string &filename) {
+    //get start of extension
+    std::string::size_type start_pos = filename.find_last_of(".");
+    if (start_pos == std::string::npos && start_pos != filename.size())
+        return "";
+    // return from last . to end of string
+    return filename.substr(start_pos + 1);
+}
+
+/**
  Parses a string between "first" and "last" characters
  and ignoring ok_chars as whitespaces. The value is
  returned in "out".
@@ -146,16 +159,16 @@ int getStringBetween(std::string& out, const char *instr, const char first, cons
     return (j+1+total_add);
 }
 
-void toLower(char * const conv) {
-    for (size_t byte_pos = 0; byte_pos < strlen(conv); ++byte_pos)
-        conv[byte_pos] = tolower(conv[byte_pos]);
+std::string toLower(const std::string &conv) {
+    std::string ret = conv;
+    std::transform(ret.begin(), ret.end(), ret.begin(), tolower);
+    return ret;
 }
 
-std::string toLower(const std::string &conv) {
-    char ret_str[conv.size()+1]; 
-    ::strcpy(ret_str, conv.c_str());
-    toLower(ret_str);
-    return ret_str;
+std::string toUpper(const std::string &conv) {
+    std::string ret = conv;
+    std::transform(ret.begin(), ret.end(), ret.begin(), toupper);
+    return ret;
 }
 
 }; // end namespace StringUtil
-- 
cgit v0.11.2