[gnote] Replace sharp::string_(ends|starts)_with with their Glibmm equivalents



commit 5491163fa14b87acd21c88075626fe5e7692a3f0
Author: Debarshi Ray <debarshir src gnome org>
Date:   Sun Jan 3 18:43:27 2010 +0200

    Replace sharp::string_(ends|starts)_with with their Glibmm equivalents

 src/gnote.cpp                              |    3 +--
 src/notebooks/notebookapplicationaddin.cpp |    5 +++--
 src/notebooks/notebookmanager.cpp          |   13 +++++++------
 src/sharp/string.cpp                       |   17 -----------------
 src/sharp/string.hpp                       |    2 --
 src/sharp/uri.cpp                          |    6 +++---
 src/tag.cpp                                |    4 +++-
 src/tagmanager.cpp                         |    6 ++++--
 src/utils.cpp                              |    6 +++---
 src/watchers.cpp                           |    6 +++---
 10 files changed, 27 insertions(+), 41 deletions(-)
---
diff --git a/src/gnote.cpp b/src/gnote.cpp
index d2fbb61..f0b6ed6 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -48,7 +48,6 @@
 #include "recentchanges.hpp"
 #include "utils.hpp"
 #include "xkeybinder.hpp"
-#include "sharp/string.hpp"
 #include "sharp/streamreader.hpp"
 #include "sharp/files.hpp"
 
