[gnote] Glib::ustring and no boost in string_replace_first



commit 348fcb0d782b8b04cfce5d38dbaf2d0713c1c633
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sun Jan 22 14:21:20 2017 +0200

    Glib::ustring and no boost in string_replace_first

 src/sharp/string.cpp |   17 +++++++++++++----
 src/sharp/string.hpp |    6 +++---
 2 files changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/src/sharp/string.cpp b/src/sharp/string.cpp
index 0bf7253..a6b59d5 100644
--- a/src/sharp/string.cpp
+++ b/src/sharp/string.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012,2014 Aurimas Cernius
+ * Copyright (C) 2012,2014,2017 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -42,10 +42,19 @@
 namespace sharp {
 
 
-  std::string string_replace_first(const std::string & source, const std::string & from,
-                             const std::string & with)
+  Glib::ustring string_replace_first(const Glib::ustring & source, const Glib::ustring & what,
+                                     const Glib::ustring & with)
   {
-    return boost::replace_first_copy(source, from, with);
+    if(source.empty() || what.empty() || what == with) {
+      return source;
+    }
+
+    Glib::ustring result;
+    auto pos = source.find(what);
+    result += source.substr(0, pos);
+    result += with;
+    result += source.substr(pos + what.size());
+    return result;
   }
 
   std::string string_replace_all(const std::string & source, const std::string & from,
diff --git a/src/sharp/string.hpp b/src/sharp/string.hpp
index 9cf2a0d..05a39df 100644
--- a/src/sharp/string.hpp
+++ b/src/sharp/string.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2014 Aurimas Cernius
+ * Copyright (C) 2014,2017 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -39,8 +39,8 @@ namespace sharp {
    * replace the first instance of %from with %with 
    * in string %source and return the result
    */
-  std::string string_replace_first(const std::string & source, const std::string & from,
-                             const std::string & with);
+  Glib::ustring string_replace_first(const Glib::ustring & source, const Glib::ustring & what,
+                                     const Glib::ustring & with);
 
   /**
    * replace all instances of %from with %with 


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