[gnote] Use Glib::ustring for string_replace_regex



commit e12a98df9d84acd35812a1c6dd36c2629b10c366
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sun Jan 22 18:42:31 2017 +0200

    Use Glib::ustring for string_replace_regex

 src/sharp/string.cpp           |    6 +++---
 src/sharp/string.hpp           |    4 ++--
 src/test/unit/stringutests.cpp |   10 ++++++++++
 3 files changed, 15 insertions(+), 5 deletions(-)
---
diff --git a/src/sharp/string.cpp b/src/sharp/string.cpp
index 67664f6..ad9ce48 100644
--- a/src/sharp/string.cpp
+++ b/src/sharp/string.cpp
@@ -88,9 +88,9 @@ namespace sharp {
     return result;
   }
 
-  std::string string_replace_regex(const std::string & source,
-                                   const std::string & regex,
-                                   const std::string & with)
+  Glib::ustring string_replace_regex(const Glib::ustring & source,
+                                     const Glib::ustring & regex,
+                                     const Glib::ustring & with)
   {
     Glib::RefPtr<Glib::Regex> re = Glib::Regex::create(regex);
     return re->replace(source, 0, with, static_cast<Glib::RegexMatchFlags>(0));
diff --git a/src/sharp/string.hpp b/src/sharp/string.hpp
index 68531ec..ccd423a 100644
--- a/src/sharp/string.hpp
+++ b/src/sharp/string.hpp
@@ -51,8 +51,8 @@ namespace sharp {
   /** 
    * regex replace in %source with matching %regex with %with
    * and return a copy */
-  std::string string_replace_regex(const std::string & source, const std::string & regex,
-                                   const std::string & with);
+  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);
 
   void string_split(std::vector<std::string> & split, const std::string & source,
diff --git a/src/test/unit/stringutests.cpp b/src/test/unit/stringutests.cpp
index 08f8e0d..3607fc4 100644
--- a/src/test/unit/stringutests.cpp
+++ b/src/test/unit/stringutests.cpp
@@ -74,5 +74,15 @@ SUITE(String)
     res = sharp::string_replace_all("foo bar baz", "baz", "bar");
     CHECK_EQUAL("foo bar bar", res);
   }
+
+  TEST(replace_regex)
+  {
+    Glib::ustring res;
+    res = sharp::string_replace_regex("CamelCase", "([aem])", "Xx");
+    CHECK_EQUAL("CXxXxXxlCXxsXx", res);
+
+    res = sharp::string_replace_regex("CamelCase", "ame", "Xx");
+    CHECK_EQUAL("CXxlCase", res);
+  }
 }
 


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