[gnote] Use std::vector in parse_tags
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Use std::vector in parse_tags
- Date: Sun, 7 Apr 2019 16:42:30 +0000 (UTC)
commit 13dc3765ee7252eaa51d3cb6f56775580e721558
Author: Aurimas Černius <aurisc4 gmail com>
Date: Sun Apr 7 17:32:08 2019 +0300
Use std::vector in parse_tags
src/notebase.cpp | 18 +++++++++---------
src/notebase.hpp | 5 +++--
2 files changed, 12 insertions(+), 11 deletions(-)
---
diff --git a/src/notebase.cpp b/src/notebase.cpp
index 3ee03878..f279d1a0 100644
--- a/src/notebase.cpp
+++ b/src/notebase.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2011-2014,2017 Aurimas Cernius
+ * Copyright (C) 2011-2014,2017,2019 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -62,15 +62,15 @@ Glib::ustring NoteBase::url_from_path(const Glib::ustring & filepath)
return "note://gnote/" + sharp::file_basename(filepath);
}
-void NoteBase::parse_tags(const xmlNodePtr tagnodes, std::list<Glib::ustring> & tags)
+std::vector<Glib::ustring> NoteBase::parse_tags(const xmlNodePtr tagnodes)
{
+ std::vector<Glib::ustring> tags;
sharp::XmlNodeSet nodes = sharp::xml_node_xpath_find(tagnodes, "//*");
if(nodes.empty()) {
- return;
+ return tags;
}
- for(sharp::XmlNodeSet::const_iterator iter = nodes.begin(); iter != nodes.end(); ++iter) {
- const xmlNodePtr node = *iter;
+ for(auto & node : nodes) {
if(xmlStrEqual(node->name, (const xmlChar*)"tag") && (node->type == XML_ELEMENT_NODE)) {
xmlChar * content = xmlNodeGetContent(node);
if(content) {
@@ -80,6 +80,8 @@ void NoteBase::parse_tags(const xmlNodePtr tagnodes, std::list<Glib::ustring> &
}
}
}
+
+ return tags;
}
@@ -332,8 +334,7 @@ void NoteBase::load_foreign_note_xml(const Glib::ustring & foreignNoteXml, Chang
else if(name == "tags") {
xmlDocPtr doc2 = xmlParseDoc((const xmlChar*)xml.read_outer_xml().c_str());
if(doc2) {
- std::list<Glib::ustring> tag_strings;
- parse_tags(doc2->children, tag_strings);
+ std::vector<Glib::ustring> tag_strings = parse_tags(doc2->children);
FOREACH(Glib::ustring & tag_str, tag_strings) {
Tag::Ptr tag = ITagManager::obj().get_or_create_tag(tag_str);
new_tags.push_back(tag);
@@ -492,8 +493,7 @@ void NoteArchiver::_read(sharp::XmlReader & xml, NoteData & data, Glib::ustring
xmlDocPtr doc2 = xmlParseDoc((const xmlChar*)xml.read_outer_xml().c_str());
if(doc2) {
- std::list<Glib::ustring> tag_strings;
- NoteBase::parse_tags(doc2->children, tag_strings);
+ std::vector<Glib::ustring> tag_strings = NoteBase::parse_tags(doc2->children);
FOREACH(Glib::ustring & tag_str, tag_strings) {
Tag::Ptr tag = ITagManager::obj().get_or_create_tag(tag_str);
data.tags()[tag->normalized_name()] = tag;
diff --git a/src/notebase.hpp b/src/notebase.hpp
index 15b0def2..c5e2abc2 100644
--- a/src/notebase.hpp
+++ b/src/notebase.hpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2011-2014,2017 Aurimas Cernius
+ * Copyright (C) 2011-2014,2017,2019 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -23,6 +23,7 @@
#define _NOTEBASE_HPP_
#include <map>
+#include <vector>
#include <glibmm/ustring.h>
#include <sigc++/signal.h>
@@ -193,7 +194,7 @@ public:
typedef std::list<Ptr> List;
static Glib::ustring url_from_path(const Glib::ustring &);
- static void parse_tags(const xmlNodePtr tagnodes, std::list<Glib::ustring> & tags);
+ static std::vector<Glib::ustring> parse_tags(const xmlNodePtr tagnodes);
NoteBase(NoteData *_data, const Glib::ustring & filepath, NoteManagerBase & manager);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]