[libgeexml] Indent all source files
- From: Roberto Majadas <telemaco src gnome org>
- To: svn-commits-list gnome org
- Subject: [libgeexml] Indent all source files
- Date: Fri, 26 Jun 2009 23:20:00 +0000 (UTC)
commit 01ecaf4ce498e3bbd89aa3af920433bb309eedf8
Author: Roberto Majadas <roberto majadas openshine com>
Date: Sat Jun 27 01:19:30 2009 +0200
Indent all source files
geexml/ElementTree.vala | 486 +++++++++++++++++++++++-----------------------
test/test-xmlreader.vala | 61 +++---
test/test-xmlwriter.vala | 72 ++++----
test/test-xpath.vala | 56 +++---
4 files changed, 336 insertions(+), 339 deletions(-)
---
diff --git a/geexml/ElementTree.vala b/geexml/ElementTree.vala
index 86d2195..777778f 100644
--- a/geexml/ElementTree.vala
+++ b/geexml/ElementTree.vala
@@ -24,262 +24,262 @@ using GLib;
using Xml;
namespace Gee.XmlEtree {
+
+ public errordomain Error {
+ FILE_NOT_FOUND,
+ XML_DOCUMENT_EMPTY
+ }
+
+ public class ElementTree : Element {
+
+ private Xml.Doc* _doc ;
+
+ public ElementTree( ) {
- public errordomain Error {
- FILE_NOT_FOUND,
- XML_DOCUMENT_EMPTY
}
-
- public class ElementTree : Element {
+
+ ~ElementTree( ) {
+ if ( this._doc != null ) {
+ delete this._doc ;
+ }
+ }
+
+ public Element root {
+ get {
+ return this ;
+ }
+
+ set {
+ this.node = value.node ;
+ }
+ }
+
+ public void parse_file( string path ) throws Error {
+ this._doc = Parser.parse_file( path );
+ if ( this._doc == null ) {
+ throw new Error.FILE_NOT_FOUND( "file %s not found or permissions missing", path );
+ }
+
+ this.node = this._doc->get_root_element( );
+ if ( this.node == null ) {
+ delete this._doc;
+ throw new Error.XML_DOCUMENT_EMPTY( "the xml'%s' is empty", path );
+ }
+ }
+
+ public void write( string path ) {
+ if ( this._doc == null ) {
+ this._doc = new Xml.Doc( "1.0" );
+ if ( this.node != null )
+ this._doc->set_root_element( this.node ) ;
- private Xml.Doc* _doc ;
-
- public ElementTree () {
-
- }
-
- ~ElementTree () {
- if ( this._doc != null ) {
- delete this._doc ;
- }
- }
-
- public Element root {
- get {
- return this ;
- }
-
- set {
- this.node = value.node ;
- }
- }
-
- public void parse_file (string path) throws Error {
- this._doc = Parser.parse_file (path);
- if (this._doc == null) {
- throw new Error.FILE_NOT_FOUND ("file %s not found or permissions missing", path);
- }
-
- this.node = this._doc->get_root_element ();
- if (this.node == null) {
- delete this._doc;
- throw new Error.XML_DOCUMENT_EMPTY ("the xml'%s' is empty", path);
- }
- }
-
- public void write (string path) {
- if (this._doc == null) {
- this._doc = new Xml.Doc("1.0");
- if ( this.node != null)
- this._doc->set_root_element(this.node) ;
-
- this._doc->save_format_file(path, this._doc, 1);
- }
- }
-
- public Gee.List find (string path) {
- Xml.XPathContext ctx ;
- Xml.XPathObject* objs ;
- Gee.List<Element> list = new ArrayList<Element> ();
-
- int i ;
-
- ctx = new XPathContext (this._doc) ;
- objs = ctx.eval_expression(path);
-
- if ( objs->nodesetval == null )
- return list;
-
- for ( i = 0 ; i < objs->nodesetval->length() ; i++ ) {
- Element fnode ;
- Xml.Node* node ;
-
- fnode = new Element(null);
- node = objs->nodesetval->item(i) ;
- fnode.node = node ;
- list.add(fnode);
- }
-
- return list;
- }
+ this._doc->save_format_file( path, this._doc, 1 );
+ }
+ }
+
+ public Gee.List find( string path ) {
+ Xml.XPathContext ctx ;
+ Xml.XPathObject* objs ;
+ Gee.List<Element> list = new ArrayList<Element>( );
+
+ int i ;
+
+ ctx = new XPathContext( this._doc ) ;
+ objs = ctx.eval_expression( path );
+
+ if ( objs->nodesetval == null )
+ return list;
+
+ for ( i = 0 ; i < objs->nodesetval->length( ) ; i++ ) {
+ Element fnode ;
+ Xml.Node* node ;
+ fnode = new Element( null );
+ node = objs->nodesetval->item( i ) ;
+ fnode.node = node ;
+ list.add( fnode );
+ }
+
+ return list;
}
-
- public class SubElement : Element {
-
- public SubElement (Element e , string tag) {
- this.node = new Xml.Node(null, tag);
- e.node->add_child(this.node);
- }
-
+
+ }
+
+ public class SubElement : Element {
+
+ public SubElement( Element e , string tag ) {
+ this.node = new Xml.Node( null, tag );
+ e.node->add_child( this.node );
}
-
- public class Element : Gee.Iterable<Element>,
- Gee.CollectionObject<Element>
- {
- private Xml.Node* _node ;
- private Xml.Node* _next_node ;
- private Gee.HashMap<string, string> _attrs ;
-
- public Element (string? tag) {
- if (tag != null){
- this.node = new Xml.Node(null, tag);
- }
- }
-
- public Xml.Node* node {
- get { return _node; }
- set {
- Xml.Node* iter ;
- if ( value->type != ElementType.ELEMENT_NODE ){
- iter = value->next ;
- while ( iter != null ) {
- if ( iter->type == ElementType.ELEMENT_NODE ){
- this._node = iter ;
- break;
- }
- iter = iter->next ;
- }
-
- if ( this._node == null ){
- this._next_node = null ;
- return;
- }
- }else{
- this._node = value;
- }
-
- iter = this._node->next ;
- while ( iter != null ) {
- if ( iter->type == ElementType.ELEMENT_NODE ){
- this._next_node = iter ;
- return ;
- }
- iter = iter->next ;
- }
- this._next_node = null ;
- }
- }
-
- public Xml.Node* next_node {
- get { return this._next_node ; }
- }
-
- public string tag {
- get {
- if (this.node != null){
- return this.node->name ;
- }else{
- return "" ;
- }
- }
-
- set {
- if (this.node != null){
- this.node->set_name(value) ;
- }else{
- this.node = new Xml.Node(null, value);
- }
- }
- }
-
- public Gee.HashMap<string, string> attribs {
- get {
- if ( this._attrs != null )
- return this._attrs ;
-
- this.lookup_node_attrs() ;
- return this._attrs ;
- }
- }
-
- public string text {
- get {
- Xml.Node* iter ;
- iter = this.node->children ;
- while ( iter != null ) {
- if ( iter->type == ElementType.TEXT_NODE ) {
- return iter->content ;
- }
- iter = iter->next ;
- }
- return "";
- }
- set {
- if (this.node != null)
- this.node->set_content(value) ;
+
+ }
+
+ public class Element : Gee.Iterable<Element>,
+ Gee.CollectionObject<Element>
+ {
+ private Xml.Node* _node ;
+ private Xml.Node* _next_node ;
+ private Gee.HashMap<string, string> _attrs ;
+
+ public Element( string? tag ) {
+ if ( tag != null ){
+ this.node = new Xml.Node( null, tag );
+ }
+ }
+
+ public Xml.Node* node {
+ get { return _node; }
+ set {
+ Xml.Node* iter ;
+ if ( value->type != ElementType.ELEMENT_NODE ){
+ iter = value->next ;
+ while ( iter != null ) {
+ if ( iter->type == ElementType.ELEMENT_NODE ){
+ this._node = iter ;
+ break;
}
+ iter = iter->next ;
+ }
+
+ if ( this._node == null ){
+ this._next_node = null ;
+ return;
+ }
+ }else{
+ this._node = value;
}
-
- public void append (Element e) {
- this.node->add_child(e.node);
+
+ iter = this._node->next ;
+ while ( iter != null ) {
+ if ( iter->type == ElementType.ELEMENT_NODE ){
+ this._next_node = iter ;
+ return ;
+ }
+ iter = iter->next ;
}
-
- public void set_attrib (string attr, string value) {
- if (this.node != null){
- this.node->set_prop(attr, value);
- this.lookup_node_attrs() ;
- }
+ this._next_node = null ;
+ }
+ }
+
+ public Xml.Node* next_node {
+ get { return this._next_node ; }
+ }
+
+ public string tag {
+ get {
+ if ( this.node != null ){
+ return this.node->name ;
+ }else{
+ return "" ;
}
-
- // Private Methods
- //-------------------------------------------------
-
- private void lookup_node_attrs () {
- this._attrs = new Gee.HashMap<string, string>( GLib.str_hash, GLib.str_equal );
-
- Xml.Attr* attr_iter = this.node->properties ;
- while ( attr_iter != null ) {
- this._attrs.set(attr_iter->name, attr_iter->children->content) ;
- attr_iter = attr_iter->next ;
- }
+ }
+
+ set {
+ if ( this.node != null ){
+ this.node->set_name( value ) ;
+ }else{
+ this.node = new Xml.Node( null, value );
}
-
- // Interation code
- //--------------------------------------------------
+ }
+ }
+
+ public Gee.HashMap<string, string> attribs {
+ get {
+ if ( this._attrs != null )
+ return this._attrs ;
-
- public Type get_element_type() {
- return typeof(Element);
+ this.lookup_node_attrs( ) ;
+ return this._attrs ;
+ }
+ }
+
+ public string text {
+ get {
+ Xml.Node* iter ;
+ iter = this.node->children ;
+ while ( iter != null ) {
+ if ( iter->type == ElementType.TEXT_NODE ) {
+ return iter->content ;
+ }
+ iter = iter->next ;
}
-
- public Gee.Iterator<Element> iterator() {
- return new Iterator<Element>(this);
+ return "";
+ }
+ set {
+ if ( this.node != null )
+ this.node->set_content( value ) ;
+ }
+ }
+
+ public void append( Element e ) {
+ this.node->add_child( e.node );
+ }
+
+ public void set_attrib( string attr, string value ) {
+ if ( this.node != null ){
+ this.node->set_prop( attr, value );
+ this.lookup_node_attrs( ) ;
+ }
+ }
+
+ // Private Methods
+ // -------------------------------------------------
+
+ private void lookup_node_attrs( ) {
+ this._attrs = new Gee.HashMap<string, string>( GLib.str_hash, GLib.str_equal );
+
+ Xml.Attr* attr_iter = this.node->properties ;
+ while ( attr_iter != null ) {
+ this._attrs.set( attr_iter->name, attr_iter->children->content ) ;
+ attr_iter = attr_iter->next ;
+ }
+ }
+
+ // Interation code
+ // --------------------------------------------------
+
+
+ public Type get_element_type( ) {
+ return typeof( Element );
+ }
+
+ public Gee.Iterator<Element> iterator( ) {
+ return new Iterator<Element>( this );
+ }
+
+ private class Iterator<T> : Gee.Iterator<T>,
+ Gee.CollectionObject<T> {
+
+ private Element etree { get; set; }
+ private bool first_iter ;
+
+ public Iterator( Element _etree ) {
+ this.first_iter = true ;
+ etree = new Element( null );
+ etree.node = _etree.node->children ;
+ }
+
+ public bool next( ) {
+ if ( etree.next_node == null ) {
+ return false;
+ }else{
+ return true;
}
-
- private class Iterator<T> : Gee.Iterator<T>,
- Gee.CollectionObject<T> {
-
- private Element etree { get; set; }
- private bool first_iter ;
-
- public Iterator(Element _etree) {
- this.first_iter = true ;
- etree = new Element(null);
- etree.node = _etree.node->children ;
- }
-
- public bool next() {
- if ( etree.next_node == null ) {
- return false;
- }else{
- return true;
- }
- }
-
- public T? get() {
- if ( this.first_iter != true ) {
- var new_etree = new Element(null);
- new_etree.node = etree.next_node ;
- etree = new_etree ;
- } else {
- this.first_iter = false ;
- }
-
- return etree ;
- }
-
+ }
+
+ public T? get( ) {
+ if ( this.first_iter != true ) {
+ var new_etree = new Element( null );
+ new_etree.node = etree.next_node ;
+ etree = new_etree ;
+ } else {
+ this.first_iter = false ;
}
-
+
+ return etree ;
+ }
+
}
-}
\ No newline at end of file
+
+ }
+}
diff --git a/test/test-xmlreader.vala b/test/test-xmlreader.vala
index 4dd950b..a9c9d3b 100644
--- a/test/test-xmlreader.vala
+++ b/test/test-xmlreader.vala
@@ -2,36 +2,35 @@ using GLib;
using Gee.XmlEtree;
public class BasicSample : Object {
-
- public void run () {
- var etree = new ElementTree();
-
- try {
- etree.parse_file("test1.xml");
- }catch (Gee.XmlEtree.Error e){
- stderr.printf ("Oops: %s\n", e.message);
+
+ public void run( ) {
+ var etree = new ElementTree( );
+
+ try {
+ etree.parse_file( "test1.xml" );
+ }catch( Gee.XmlEtree.Error e ){
+ stderr.printf( "Oops: %s\n", e.message );
+ }
+
+
+ // Iterating xml elements
+ // --------------------------------
+
+ foreach( Element e in etree ) {
+ stdout.printf( "<%s>\n" , e.tag );
+ foreach( string key in e.attribs.get_keys( ) ) {
+ stdout.printf( " |-> '%s' : '%s'\n", key, e.attribs[key] ) ;
}
-
-
- // Iterating xml elements
- //--------------------------------
-
- foreach (Element e in etree) {
- stdout.printf ("<%s>\n" , e.tag );
- foreach (string key in e.attribs.get_keys() ) {
- stdout.printf (" |-> '%s' : '%s'\n", key, e.attribs[key]) ;
- }
- if ( e.tag != "note" )
- stdout.printf (" \\-> text : '%s'\n", e.text);
- }
-
- }
-
- public static int main (string[] args) {
- var sample = new BasicSample ();
-
- sample.run ();
- return 0;
- }
+ if ( e.tag != "note" )
+ stdout.printf( " \\-> text : '%s'\n", e.text );
+ }
+
+ }
+
+ public static int main( string[] args ) {
+ var sample = new BasicSample( );
+
+ sample.run( );
+ return 0;
+ }
}
-
diff --git a/test/test-xmlwriter.vala b/test/test-xmlwriter.vala
index 86fd98a..9a7e1dc 100644
--- a/test/test-xmlwriter.vala
+++ b/test/test-xmlwriter.vala
@@ -1,41 +1,39 @@
-using GLib;
using Gee.XmlEtree;
public class BasicSample : Object {
-
- public void run () {
- ElementTree etree ;
- Element sub_e ;
-
-
- etree = new ElementTree();
- etree.root = new Element("note") ;
-
- // Appending SubElements
- sub_e = new SubElement(etree.root, "to");
- sub_e.text = "Harry" ;
- sub_e.set_attrib("city", "London");
-
- sub_e = new SubElement(etree.root, "from");
- sub_e.text = "John" ;
- sub_e.set_attrib("city", "New York");
-
- sub_e = new SubElement(etree.root, "heading");
- sub_e.text = "Reminder" ;
-
- // Another way to append SubElements
- sub_e = new Element("body");
- sub_e.text = "Don't forget me this weekend!" ;
- etree.append(sub_e);
-
- etree.write("note.xml");
- }
-
- public static int main (string[] args) {
- var sample = new BasicSample ();
-
- sample.run ();
- return 0;
- }
+
+ public void run( ) {
+ ElementTree etree ;
+ Element sub_e ;
+
+
+ etree = new ElementTree( );
+ etree.root = new Element( "note" ) ;
+
+ // Appending SubElements
+ sub_e = new SubElement( etree.root, "to" );
+ sub_e.text = "Harry" ;
+ sub_e.set_attrib( "city", "London" );
+
+ sub_e = new SubElement( etree.root, "from" );
+ sub_e.text = "John" ;
+ sub_e.set_attrib( "city", "New York" );
+
+ sub_e = new SubElement( etree.root, "heading" );
+ sub_e.text = "Reminder" ;
+
+ // Another way to append SubElements
+ sub_e = new Element( "body" );
+ sub_e.text = "Don't forget me this weekend!" ;
+ etree.append( sub_e );
+
+ etree.write( "note.xml" );
+ }
+
+ public static int main( string[] args ) {
+ var sample = new BasicSample( );
+
+ sample.run( );
+ return 0;
+ }
}
-
diff --git a/test/test-xpath.vala b/test/test-xpath.vala
index a48d515..83e9874 100644
--- a/test/test-xpath.vala
+++ b/test/test-xpath.vala
@@ -2,31 +2,31 @@ using GLib;
using Gee.XmlEtree;
public class BasicSample : Object {
-
- public void run () {
- var etree = new ElementTree();
-
- try {
- etree.parse_file("test2.xml");
- }catch (Gee.XmlEtree.Error e){
- stderr.printf ("Oops: %s\n", e.message);
- }
-
- // Finding Elements with Xpath
- //----------------------------
-
- Gee.List<Element> list = etree.find("/addressbook/email") ;
- int i = 1 ;
- foreach (Element e in list) {
- stdout.printf("Email_%i : %s\n", i, e.text);
- i++;
- }
- }
-
- public static int main (string[] args) {
- var sample = new BasicSample ();
-
- sample.run ();
- return 0;
- }
-}
\ No newline at end of file
+
+ public void run( ) {
+ var etree = new ElementTree( );
+
+ try {
+ etree.parse_file( "test2.xml" );
+ }catch( Gee.XmlEtree.Error e ){
+ stderr.printf( "Oops: %s\n", e.message );
+ }
+
+ // Finding Elements with Xpath
+ // ----------------------------
+
+ Gee.List<Element> list = etree.find( "/addressbook/email" ) ;
+ int i = 1 ;
+ foreach( Element e in list ) {
+ stdout.printf( "Email_%i : %s\n", i, e.text );
+ i++;
+ }
+ }
+
+ public static int main( string[] args ) {
+ var sample = new BasicSample( );
+
+ sample.run( );
+ return 0;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]