[gnote] Use Glib::ustring and no boost in string_last_index_of



commit 24fe7507227732c28c7c6fd4cfe6dc07ac1935dd
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sun Jan 22 20:16:18 2017 +0200

    Use Glib::ustring and no boost in string_last_index_of

 src/sharp/string.cpp           |   11 +++--------
 src/sharp/string.hpp           |    2 +-
 src/test/unit/stringutests.cpp |    9 +++++++++
 3 files changed, 13 insertions(+), 9 deletions(-)
---
diff --git a/src/sharp/string.cpp b/src/sharp/string.cpp
index d46d5e8..b7c3ea9 100644
--- a/src/sharp/string.cpp
+++ b/src/sharp/string.cpp
@@ -170,19 +170,14 @@ namespace sharp {
     return source.substr(start, end - start);
   }
 
-  int string_last_index_of(const std::string & source, const std::string & search)
+  int string_last_index_of(const Glib::ustring & source, const Glib::ustring & search)
   {
     if(search.empty()) {
         // Return last index, unless the source is the empty string, return 0
         return source.empty() ? 0 : source.size() - 1;
     }
-    boost::iterator_range<std::string::const_iterator> iter
-      = boost::find_last(source, search);
-    if(iter.begin() == source.end()) {
-      // NOT FOUND
-      return -1;
-    }
-    return iter.begin() - source.begin();
+
+    return source.rfind(search);
   }
 
 
diff --git a/src/sharp/string.hpp b/src/sharp/string.hpp
index 3fd0915..c7136ef 100644
--- a/src/sharp/string.hpp
+++ b/src/sharp/string.hpp
@@ -68,7 +68,7 @@ namespace sharp {
 
   int string_index_of(const std::string & source, const std::string & with);
   int string_index_of(const std::string & source, const std::string & with, int);
-  int string_last_index_of(const std::string & source, const std::string & with);
+  int string_last_index_of(const Glib::ustring & source, const Glib::ustring & search);
 }
 
 
diff --git a/src/test/unit/stringutests.cpp b/src/test/unit/stringutests.cpp
index 38ecd66..4dec974 100644
--- a/src/test/unit/stringutests.cpp
+++ b/src/test/unit/stringutests.cpp
@@ -112,5 +112,14 @@ SUITE(String)
     CHECK_EQUAL("foo", sharp::string_trim("foo", "*+"));
     CHECK_EQUAL("", sharp::string_trim("", "*+"));
   }
+
+  TEST(last_index_of)
+  {
+    Glib::ustring line = "\t\tjust\na\tbunch of\n\nrandom\t words\n\n\t";
+    CHECK_EQUAL(line.size() - 1, sharp::string_last_index_of(line, ""));
+    CHECK_EQUAL(0, sharp::string_last_index_of("", ""));
+    CHECK_EQUAL(8, sharp::string_last_index_of("foo bar baz", "ba"));
+    CHECK_EQUAL(-1, sharp::string_last_index_of("foo bar baz", "Camel"));
+  }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]