[gxml] TokenList: renamed from GDomTokenList
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] TokenList: renamed from GDomTokenList
- Date: Fri, 5 Jul 2019 18:47:54 +0000 (UTC)
commit c6cdcfa14f7b593d71cb621cab3ff95ddf23b950
Author: Daniel Espinosa <esodan gmail com>
Date: Fri Jul 5 13:36:07 2019 -0500
TokenList: renamed from GDomTokenList
gxml/DomCollections.vala | 2 +-
gxml/GDomCollections.vala | 89 ------------------------------------
gxml/TokenList.vala | 113 ++++++++++++++++++++++++++++++++++++++++++++++
gxml/meson.build | 1 +
4 files changed, 115 insertions(+), 90 deletions(-)
---
diff --git a/gxml/DomCollections.vala b/gxml/DomCollections.vala
index d1fe240..5c2d6a9 100644
--- a/gxml/DomCollections.vala
+++ b/gxml/DomCollections.vala
@@ -130,7 +130,7 @@ public class GXml.DomNodeFilter : Object {
public const int SHOW_DOCUMENT_FRAGMENT = (int) 0x400;
public const int SHOW_NOTATION = (int) 0x800; // historical
- public delegate int AcceptNode(Node node); // FIXME: Should be a User defined method
+ public delegate int accept_node (DomNode node); // FIXME: Should be a User defined method
}
diff --git a/gxml/GDomCollections.vala b/gxml/GDomCollections.vala
index 3d2d86c..57d7d32 100644
--- a/gxml/GDomCollections.vala
+++ b/gxml/GDomCollections.vala
@@ -22,95 +22,6 @@
using Gee;
-/**
- * DOM4 List of string tokens, powered by libxml2 library.
- */
-public class GXml.GDomTokenList : Gee.ArrayList<string>, GXml.DomTokenList {
- protected DomElement _element;
- protected string _attr = null;
-
- public int length { get { return size; } }
- public string? item (int index) { return base.get (index); }
-
- public GDomTokenList (DomElement e, string? attr) {
- _element = e;
- _attr = attr;
- if (_attr != null) {
- var av = _element.get_attribute (_attr);
- if (av == "") return;
- if (" " in av) {
- string[] s = av.split (" ");
- for (int i = 0; i < s.length; i++) {
- (this as Gee.ArrayList<string>).add (s[i]);
- }
- } else {
- (this as Gee.ArrayList<string>).add (av);
- }
- }
- }
-
- public new bool contains (string token) throws GLib.Error {
- if (token == "")
- throw new GXml.DomError.SYNTAX_ERROR (_("DOM: Invalid token. No empty string could be used as token to
check if it is contained in token list"));
- if (" " in token)
- throw new GXml.DomError.INVALID_CHARACTER_ERROR (_("DOM: Invalid token. No white spaces could be
included as token to check if it is contained in token list"));
- return base.contains (token);
- }
-
- public new void add (string[] tokens) throws GLib.Error {
- foreach (string s in tokens) {
- if (s == "")
- throw new GXml.DomError.SYNTAX_ERROR (_("DOM: Invalid token. Empty string can't be used as
token"));
- if (" " in s)
- throw new GXml.DomError.INVALID_CHARACTER_ERROR (_("DOM: Invalid token. White spaces can't be used
as token"));
- base.add (s);
- }
- update ();
- }
- public new void remove (string[] tokens) {
- for (int i = 0; i < size; i++) {
- string s = get (i);
- foreach (string ts in tokens) {
- if (s == ts) base.remove_at (i);
- }
- }
- update ();
- }
- /**
- * A convenient method to remove or add tokens. If force is true, this method
- * will add it to the list of tokens, same as {@link add}. If force is false
- * will remove a token from the list {@link remove}
- */
- public bool toggle (string token, bool force = false, bool auto = true) throws GLib.Error {
- if (token == "")
- throw new GXml.DomError.SYNTAX_ERROR (_("DOM: Invalid token. Empty string can't be used as token"));
- if (" " in token)
- throw new GXml.DomError.INVALID_CHARACTER_ERROR (_("DOM: Invalid token. White spaces can't be used as
token"));
- if (contains (token) && auto) { // FIXME: missing force use
- remove_at (index_of (token));
- return false;
- } else {
- if (!force) return false;
- }
- update ();
- return true;
- }
- public void update () {
- if (_element == null) return;
- if (_attr == null) return;
- try { _element.set_attribute (_attr, this.to_string ()); }
- catch (GLib.Error e) { warning (_("Update Error: ")+e.message); }
- }
- public string to_string () {
- string s = "";
- for (int i = 0; i < size; i++ ) {
- s += this.get (i);
- if (i+1 < size) s += " ";
- }
- return s;
- }
-}
-
/**
* DOM4 Setteable token list, powered by libxml2 library.
*/
diff --git a/gxml/TokenList.vala b/gxml/TokenList.vala
new file mode 100644
index 0000000..1ca20ce
--- /dev/null
+++ b/gxml/TokenList.vala
@@ -0,0 +1,113 @@
+/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
+/* GXmlDomCollections.vala
+ *
+ * Copyright (C) 2016 Daniel Espinosa <esodan gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Daniel Espinosa <esodan gmail com>
+ */
+
+using Gee;
+
+/**
+ * DOM4 List of string tokens, powered by libxml2 library.
+ */
+public class GXml.TokenList : Gee.ArrayList<string>, GXml.DomTokenList {
+ protected DomElement _element;
+ protected string _attr = null;
+
+ public int length { get { return size; } }
+ public string? item (int index) { return base.get (index); }
+
+ public TokenList (DomElement e, string? attr) {
+ _element = e;
+ _attr = attr;
+ if (_attr != null) {
+ var av = _element.get_attribute (_attr);
+ if (av == "") return;
+ if (" " in av) {
+ string[] s = av.split (" ");
+ for (int i = 0; i < s.length; i++) {
+ (this as Gee.ArrayList<string>).add (s[i]);
+ }
+ } else {
+ (this as Gee.ArrayList<string>).add (av);
+ }
+ }
+ }
+
+ public new bool contains (string token) throws GLib.Error {
+ if (token == "")
+ throw new GXml.DomError.SYNTAX_ERROR (_("DOM: Invalid token. No empty string could be used as token to
check if it is contained in token list"));
+ if (" " in token)
+ throw new GXml.DomError.INVALID_CHARACTER_ERROR (_("DOM: Invalid token. No white spaces could be
included as token to check if it is contained in token list"));
+ return base.contains (token);
+ }
+
+ public new void add (string[] tokens) throws GLib.Error {
+ foreach (string s in tokens) {
+ if (s == "")
+ throw new GXml.DomError.SYNTAX_ERROR (_("DOM: Invalid token. Empty string can't be used as
token"));
+ if (" " in s)
+ throw new GXml.DomError.INVALID_CHARACTER_ERROR (_("DOM: Invalid token. White spaces can't be used
as token"));
+ base.add (s);
+ }
+ update ();
+ }
+ public new void remove (string[] tokens) {
+ for (int i = 0; i < size; i++) {
+ string s = get (i);
+ foreach (string ts in tokens) {
+ if (s == ts) base.remove_at (i);
+ }
+ }
+ update ();
+ }
+ /**
+ * A convenient method to remove or add tokens. If force is true, this method
+ * will add it to the list of tokens, same as {@link add}. If force is false
+ * will remove a token from the list {@link remove}
+ */
+ public bool toggle (string token, bool force = false, bool auto = true) throws GLib.Error {
+ if (token == "")
+ throw new GXml.DomError.SYNTAX_ERROR (_("DOM: Invalid token. Empty string can't be used as token"));
+ if (" " in token)
+ throw new GXml.DomError.INVALID_CHARACTER_ERROR (_("DOM: Invalid token. White spaces can't be used as
token"));
+ if (contains (token) && auto) { // FIXME: missing force use
+ remove_at (index_of (token));
+ return false;
+ } else {
+ if (!force) return false;
+ }
+ update ();
+ return true;
+ }
+ public void update () {
+ if (_element == null) return;
+ if (_attr == null) return;
+ try { _element.set_attribute (_attr, this.to_string ()); }
+ catch (GLib.Error e) { warning (_("Update Error: ")+e.message); }
+ }
+ public string to_string () {
+ string s = "";
+ for (int i = 0; i < size; i++ ) {
+ s += this.get (i);
+ if (i+1 < size) s += " ";
+ }
+ return s;
+ }
+}
+
diff --git a/gxml/meson.build b/gxml/meson.build
index 4de553b..26d50c5 100644
--- a/gxml/meson.build
+++ b/gxml/meson.build
@@ -72,6 +72,7 @@ valasources = files ([
'NodeType.vala',
'Parser.vala',
'Schema.vala',
+ 'TokenList.vala',
'XAttribute.vala',
'XCharacter.vala',
'XChildNode.vala',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]