[gnote] Use Glib::ustring for string_match_iregex and test



commit 1c71d94c75cd9ca342c8e29809f2409be942b1d9
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sun Jan 22 19:01:00 2017 +0200

    Use Glib::ustring for string_match_iregex and test

 src/sharp/string.cpp           |    4 ++--
 src/sharp/string.hpp           |    2 +-
 src/test/unit/stringutests.cpp |    5 +++++
 3 files changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/src/sharp/string.cpp b/src/sharp/string.cpp
index ad9ce48..0e6ef4c 100644
--- a/src/sharp/string.cpp
+++ b/src/sharp/string.cpp
@@ -96,11 +96,11 @@ namespace sharp {
     return re->replace(source, 0, with, static_cast<Glib::RegexMatchFlags>(0));
   }
   
-  bool string_match_iregex(const std::string & source, const std::string & regex)  
+  bool string_match_iregex(const Glib::ustring & source, const Glib::ustring & regex)
   {
     Glib::RefPtr<Glib::Regex> re = Glib::Regex::create(regex, Glib::REGEX_CASELESS);
     Glib::MatchInfo match_info;
-    if(re->match(source)) {
+    if(re->match(source, match_info)) {
       return match_info.fetch(0) == source;
     }
     return false;
diff --git a/src/sharp/string.hpp b/src/sharp/string.hpp
index ccd423a..21a118e 100644
--- a/src/sharp/string.hpp
+++ b/src/sharp/string.hpp
@@ -53,7 +53,7 @@ namespace sharp {
    * and return a copy */
   Glib::ustring string_replace_regex(const Glib::ustring & source, const Glib::ustring & regex,
                                      const Glib::ustring & with);
-  bool string_match_iregex(const std::string & source, const std::string & regex);
+  bool string_match_iregex(const Glib::ustring & source, const Glib::ustring & regex);
 
   void string_split(std::vector<std::string> & split, const std::string & source,
                     const char * delimiters);
diff --git a/src/test/unit/stringutests.cpp b/src/test/unit/stringutests.cpp
index 3607fc4..5e4664c 100644
--- a/src/test/unit/stringutests.cpp
+++ b/src/test/unit/stringutests.cpp
@@ -84,5 +84,10 @@ SUITE(String)
     res = sharp::string_replace_regex("CamelCase", "ame", "Xx");
     CHECK_EQUAL("CXxlCase", res);
   }
+
+  TEST(match_iregex)
+  {
+    CHECK(sharp::string_match_iregex("CamelCase", "^Camel.*$"));
+  }
 }
 


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