@@ -487,7 +486,7 @@ namespace gnote {
     }
 
     if(m_open_note && *m_open_note) {
-      if (sharp::string_starts_with(m_open_note, "note://gnote/")) {
+      if (Glib::str_has_prefix(m_open_note, "note://gnote/")) {
         m_open_note_uri = m_open_note;
       }
       else if (sharp::file_exists(m_open_note)) {
diff --git a/src/notebooks/notebookapplicationaddin.cpp b/src/notebooks/notebookapplicationaddin.cpp
index 09a8789..57303cd 100644
--- a/src/notebooks/notebookapplicationaddin.cpp
+++ b/src/notebooks/notebookapplicationaddin.cpp
@@ -21,6 +21,7 @@
 
 #include <boost/bind.hpp>
 
+#include <glibmm.h>
 #include <glibmm/i18n.h>
 #include <gtkmm/stock.h>
 #include <gtkmm/treeiter.h>
@@ -303,7 +304,7 @@ namespace gnote {
       
       std::string megaPrefix(Tag::SYSTEM_TAG_PREFIX);
       megaPrefix += Notebook::NOTEBOOK_TAG_PREFIX;
-      if (!tag->is_system() || !sharp::string_starts_with(tag->name(), megaPrefix)) {
+      if (!tag->is_system() || !Glib::str_has_prefix(tag->name(), megaPrefix)) {
         return;
       }
       
@@ -324,7 +325,7 @@ namespace gnote {
       std::string megaPrefix(Tag::SYSTEM_TAG_PREFIX);
       megaPrefix += Notebook::NOTEBOOK_TAG_PREFIX;
 
-      if (!sharp::string_starts_with(normalizedTagName, megaPrefix)) {
+      if (!Glib::str_has_prefix(normalizedTagName, megaPrefix)) {
         return;
       }
       
diff --git a/src/notebooks/notebookmanager.cpp b/src/notebooks/notebookmanager.cpp
index 80f03a0..26b2773 100644
--- a/src/notebooks/notebookmanager.cpp
+++ b/src/notebooks/notebookmanager.cpp
@@ -20,6 +20,7 @@
 
 #include <string.h>
 
+#include <glibmm.h>
 #include <glibmm/i18n.h>
 #include <gtkmm/treemodelsort.h>
 
@@ -265,9 +266,9 @@ namespace gnote {
     bool NotebookManager::is_notebook_tag(const Tag::Ptr & tag)
     {
       std::string fullTagName = tag->name();
-      return sharp::string_starts_with(fullTagName, 
-                                       std::string(Tag::SYSTEM_TAG_PREFIX) 
-                                       + Notebook::NOTEBOOK_TAG_PREFIX);
+      return Glib::str_has_prefix(fullTagName,
+                                  std::string(Tag::SYSTEM_TAG_PREFIX)
+                                  + Notebook::NOTEBOOK_TAG_PREFIX);
     }
 
 
@@ -440,9 +441,9 @@ namespace gnote {
         const Tag::Ptr & tag(*tag_iter);
         // Skip over tags that aren't notebooks
         if (!tag->is_system()
-            || !sharp::string_starts_with(tag->name(),
-                                          std::string(Tag::SYSTEM_TAG_PREFIX)
-                                          + Notebook::NOTEBOOK_TAG_PREFIX)) {
+            || !Glib::str_has_prefix(tag->name(),
+                                     std::string(Tag::SYSTEM_TAG_PREFIX)
+                                     + Notebook::NOTEBOOK_TAG_PREFIX)) {
           continue;
         }
         Notebook::Ptr notebook(new Notebook (tag));
diff --git a/src/sharp/string.cpp b/src/sharp/string.cpp
index ab845b2..ba679a8 100644
--- a/src/sharp/string.cpp
+++ b/src/sharp/string.cpp
@@ -106,23 +106,6 @@ namespace sharp {
     return boost::trim_copy_if(source, boost::is_any_of(set_of_char));
   }
 
-  bool string_starts_with(const std::string & source, const std::string & with)
-  {
-    if(source.empty()) {
-      return false;
-    }
-    return boost::starts_with(source, with);
-  }
-
-  bool string_ends_with(const std::string & source, const std::string & with)
-  {
-    if(source.empty()) {
-      return false;
-    }
-    return boost::ends_with(source, with);
-  }
-
-
   bool string_contains(const std::string & source, const std::string &search)
   {
     return string_index_of(source, search) != -1;
diff --git a/src/sharp/string.hpp b/src/sharp/string.hpp
index a42c6cb..89aed99 100644
--- a/src/sharp/string.hpp
+++ b/src/sharp/string.hpp
@@ -67,8 +67,6 @@ namespace sharp {
   std::string string_trim(const std::string & source);
   std::string string_trim(const std::string & source, const char * set_of_char);
 
-  bool string_starts_with(const std::string & source, const std::string & with);
-  bool string_ends_with(const std::string & source, const std::string & with);
   bool string_contains(const std::string & source, const std::string &);
   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);
diff --git a/src/sharp/uri.cpp b/src/sharp/uri.cpp
index fa244f4..a1b9b1d 100644
--- a/src/sharp/uri.cpp
+++ b/src/sharp/uri.cpp
@@ -23,7 +23,7 @@
  */
 
 
-
+#include <glibmm.h>
 
 #include "sharp/string.hpp"
 #include "sharp/uri.hpp"
@@ -38,7 +38,7 @@ namespace sharp {
 
   bool Uri::is_file() const
   {
-    return string_starts_with(m_uri, FILE_URI_SCHEME);
+    return Glib::str_has_prefix(m_uri, FILE_URI_SCHEME);
   }
 
 
@@ -54,7 +54,7 @@ namespace sharp {
 
   bool Uri::_is_scheme(const std::string & scheme) const
   {
-    return string_starts_with(m_uri, scheme);
+    return Glib::str_has_prefix(m_uri, scheme);
   }
 
   std::string Uri::get_host() const
diff --git a/src/tag.cpp b/src/tag.cpp
index a2a7108..0defe8a 100644
--- a/src/tag.cpp
+++ b/src/tag.cpp
@@ -21,6 +21,8 @@
 
 #include <map>
 
+#include <glibmm.h>
+
 #include "sharp/map.hpp"
 #include "sharp/string.hpp"
 #include "note.hpp"
@@ -72,7 +74,7 @@ namespace gnote {
       if (!trimmed_name.empty()) {
         m_name = trimmed_name;
         m_normalized_name = sharp::string_to_lower(trimmed_name);
-        if(sharp::string_starts_with(m_normalized_name, SYSTEM_TAG_PREFIX)) {
+        if(Glib::str_has_prefix(m_normalized_name, SYSTEM_TAG_PREFIX)) {
           m_issystem = true;
         }
         std::vector<std::string> splits;
diff --git a/src/tagmanager.cpp b/src/tagmanager.cpp
index 0c513a6..d73ae82 100644
--- a/src/tagmanager.cpp
+++ b/src/tagmanager.cpp
@@ -20,6 +20,8 @@
 
 #include <string.h>
 
+#include <glibmm.h>
+
 #include "tagmanager.hpp"
 #include "debug.hpp"
 #include "note.hpp"
@@ -73,7 +75,7 @@ namespace gnote {
 
     std::vector<std::string> splits;
     sharp::string_split(splits, normalized_tag_name, ":");
-    if ((splits.size() > 2) || sharp::string_starts_with(normalized_tag_name, Tag::SYSTEM_TAG_PREFIX)) {
+    if ((splits.size() > 2) || Glib::str_has_prefix(normalized_tag_name, Tag::SYSTEM_TAG_PREFIX)) {
       Glib::Mutex::Lock lock(m_locker);
       std::map<std::string, Tag::Ptr>::const_iterator iter = m_internal_tags.find(normalized_tag_name);
       if(iter != m_internal_tags.end()) {
@@ -104,7 +106,7 @@ namespace gnote {
 
     std::vector<std::string> splits;
     sharp::string_split(splits, normalized_tag_name, ":");
-    if ((splits.size() > 2) || sharp::string_starts_with(normalized_tag_name, Tag::SYSTEM_TAG_PREFIX)){
+    if ((splits.size() > 2) || Glib::str_has_prefix(normalized_tag_name, Tag::SYSTEM_TAG_PREFIX)){
       Glib::Mutex::Lock lock(m_locker);
       std::map<std::string, Tag::Ptr>::iterator iter;
       iter = m_internal_tags.find(normalized_tag_name);
diff --git a/src/utils.cpp b/src/utils.cpp
index 1c3c78c..b2a2cd9 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -458,17 +458,17 @@ namespace gnote {
 
         const std::string & i(*iter);
 
-        if(sharp::string_starts_with(i, "#")) {
+        if(Glib::str_has_prefix(i, "#")) {
           continue;
         }
 
         std::string s = i;
-        if(sharp::string_ends_with(i, "\r")) {
+        if(Glib::str_has_suffix(i, "\r")) {
           s.erase(s.end() - 1, s.end());
         }
 
         // Handle evo's broken file urls
-        if(sharp::string_starts_with(s, "file:////")) {
+        if(Glib::str_has_prefix(s, "file:////")) {
           s = sharp::string_replace_first(s, "file:////", "file:///");
         }
         DBG_OUT("uri = %s", s.c_str());
diff --git a/src/watchers.cpp b/src/watchers.cpp
index 1b6911a..77cefc6 100644
--- a/src/watchers.cpp
+++ b/src/watchers.cpp
@@ -455,14 +455,14 @@ namespace gnote {
     // Simple url massaging.  Add to 'http://' to the front
     // of www.foo.com, 'mailto:' to alex foo com, 'file://'
     // to /home/alex/foo.
-    if (sharp::string_starts_with(url, "www.")) {
+    if (Glib::str_has_prefix(url, "www.")) {
       url = "http://"; + url;
     }
-    else if (sharp::string_starts_with(url, "/") &&
+    else if (Glib::str_has_prefix(url, "/") &&
              sharp::string_last_index_of(url, "/") > 1) {
       url = "file://" + url;
     }
-    else if (sharp::string_starts_with(url, "~/")) {
+    else if (Glib::str_has_prefix(url, "~/")) {
       const char * home = getenv("HOME");
       if(home) {
         url = std::string("file://") + home + "/" +



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