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



commit 9f1b52c3226974cfcae4e3a947d14756191ce20d
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sun Jan 22 22:49:29 2017 +0200

    Use Glib::ustring in string_split and no boost

 src/addininfo.cpp                 |    6 +++---
 src/mainwindow.cpp                |    4 ++--
 src/note.cpp                      |    6 ++----
 src/notemanagerbase.cpp           |    2 +-
 src/searchnoteswidget.cpp         |    2 +-
 src/sharp/string.cpp              |   29 ++++++++++++++++++++++-------
 src/sharp/string.hpp              |    5 ++---
 src/sharp/timespan.cpp            |    2 +-
 src/synchronization/syncutils.cpp |    8 ++++----
 src/tag.cpp                       |    4 ++--
 src/tagmanager.cpp                |    6 +++---
 src/test/unit/stringutests.cpp    |   28 ++++++++++++++++++++++++++++
 src/utils.cpp                     |    9 ++-------
 13 files changed, 73 insertions(+), 38 deletions(-)
---
diff --git a/src/addininfo.cpp b/src/addininfo.cpp
index e2fa9ca..02a7e7a 100644
--- a/src/addininfo.cpp
+++ b/src/addininfo.cpp
@@ -104,7 +104,7 @@ void AddinInfo::load_from_file(const std::string & info_file)
       load_actions(addin_info, "actions_int", &Glib::Variant<gint32>::variant_type());
       load_actions(addin_info, "actions_string", &Glib::Variant<Glib::ustring>::variant_type());
       if(addin_info.has_key(ADDIN_ACTIONS, "non_modifying_actions")) {
-        std::vector<std::string> actions;
+        std::vector<Glib::ustring> actions;
         sharp::string_split(actions, addin_info.get_string(ADDIN_ACTIONS, "non_modifying_actions"), ",");
         for(auto action : actions) {
           m_non_modifying_actions.push_back(action);
@@ -120,7 +120,7 @@ void AddinInfo::load_from_file(const std::string & info_file)
 void AddinInfo::load_actions(Glib::KeyFile & addin_info, const Glib::ustring & key, const Glib::VariantType 
*type)
 {
   if(addin_info.has_key(ADDIN_ACTIONS, key)) {
-    std::vector<std::string> actions;
+    std::vector<Glib::ustring> actions;
     sharp::string_split(actions, addin_info.get_string(ADDIN_ACTIONS, key), ",");
     for(auto action : actions) {
       m_actions[action] = type;
@@ -159,7 +159,7 @@ bool AddinInfo::validate_compatibility(const Glib::ustring & release, const Glib
   }
   else {
     try {
-      std::vector<std::string> parts;
+      std::vector<Glib::ustring> parts;
       sharp::string_split(parts, m_libgnote_version_info, ":");
       if(parts.size() != 3) {
         return false;
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 4f3f808..2120d6a 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2013,2015-2016 Aurimas Cernius
+ * Copyright (C) 2013,2015-2017 Aurimas Cernius
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -116,7 +116,7 @@ bool MainWindow::use_client_side_decorations()
     }
     else {
       s_use_client_side_decorations = 0;
-      std::vector<std::string> desktops;
+      std::vector<Glib::ustring> desktops;
       sharp::string_split(desktops, setting, ",");
       const char *current_desktop = std::getenv("DESKTOP_SESSION");
       if (current_desktop) {
diff --git a/src/note.cpp b/src/note.cpp
index 27826a7..75fc408 100644
--- a/src/note.cpp
+++ b/src/note.cpp
@@ -802,11 +802,9 @@ namespace gnote {
       new_pinned = uri() + " " + old_pinned;
     } 
     else {
-      std::vector<std::string> pinned_split;
+      std::vector<Glib::ustring> pinned_split;
       sharp::string_split(pinned_split, old_pinned, " \t\n");
-      for(std::vector<std::string>::const_iterator iter = pinned_split.begin();
-          iter != pinned_split.end(); ++iter) {
-        const std::string & pin(*iter);
+      for(auto pin : pinned_split) {
         if (!pin.empty() && (pin != uri())) {
           new_pinned += pin + " ";
         }
diff --git a/src/notemanagerbase.cpp b/src/notemanagerbase.cpp
index 76409df..aad20bc 100644
--- a/src/notemanagerbase.cpp
+++ b/src/notemanagerbase.cpp
@@ -398,7 +398,7 @@ Glib::ustring NoteManagerBase::split_title_from_content(Glib::ustring title, Gli
   if(title.empty())
     return "";
 
-  std::vector<std::string> lines;
+  std::vector<Glib::ustring> lines;
   sharp::string_split(lines, title, "\n\r");
   if(lines.size() > 0) {
     title = lines [0];
diff --git a/src/searchnoteswidget.cpp b/src/searchnoteswidget.cpp
index 5b63928..0b26ef4 100644
--- a/src/searchnoteswidget.cpp
+++ b/src/searchnoteswidget.cpp
@@ -1496,7 +1496,7 @@ void SearchNotesWidget::on_sorting_changed()
 
 void SearchNotesWidget::parse_sorting_setting(const Glib::ustring & sorting)
 {
-  std::vector<std::string> tokens;
+  std::vector<Glib::ustring> tokens;
   sharp::string_split(tokens, sorting.lowercase(), ":");
   if(tokens.size() != 2) {
     ERR_OUT(_("Failed to parse setting %s (Value: %s):"), Preferences::SEARCH_SORTING, sorting.c_str());
diff --git a/src/sharp/string.cpp b/src/sharp/string.cpp
index 467e633..a5cb5e3 100644
--- a/src/sharp/string.cpp
+++ b/src/sharp/string.cpp
@@ -30,10 +30,6 @@
 #include "sharp/string.hpp"
 
 #include <glibmm/regex.h>
-#include <boost/algorithm/string/case_conv.hpp>
-#include <boost/algorithm/string/classification.hpp>
-#include <boost/algorithm/string/predicate.hpp>
-#include <boost/algorithm/string/split.hpp>
 
 #include "debug.hpp"
 
@@ -105,10 +101,29 @@ namespace sharp {
     return false;
   }
 
-  void string_split(std::vector<std::string> & split, const std::string & source,
-                    const char * delimiters)
+  void string_split(std::vector<Glib::ustring> & split, const Glib::ustring & source,
+                    const Glib::ustring & delimiters)
   {
-    boost::split(split, source, boost::is_any_of(delimiters));
+    Glib::ustring::size_type start = 0;
+    while(start < source.size()) {
+      auto pos = source.find_first_of(delimiters, start);
+      if(pos == start) {
+        split.push_back("");
+      }
+      else if(pos == Glib::ustring::npos) {
+        split.push_back(source.substr(start));
+        break;
+      }
+      else {
+        split.push_back(source.substr(start, pos - start));
+      }
+      if(pos == source.size() - 1) {
+        // match at the last char in source, meaning empty part in the end
+        split.push_back("");
+        break;
+      }
+      start = pos + 1;
+    }
   }
 
   Glib::ustring string_substring(const Glib::ustring & source, int start)
diff --git a/src/sharp/string.hpp b/src/sharp/string.hpp
index 8735673..6ba25c5 100644
--- a/src/sharp/string.hpp
+++ b/src/sharp/string.hpp
@@ -28,7 +28,6 @@
 #ifndef __SHARP_STRING_HPP_
 #define __SHARP_STRING_HPP_
 
-#include <string>
 #include <vector>
 
 #include <glibmm/ustring.h>
@@ -55,8 +54,8 @@ namespace sharp {
                                      const Glib::ustring & with);
   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);
+  void string_split(std::vector<Glib::ustring> & split, const Glib::ustring & source,
+                    const Glib::ustring & delimiters);
 
   /** copy the substring for %source, starting at %start until the end */
   Glib::ustring string_substring(const Glib::ustring & source, int start);
diff --git a/src/sharp/timespan.cpp b/src/sharp/timespan.cpp
index cf44eb0..088373a 100644
--- a/src/sharp/timespan.cpp
+++ b/src/sharp/timespan.cpp
@@ -105,7 +105,7 @@ namespace sharp {
 
   TimeSpan TimeSpan::parse(const Glib::ustring & s)
   {
-    std::vector<std::string> tokens;
+    std::vector<Glib::ustring> tokens;
     sharp::string_split(tokens, s, ":");
     if(tokens.size() != 5) {
       return TimeSpan(0, 0, 0, 0, 0);
diff --git a/src/synchronization/syncutils.cpp b/src/synchronization/syncutils.cpp
index bf8aede..6827b51 100644
--- a/src/synchronization/syncutils.cpp
+++ b/src/synchronization/syncutils.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012-2014,2016 Aurimas Cernius
+ * Copyright (C) 2012-2014,2016-2017 Aurimas Cernius
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -211,7 +211,7 @@ namespace sync {
     for(std::vector<std::string>::const_iterator iter = executableNames.begin();
         iter != executableNames.end(); ++iter) {
       std::string pathVar = Glib::getenv("PATH");
-      std::vector<std::string> paths;
+      std::vector<Glib::ustring> paths;
       const char separator[] = {G_SEARCHPATH_SEPARATOR, 0};
       sharp::string_split(paths, pathVar, separator);
 
@@ -222,8 +222,8 @@ namespace sync {
         }
       }
 
-      for(std::vector<std::string>::iterator path = paths.begin(); path != paths.end(); ++path) {
-        std::string testExecutablePath = Glib::build_filename(*path, *iter);
+      for(auto path : paths) {
+        Glib::ustring testExecutablePath = Glib::build_filename(path, *iter);
         if(sharp::file_exists(testExecutablePath)) {
           return testExecutablePath;
         }
diff --git a/src/tag.cpp b/src/tag.cpp
index 2559461..c6cfd33 100644
--- a/src/tag.cpp
+++ b/src/tag.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2014 Aurimas Cernius
+ * Copyright (C) 2014,2017 Aurimas Cernius
  * Copyright (C) 2010 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -68,7 +68,7 @@ namespace gnote {
         if(Glib::str_has_prefix(m_normalized_name, SYSTEM_TAG_PREFIX)) {
           m_issystem = true;
         }
-        std::vector<std::string> splits;
+        std::vector<Glib::ustring> splits;
         sharp::string_split(splits, value, ":");
         m_isproperty  = (splits.size() >= 3);
       }
diff --git a/src/tagmanager.cpp b/src/tagmanager.cpp
index 2ffcb56..596cb22 100644
--- a/src/tagmanager.cpp
+++ b/src/tagmanager.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011,2013-2014 Aurimas Cernius
+ * Copyright (C) 2011,2013-2014,2017 Aurimas Cernius
  * Copyright (C) 2010 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -73,7 +73,7 @@ namespace gnote {
     if (normalized_tag_name.empty())
       throw sharp::Exception ("TagManager.GetTag () called with an empty tag name.");
 
-    std::vector<std::string> splits;
+    std::vector<Glib::ustring> splits;
     sharp::string_split(splits, normalized_tag_name, ":");
     if ((splits.size() > 2) || Glib::str_has_prefix(normalized_tag_name, Tag::SYSTEM_TAG_PREFIX)) {
       Glib::Mutex::Lock lock(m_locker);
@@ -104,7 +104,7 @@ namespace gnote {
     if (normalized_tag_name.empty())
       throw sharp::Exception ("TagManager.GetOrCreateTag () called with an empty tag name.");
 
-    std::vector<std::string> splits;
+    std::vector<Glib::ustring> splits;
     sharp::string_split(splits, normalized_tag_name, ":");
     if ((splits.size() > 2) || Glib::str_has_prefix(normalized_tag_name, Tag::SYSTEM_TAG_PREFIX)){
       Glib::Mutex::Lock lock(m_locker);
diff --git a/src/test/unit/stringutests.cpp b/src/test/unit/stringutests.cpp
index 4dec974..5a8c947 100644
--- a/src/test/unit/stringutests.cpp
+++ b/src/test/unit/stringutests.cpp
@@ -121,5 +121,33 @@ SUITE(String)
     CHECK_EQUAL(8, sharp::string_last_index_of("foo bar baz", "ba"));
     CHECK_EQUAL(-1, sharp::string_last_index_of("foo bar baz", "Camel"));
   }
+
+  TEST(split)
+  {
+    std::vector<Glib::ustring> splits;
+    sharp::string_split(splits, "foo bar baz", " ");
+    CHECK_EQUAL(3, splits.size());
+    CHECK_EQUAL("foo", splits[0]);
+    CHECK_EQUAL("bar", splits[1]);
+    CHECK_EQUAL("baz", splits[2]);
+
+    splits.clear();
+    sharp::string_split(splits, "\t\tjust\na\tbunch of\n\nrandom\t words\n\n\t", " \t\n");
+
+    CHECK_EQUAL(13, splits.size());
+    CHECK_EQUAL("", splits[0]);
+    CHECK_EQUAL("", splits[1]);
+    CHECK_EQUAL("just", splits[2]);
+    CHECK_EQUAL("a", splits[3]);
+    CHECK_EQUAL("bunch", splits[4]);
+    CHECK_EQUAL("of", splits[5]);
+    CHECK_EQUAL("", splits[6]);
+    CHECK_EQUAL("random", splits[7]);
+    CHECK_EQUAL("", splits[8]);
+    CHECK_EQUAL("words", splits[9]);
+    CHECK_EQUAL("", splits[10]);
+    CHECK_EQUAL("", splits[11]);
+    CHECK_EQUAL("", splits[12]);
+  }
 }
 
diff --git a/src/utils.cpp b/src/utils.cpp
index d61f351..35a1ae2 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -548,14 +548,9 @@ namespace gnote {
 
     void UriList::load_from_string(const std::string & data)
     {
-      std::vector<std::string> items;
+      std::vector<Glib::ustring> items;
       sharp::string_split(items, data, "\n");
-      std::vector<Glib::ustring> uitems;
-      for(std::vector<std::string>::iterator iter = items.begin();
-          iter != items.end(); ++iter) {
-        uitems.push_back(*iter);
-      }
-      load_from_string_list(uitems);
+      load_from_string_list(items);
     }
 
     void UriList::load_from_string_list(const std::vector<Glib::ustring> & items)


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