1 /**
2  * @file    XMLToken.cpp
3  * @brief   A unit of XML syntax, either an XML element or text.
4  * @author  Ben Bornstein
5  *
6  * <!--------------------------------------------------------------------------
7  * This file is part of libSBML.  Please visit http://sbml.org for more
8  * information about SBML, and the latest version of libSBML.
9  *
10  * Copyright (C) 2020 jointly by the following organizations:
11  *     1. California Institute of Technology, Pasadena, CA, USA
12  *     2. University of Heidelberg, Heidelberg, Germany
13  *     3. University College London, London, UK
14  *
15  * Copyright (C) 2019 jointly by the following organizations:
16  *     1. California Institute of Technology, Pasadena, CA, USA
17  *     2. University of Heidelberg, Heidelberg, Germany
18  *
19  * Copyright (C) 2013-2018 jointly by the following organizations:
20  *     1. California Institute of Technology, Pasadena, CA, USA
21  *     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
22  *     3. University of Heidelberg, Heidelberg, Germany
23  *
24  * Copyright (C) 2009-2013 jointly by the following organizations:
25  *     1. California Institute of Technology, Pasadena, CA, USA
26  *     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
27  *
28  * Copyright (C) 2006-2008 by the California Institute of Technology,
29  *     Pasadena, CA, USA
30  *
31  * Copyright (C) 2002-2005 jointly by the following organizations:
32  *     1. California Institute of Technology, Pasadena, CA, USA
33  *     2. Japan Science and Technology Agency, Japan
34  *
35  * This library is free software; you can redistribute it and/or modify it
36  * under the terms of the GNU Lesser General Public License as published by
37  * the Free Software Foundation.  A copy of the license agreement is provided
38  * in the file named "LICENSE.txt" included with this software distribution and
39  * also available online as http://sbml.org/software/libsbml/license.html
40  * ---------------------------------------------------------------------- -->*/
41 
42 #include <sstream>
43 
44 /** @cond doxygenLibsbmlInternal */
45 #include <sbml/xml/XMLOutputStream.h>
46 #include <sbml/util/util.h>
47 #include <sbml/xml/XMLConstructorException.h>
48 /** @endcond */
49 #include <sbml/xml/XMLToken.h>
50 
51 /** @cond doxygenIgnored */
52 using namespace std;
53 /** @endcond */
54 
55 LIBSBML_CPP_NAMESPACE_BEGIN
56 #ifdef __cplusplus
57 
58 /*
59  * Creates a new empty XMLToken.
60  */
XMLToken()61 XMLToken::XMLToken () :
62    mIsStart   ( false )
63  , mIsEnd     ( false )
64  , mIsText    ( false )
65  , mLine      ( 0     )
66  , mColumn    ( 0     )
67 {
68 }
69 
70 
71 /*
72  * Creates a start element XMLToken with the given set of attributes and
73  * namespace declarations.
74  */
XMLToken(const XMLTriple & triple,const XMLAttributes & attributes,const XMLNamespaces & namespaces,const unsigned int line,const unsigned int column)75 XMLToken::XMLToken (  const XMLTriple&      triple
76                     , const XMLAttributes&  attributes
77                     , const XMLNamespaces&  namespaces
78                     , const unsigned int    line
79                     , const unsigned int    column ) :
80    mTriple    ( triple     )
81  , mAttributes( attributes )
82  , mNamespaces( namespaces )
83  , mIsStart   ( true       )
84  , mIsEnd     ( false      )
85  , mIsText    ( false      )
86  , mLine      ( line       )
87  , mColumn    ( column     )
88 {
89 }
90 
91 
92 /*
93  * Creates a start element XMLToken with the given set of attributes.
94  */
XMLToken(const XMLTriple & triple,const XMLAttributes & attributes,const unsigned int line,const unsigned int column)95 XMLToken::XMLToken (  const XMLTriple&      triple
96                     , const XMLAttributes&  attributes
97                     , const unsigned int    line
98                     , const unsigned int    column ) :
99    mTriple    ( triple     )
100  , mAttributes( attributes )
101  , mIsStart   ( true       )
102  , mIsEnd     ( false      )
103  , mIsText    ( false      )
104  , mLine      ( line       )
105  , mColumn    ( column     )
106 {
107 }
108 
109 
110 /*
111  * Creates an end element XMLToken.
112  */
XMLToken(const XMLTriple & triple,const unsigned int line,const unsigned int column)113 XMLToken::XMLToken (  const XMLTriple&    triple
114                     , const unsigned int  line
115                     , const unsigned int  column ) :
116    mTriple    ( triple )
117  , mIsStart   ( false  )
118  , mIsEnd     ( true   )
119  , mIsText    ( false  )
120  , mLine      ( line   )
121  , mColumn    ( column )
122 
123 {
124 }
125 
126 
127 /*
128  * Creates a text XMLToken.
129  */
XMLToken(const std::string & chars,const unsigned int line,const unsigned int column)130 XMLToken::XMLToken (  const std::string&  chars
131                     , const unsigned int  line
132                     , const unsigned int  column )
133  : mChars     ( chars  )
134  , mIsStart   ( false  )
135  , mIsEnd     ( false  )
136  , mIsText    ( true   )
137  , mLine      ( line   )
138  , mColumn    ( column )
139 {
140 }
141 
142 
143 /*
144  * Destroys this XMLToken.
145  */
~XMLToken()146 XMLToken::~XMLToken ()
147 {
148 }
149 
150 
151 /*
152  * Copy constructor; creates a copy of this XMLToken.
153  */
XMLToken(const XMLToken & orig)154 XMLToken::XMLToken(const XMLToken& orig)
155  : mTriple()
156  , mAttributes()
157  , mNamespaces()
158  , mChars (orig.mChars)
159  , mIsStart (orig.mIsStart)
160  , mIsEnd (orig.mIsEnd)
161  , mIsText (orig.mIsText)
162  , mLine (orig.mLine)
163  , mColumn (orig.mColumn)
164 {
165   if (!orig.mTriple.isEmpty())
166     mTriple = XMLTriple(orig.getName(), orig.getURI(), orig.getPrefix());
167 
168   if (!orig.mAttributes.isEmpty())
169     mAttributes = XMLAttributes(orig.getAttributes());
170 
171   if (!orig.mNamespaces.isEmpty())
172     mNamespaces = XMLNamespaces(orig.getNamespaces());
173 
174 }
175 
176 
177 /*
178  * Assignment operator for XMLToken.
179  */
180 XMLToken&
operator =(const XMLToken & rhs)181 XMLToken::operator=(const XMLToken& rhs)
182 {
183   if(&rhs!=this)
184   {
185     if (rhs.mTriple.isEmpty())
186       mTriple = XMLTriple();
187     else
188       mTriple = XMLTriple(rhs.getName(), rhs.getURI(), rhs.getPrefix());
189 
190     if (rhs.mAttributes.isEmpty())
191       mAttributes = XMLAttributes();
192     else
193       mAttributes = XMLAttributes(rhs.getAttributes());
194 
195     if (rhs.mNamespaces.isEmpty())
196       mNamespaces = XMLNamespaces();
197     else
198       mNamespaces = XMLNamespaces(rhs.getNamespaces());
199 
200     mChars = rhs.mChars;
201 
202     mIsStart = rhs.mIsStart;
203     mIsEnd = rhs.mIsEnd;
204     mIsText = rhs.mIsText;
205 
206     mLine = rhs.mLine;
207     mColumn = rhs.mColumn;
208   }
209 
210   return *this;
211 }
212 
213 /*
214  * Creates and returns a deep copy of this XMLToken.
215  *
216  * @return a (deep) copy of this XMLToken set.
217  */
218 XMLToken*
clone() const219 XMLToken::clone () const
220 {
221   return new XMLToken(*this);
222 }
223 
224 
225 /*
226  * Appends characters to this XML text content.
227  */
228 int
append(const std::string & chars)229 XMLToken::append (const std::string& chars)
230 {
231   if (chars.empty())
232   {
233     return LIBSBML_OPERATION_FAILED;
234   }
235   else
236   {
237     mChars.append(chars);
238     return LIBSBML_OPERATION_SUCCESS;
239   }
240 }
241 
242 
243 
244 /*
245  * @return the characters of this XML text.
246  */
247 const string&
getCharacters() const248 XMLToken::getCharacters() const
249 {
250   return mChars;
251 }
252 
253 
254 int
setCharacters(const std::string & chars)255 XMLToken::setCharacters(const std::string& chars)
256 {
257   if (chars.empty())
258   {
259     return LIBSBML_OPERATION_FAILED;
260   }
261   else
262   {
263     mChars = chars;
264     return LIBSBML_OPERATION_SUCCESS;
265   }
266 }
267 
268 /*
269  * @return the column at which this XMLToken occurred.
270  */
271 unsigned int
getColumn() const272 XMLToken::getColumn () const
273 {
274   return mColumn;
275 }
276 
277 
278 /*
279  * @return the line at which this XMLToken occurred.
280  */
281 unsigned int
getLine() const282 XMLToken::getLine () const
283 {
284   return mLine;
285 }
286 
287 
288 /*
289  * @return the XMLAttributes of this XML element.
290  */
291 const XMLAttributes&
getAttributes() const292 XMLToken::getAttributes () const
293 {
294   return mAttributes;
295 }
296 
297 
298 /*
299  * Sets an XMLAttributes to this XMLToken.
300  * Nothing will be done if this XMLToken is not a start element.
301  *
302  * @param attributes XMLAttributes to be set to this XMLToken.
303  *
304  * @note This function replaces the existing XMLAttributes with the new one.
305  */
306 int
setAttributes(const XMLAttributes & attributes)307 XMLToken::setAttributes(const XMLAttributes& attributes)
308 {
309 
310   /* the code will crash if the attributes points to NULL
311    * put in a try catch statement to check
312    */
313   if (mIsStart)
314   {
315     try
316     {
317       mAttributes = attributes;
318       return LIBSBML_OPERATION_SUCCESS;
319     }
320     catch (...)
321     {
322       return LIBSBML_OPERATION_FAILED;
323     }
324   }
325   else
326   {
327     return LIBSBML_INVALID_XML_OPERATION;
328   }
329 }
330 
331 
332 /*
333  * Adds an attribute to the attribute set in this XMLToken optionally
334  * with a prefix and URI defining a namespace.
335  * Nothing will be done if this XMLToken is not a start element.
336  *
337  * @param name a string, the local name of the attribute.
338  * @param value a string, the value of the attribute.
339  * @param namespaceURI a string, the namespace URI of the attribute.
340  * @param prefix a string, the prefix of the namespace.
341  *
342  * @note if local name with the same namespace URI already exists in the
343  * attribute set, its value and prefix will be replaced.
344  *
345  * The native C++ implementation of this method defines a
346  * default argument value.  In the documentation generated for different
347  * libSBML language bindings, you may or may not see corresponding
348  * arguments in the method declarations.  For example, in Java, a default
349  * argument is handled by declaring two separate methods, with one of
350  * them having the argument and the other one lacking the argument.
351  * However, the libSBML documentation will be @em identical for both
352  * methods.  Consequently, if you are reading this and do not see an
353  * argument even though one is described, please look for descriptions of
354  * other variants of this method near where this one appears in the
355  * documentation.
356  */
357 int
addAttr(const std::string & name,const std::string & value,const std::string namespaceURI,const std::string prefix)358 XMLToken::addAttr (  const std::string& name
359                    , const std::string& value
360                    , const std::string namespaceURI
361                    , const std::string prefix      )
362 {
363   if (mIsStart)
364   {
365     return mAttributes.add(name, value, namespaceURI, prefix);
366   }
367   else
368   {
369     return LIBSBML_INVALID_XML_OPERATION;
370   }
371 }
372 
373 
374 /*
375  * Adds an attribute with the given XMLTriple/value pair to the attribute set
376  * in this XMLToken.
377  * Nothing will be done if this XMLToken is not a start element.
378  *
379  * @note if local name with the same namespace URI already exists in the
380  * attribute set, its value and prefix will be replaced.
381  *
382  * @param triple an XMLTriple, the XML triple of the attribute.
383  * @param value a string, the value of the attribute.
384  */
385 int
addAttr(const XMLTriple & triple,const std::string & value)386 XMLToken::addAttr ( const XMLTriple& triple, const std::string& value)
387 {
388   if (mIsStart)
389   {
390     return mAttributes.add(triple, value);
391   }
392   else
393   {
394     return LIBSBML_INVALID_XML_OPERATION;
395   }
396 }
397 
398 
399 /*
400  * Removes an attribute with the given index from the attribute set in
401  * this XMLToken.
402  * Nothing will be done if this XMLToken is not a start element.
403  *
404  * @param n an integer the index of the resource to be deleted.
405  */
406 int
removeAttr(int n)407 XMLToken::removeAttr (int n)
408 {
409   if (mIsStart)
410   {
411     return mAttributes.remove(n);
412   }
413   else
414   {
415     return LIBSBML_INVALID_XML_OPERATION;
416   }
417 }
418 
419 
420 /*
421  * Removes an attribute with the given local name and namespace URI from
422  * the attribute set in this XMLToken.
423  * Nothing will be done if this XMLToken is not a start element.
424  *
425  * @param name   a string, the local name of the attribute.
426  * @param uri    a string, the namespace URI of the attribute.
427  */
428 int
removeAttr(const std::string & name,const std::string uri)429 XMLToken::removeAttr (const std::string& name, const std::string uri)
430 {
431   if (mIsStart)
432   {
433     return mAttributes.remove(name, uri);
434   }
435   else
436   {
437     return LIBSBML_INVALID_XML_OPERATION;
438   }
439 }
440 
441 
442 /*
443  * Removes an attribute with the given XMLTriple from the attribute set
444  * in this XMLToken.
445  * Nothing will be done if this XMLToken is not a start element.
446  *
447  * @param triple an XMLTriple, the XML triple of the attribute.
448  */
449 int
removeAttr(const XMLTriple & triple)450 XMLToken::removeAttr (const XMLTriple& triple)
451 {
452   if (mIsStart)
453   {
454     return mAttributes.remove(triple);
455   }
456   else
457   {
458     return LIBSBML_INVALID_XML_OPERATION;
459   }
460 }
461 
462 
463 /*
464  * Clears (deletes) all attributes in this XMLToken.
465  * Nothing will be done if this XMLToken is not a start element.
466  */
467 int
clearAttributes()468 XMLToken::clearAttributes()
469 {
470   if (mIsStart)
471   {
472     return mAttributes.clear();
473   }
474   else
475   {
476     return LIBSBML_INVALID_XML_OPERATION;
477   }
478 }
479 
480 
481 /*
482  * Return the index of an attribute with the given local name and namespace URI.
483  *
484  * @param name a string, the local name of the attribute.
485  * @param uri  a string, the namespace URI of the attribute.
486  *
487  * @return the index of an attribute with the given local name and namespace URI,
488  * or @c -1 if not present.
489  *
490  * The native C++ implementation of this method defines a
491  * default argument value.  In the documentation generated for different
492  * libSBML language bindings, you may or may not see corresponding
493  * arguments in the method declarations.  For example, in Java, a default
494  * argument is handled by declaring two separate methods, with one of
495  * them having the argument and the other one lacking the argument.
496  * However, the libSBML documentation will be @em identical for both
497  * methods.  Consequently, if you are reading this and do not see an
498  * argument even though one is described, please look for descriptions of
499  * other variants of this method near where this one appears in the
500  * documentation.
501  */
502 int
getAttrIndex(const std::string & name,const std::string uri) const503 XMLToken::getAttrIndex (const std::string& name, const std::string uri) const
504 {
505   return mAttributes.getIndex(name, uri);
506 }
507 
508 
509 /*
510  * Return the index of an attribute with the given XMLTriple.
511  *
512  * @param triple an XMLTriple, the XML triple of the attribute for which
513  *        the index is required.
514  *
515  * @return the index of an attribute with the given XMLTriple, or @c -1 if not present.
516  */
517 int
getAttrIndex(const XMLTriple & triple) const518 XMLToken::getAttrIndex (const XMLTriple& triple) const
519 {
520   return mAttributes.getIndex(triple);
521 }
522 
523 
524 /*
525  * Return the number of attributes in the attributes set.
526  *
527  * @return the number of attributes in the attributes set in this XMLToken.
528  */
529 int
getAttributesLength() const530 XMLToken::getAttributesLength () const
531 {
532   return mAttributes.getLength();
533 }
534 
535 
536 /*
537  * Return the local name of an attribute in the attributes set in this
538  * XMLToken (by position).
539  *
540  * @param index an integer, the position of the attribute whose local name
541  * is required.
542  *
543  * @return the local name of an attribute in this list (by position).
544  *
545  * @note If index
546  * is out of range, an empty string will be returned.  Use hasAttr(index)
547  * to test for the attribute existence.
548  */
549 std::string
getAttrName(int index) const550 XMLToken::getAttrName (int index) const
551 {
552   return mAttributes.getName(index);
553 }
554 
555 
556 /*
557  * Return the prefix of an attribute in the attribute set in this
558  * XMLToken (by position).
559  *
560  * @param index an integer, the position of the attribute whose prefix is
561  * required.
562  *
563  * @return the namespace prefix of an attribute in the attribute set
564  * (by position).
565  *
566  * @note If index is out of range, an empty string will be
567  * returned. Use hasAttr(index) to test for the attribute existence.
568  */
569 std::string
getAttrPrefix(int index) const570 XMLToken::getAttrPrefix (int index) const
571 {
572   return mAttributes.getPrefix(index);
573 }
574 
575 
576 /*
577  * Return the prefixed name of an attribute in the attribute set in this
578  * XMLToken (by position).
579  *
580  * @param index an integer, the position of the attribute whose prefixed
581  * name is required.
582  *
583  * @return the prefixed name of an attribute in the attribute set
584  * (by position).
585  *
586  * @note If index is out of range, an empty string will be
587  * returned.  Use hasAttr(index) to test for attribute existence.
588  */
589 std::string
getAttrPrefixedName(int index) const590 XMLToken::getAttrPrefixedName (int index) const
591 {
592   return mAttributes.getPrefixedName(index);
593 }
594 
595 
596 /*
597  * Return the namespace URI of an attribute in the attribute set in this
598  * XMLToken (by position).
599  *
600  * @param index an integer, the position of the attribute whose namespace
601  * URI is required.
602  *
603  * @return the namespace URI of an attribute in the attribute set (by position).
604  *
605  * @note If index is out of range, an empty string will be returned.  Use
606  * hasAttr(index) to test for attribute existence.
607  */
608 std::string
getAttrURI(int index) const609 XMLToken::getAttrURI (int index) const
610 {
611   return mAttributes.getURI(index);
612 }
613 
614 
615 /*
616  * Return the value of an attribute in the attribute set in this XMLToken
617  * (by position).
618  *
619  * @param index an integer, the position of the attribute whose value is
620  * required.
621  *
622  * @return the value of an attribute in the attribute set (by position).
623  *
624  * @note If index
625  * is out of range, an empty string will be returned. Use hasAttr(index)
626  * to test for attribute existence.
627  */
628 std::string
getAttrValue(int index) const629 XMLToken::getAttrValue (int index) const
630 {
631   return mAttributes.getValue(index);
632 }
633 
634 
635 /*
636  * Return a value of an attribute with the given local name and namespace URI.
637  *
638  * @param name a string, the local name of the attribute whose value is required.
639  * @param uri  a string, the namespace URI of the attribute.
640  *
641  * @return The attribute value as a string.
642  *
643  * @note If an attribute with the
644  * given local name and namespace URI does not exist, an empty string will be
645  * returned.
646  * Use hasAttr(name, uri) to test for attribute existence.
647  *
648  * The native C++ implementation of this method defines a
649  * default argument value.  In the documentation generated for different
650  * libSBML language bindings, you may or may not see corresponding
651  * arguments in the method declarations.  For example, in Java, a default
652  * argument is handled by declaring two separate methods, with one of
653  * them having the argument and the other one lacking the argument.
654  * However, the libSBML documentation will be @em identical for both
655  * methods.  Consequently, if you are reading this and do not see an
656  * argument even though one is described, please look for descriptions of
657  * other variants of this method near where this one appears in the
658  * documentation.
659  */
660 std::string
getAttrValue(const std::string & name,const std::string uri) const661 XMLToken::getAttrValue (const std::string& name, const std::string uri) const
662 {
663   return mAttributes.getValue(name, uri);
664 }
665 
666 
667 /*
668  * Return a value of an attribute with the given XMLTriple.
669  *
670  * @param triple an XMLTriple, the XML triple of the attribute whose
671  *        value is required.
672  *
673  * @return The attribute value as a string.
674  *
675  * @note If an attribute with the
676  * given XMLTriple does not exist, an empty string will be returned.
677  * Use hasAttr(triple) to test for attribute existence.
678  */
679 std::string
getAttrValue(const XMLTriple & triple) const680 XMLToken::getAttrValue (const XMLTriple& triple) const
681 {
682   return mAttributes.getValue(triple);
683 }
684 
685 
686 /*
687  * Predicate returning @c true or @c false depending on whether
688  * an attribute with the given index exists in the attribute set in this
689  * XMLToken.
690  *
691  * @param index an integer, the position of the attribute.
692  *
693  * @return @c true if an attribute with the given index exists in the attribute
694  * set in this XMLToken, @c false otherwise.
695  */
696 bool
hasAttr(int index) const697 XMLToken::hasAttr (int index) const
698 {
699   return mAttributes.hasAttribute(index);
700 }
701 
702 
703 /*
704  * Predicate returning @c true or @c false depending on whether
705  * an attribute with the given local name and namespace URI exists
706  * in the attribute set in this XMLToken.
707  *
708  * @param name a string, the local name of the attribute.
709  * @param uri  a string, the namespace URI of the attribute.
710  *
711  * @return @c true if an attribute with the given local name and namespace
712  * URI exists in the attribute set in this XMLToken, @c false otherwise.
713  *
714  * @if notcpp @htmlinclude warn-default-args-in-docs.html @endif@~
715  */
716 bool
hasAttr(const std::string & name,const std::string uri) const717 XMLToken::hasAttr (const std::string& name, const std::string uri) const
718 {
719   return mAttributes.hasAttribute(name, uri);
720 }
721 
722 
723 /*
724  * Predicate returning @c true or @c false depending on whether
725  * an attribute with the given XML triple exists in the attribute set in
726  * this XMLToken
727  *
728  * @param triple an XMLTriple, the XML triple of the attribute.
729  *
730  * @return @c true if an attribute with the given XML triple exists
731  * in the attribute set in this XMLToken, @c false otherwise.
732  *
733  */
734 bool
hasAttr(const XMLTriple & triple) const735 XMLToken::hasAttr (const XMLTriple& triple) const
736 {
737   return mAttributes.hasAttribute(triple);
738 }
739 
740 
741 /*
742  * Predicate returning @c true or @c false depending on whether
743  * the attribute set in this XMLToken set is empty.
744  *
745  * @return @c true if the attribute set in this XMLToken is empty,
746  * @c false otherwise.
747  */
748 bool
isAttributesEmpty() const749 XMLToken::isAttributesEmpty () const
750 {
751   return mAttributes.isEmpty();
752 }
753 
754 
755 
756 
757 /*
758  * @return the XML namespace declarations for this XML element.
759  */
760 const XMLNamespaces&
getNamespaces() const761 XMLToken::getNamespaces () const
762 {
763   return mNamespaces;
764 }
765 
766 
767 /*
768  * Sets an XMLnamespaces to this XML element.
769  * Nothing will be done if this XMLToken is not a start element.
770  *
771  * @note This function replaces the existing XMLNamespaces with the new one.
772  */
773 int
setNamespaces(const XMLNamespaces & namespaces)774 XMLToken::setNamespaces(const XMLNamespaces& namespaces)
775 {
776 
777   /* the code will crash if the namespaces points to NULL
778    * put in a try catch statement to check
779    */
780   if (mIsStart)
781   {
782     try
783     {
784       mNamespaces = namespaces;
785       return LIBSBML_OPERATION_SUCCESS;
786     }
787     catch (...)
788     {
789       return LIBSBML_OPERATION_FAILED;
790     }
791   }
792   else
793   {
794     return LIBSBML_INVALID_XML_OPERATION;
795   }
796 }
797 
798 
799 /*
800  * Appends an XML namespace prefix and URI pair to this XMLToken.
801  * If there is an XML namespace with the given prefix in this XMLToken,
802  * then the existing XML namespace will be overwritten by the new one.
803  *
804  * Nothing will be done if this XMLToken is not a start element.
805  */
806 int
addNamespace(const std::string & uri,const std::string prefix)807 XMLToken::addNamespace (const std::string& uri, const std::string prefix)
808 {
809 
810    if (mIsStart)
811    {
812      mNamespaces.add(uri, prefix);
813      return LIBSBML_OPERATION_SUCCESS;
814    }
815   else
816   {
817     return LIBSBML_INVALID_XML_OPERATION;
818   }
819 }
820 
821 
822 /*
823  * Removes an XML Namespace stored in the given position of the XMLNamespaces
824  * of this XMLToken.
825  * Nothing will be done if this XMLToken is not a start element.
826  *
827  * @param index an integer, position of the removed namespace.
828  */
829 int
removeNamespace(int index)830 XMLToken::removeNamespace (int index)
831 {
832    if (mIsStart)
833    {
834      return mNamespaces.remove(index);
835    }
836   else
837   {
838     return LIBSBML_INVALID_XML_OPERATION;
839   }
840 }
841 
842 
843 /*
844  * Removes an XML Namespace with the given prefix.
845  * Nothing will be done if this XMLToken is not a start element.
846  *
847  * @param prefix a string, prefix of the required namespace.
848  */
849 int
removeNamespace(const std::string & prefix)850 XMLToken::removeNamespace (const std::string& prefix)
851 {
852   if (mIsStart)
853   {
854     return mNamespaces.remove(prefix);
855   }
856   else
857   {
858     return LIBSBML_INVALID_XML_OPERATION;
859   }
860 }
861 
862 
863 /*
864  * Clears (deletes) all XML namespace declarations in the XMLNamespaces of
865  * this XMLToken.
866  * Nothing will be done if this XMLToken is not a start element.
867  */
868 int
clearNamespaces()869 XMLToken::clearNamespaces ()
870 {
871    if (mIsStart)
872    {
873      return mNamespaces.clear();
874   }
875   else
876   {
877     return LIBSBML_INVALID_XML_OPERATION;
878   }
879 }
880 
881 
882 /*
883  * Look up the index of an XML namespace declaration by URI.
884  *
885  * @param uri a string, uri of the required namespace.
886  *
887  * @return the index of the given declaration, or @c -1 if not present.
888  */
889 int
getNamespaceIndex(const std::string & uri) const890 XMLToken::getNamespaceIndex (const std::string& uri) const
891 {
892   return mNamespaces.getIndex(uri);
893 }
894 
895 
896 /*
897  * Look up the index of an XML namespace declaration by @p prefix.
898  *
899  * @param prefix a string, prefix of the required namespace.
900  *
901  * @return the index of the given declaration, or @c -1 if not present.
902  */
903 int
getNamespaceIndexByPrefix(const std::string & prefix) const904 XMLToken::getNamespaceIndexByPrefix (const std::string& prefix) const
905 {
906   return mNamespaces.getIndexByPrefix(prefix);
907 }
908 
909 
910 /*
911  * Returns the number of XML namespaces stored in the XMLNamespaces
912  * of this XMLToken.
913  *
914  * @return the number of namespaces in this list.
915  */
916 int
getNamespacesLength() const917 XMLToken::getNamespacesLength () const
918 {
919   return mNamespaces.getLength();
920 }
921 
922 
923 /*
924  * Look up the prefix of an XML namespace declaration by position.
925  *
926  * Callers should use getNamespacesLength() to find out how many
927  * namespaces are stored in the XMLNamespaces.
928  *
929  * @return the prefix of an XML namespace declaration in the XMLNamespaces
930  * (by position).
931  */
932 std::string
getNamespacePrefix(int index) const933 XMLToken::getNamespacePrefix (int index) const
934 {
935   return mNamespaces.getPrefix(index);
936 }
937 
938 
939 /*
940  * Look up the prefix of an XML namespace declaration by its URI.
941  *
942  * @return the prefix of an XML namespace declaration given its URI.
943  */
944 std::string
getNamespacePrefix(const std::string & uri) const945 XMLToken::getNamespacePrefix (const std::string& uri) const
946 {
947   return mNamespaces.getPrefix(uri);
948 }
949 
950 
951 /*
952  * Look up the URI of an XML namespace declaration by its position.
953  *
954  * @return the URI of an XML namespace declaration in the XMLNamespaces
955  * (by position).
956  */
957 std::string
getNamespaceURI(int index) const958 XMLToken::getNamespaceURI (int index) const
959 {
960   return mNamespaces.getURI(index);
961 }
962 
963 
964 /*
965  * Look up the URI of an XML namespace declaration by its prefix.
966  *
967  * @return the URI of an XML namespace declaration given its prefix.
968  */
969 std::string
getNamespaceURI(const std::string prefix) const970 XMLToken::getNamespaceURI (const std::string prefix) const
971 {
972   return mNamespaces.getURI(prefix);
973 }
974 
975 
976 /*
977  * Predicate returning @c true or @c false depending on whether
978  * the XMLNamespaces of this XMLToken is empty.
979  *
980  * @return @c true if the XMLNamespaces of this XMLToken is empty,
981  * @c false otherwise.
982  */
983 bool
isNamespacesEmpty() const984 XMLToken::isNamespacesEmpty () const
985 {
986   return mNamespaces.isEmpty();
987 }
988 
989 
990 /*
991  * Predicate returning @c true or @c false depending on whether
992  * an XML Namespace with the given URI is contained in the XMLNamespaces of
993  * this XMLToken.
994  *
995  * @return @c true if an XML Namespace with the given URI is contained in the
996  * XMLNamespaces of this XMLToken,  @c false otherwise.
997  */
998 bool
hasNamespaceURI(const std::string & uri) const999 XMLToken::hasNamespaceURI(const std::string& uri) const
1000 {
1001   return mNamespaces.hasURI(uri);
1002 }
1003 
1004 
1005 /*
1006  * Predicate returning @c true or @c false depending on whether
1007  * an XML Namespace with the given prefix is contained in the XMLNamespaces of
1008  * this XMLToken.
1009  *
1010  * @param prefix a string, the prefix for the namespace.
1011  *
1012  * @return @c true if an XML Namespace with the given URI is contained in the
1013  * XMLNamespaces of this XMLToken, @c false otherwise.
1014  */
1015 bool
hasNamespacePrefix(const std::string & prefix) const1016 XMLToken::hasNamespacePrefix(const std::string& prefix) const
1017 {
1018   return mNamespaces.hasPrefix(prefix);
1019 }
1020 
1021 
1022 /*
1023  * Predicate returning @c true or @c false depending on whether
1024  * an XML Namespace with the given uri/prefix pair is contained in the
1025  * XMLNamespaces ofthis XMLToken.
1026  *
1027  * @param uri a string, the uri for the namespace.
1028  * @param prefix a string, the prefix for the namespace.
1029  *
1030  * @return @c true if an XML Namespace with the given uri/prefix pair is
1031  * contained in the XMLNamespaces of this XMLToken,  @c false otherwise.
1032  */
1033 bool
hasNamespaceNS(const std::string & uri,const std::string & prefix) const1034 XMLToken::hasNamespaceNS(const std::string& uri, const std::string& prefix) const
1035 {
1036   return mNamespaces.hasNS(uri,prefix);
1037 }
1038 
1039 
1040 /*
1041  * Sets the XMLTripe (name, uri and prefix) of this XML element.
1042  * Nothing will be done if this XML element is a text node.
1043  */
1044 int
setTriple(const XMLTriple & triple)1045 XMLToken::setTriple(const XMLTriple& triple)
1046 {
1047 
1048   /* the code will crash if the triple points to NULL
1049    * put in a try catch statement to check
1050    */
1051   if (! mIsText )
1052   {
1053     try
1054     {
1055       mTriple = triple;
1056       return LIBSBML_OPERATION_SUCCESS;
1057     }
1058     catch (...)
1059     {
1060       return LIBSBML_OPERATION_FAILED;
1061     }
1062   }
1063   else
1064   {
1065     return LIBSBML_INVALID_XML_OPERATION;
1066   }
1067 
1068 }
1069 
1070 
1071 /*
1072  * @return the (unqualified) name of this XML element.
1073  */
1074 const string&
getName() const1075 XMLToken::getName () const
1076 {
1077   return mTriple.getName();
1078 }
1079 
1080 
1081 /*
1082  * @return the namespace prefix of this XML element.  If no prefix
1083  * exists, an empty string will be return.
1084  */
1085 const string&
getPrefix() const1086 XMLToken::getPrefix () const
1087 {
1088   return mTriple.getPrefix();
1089 }
1090 
1091 
1092 /*
1093  * @return the namespace URI of this XML element.
1094  */
1095 const string&
getURI() const1096 XMLToken::getURI () const
1097 {
1098   return mTriple.getURI();
1099 }
1100 
1101 
1102 
1103 /*
1104  * @return @c true if this XMLToken is an XML element.
1105  */
1106 bool
isElement() const1107 XMLToken::isElement () const
1108 {
1109   return mIsStart || mIsEnd;
1110 }
1111 
1112 
1113 /*
1114  * @return @c true if this XMLToken is an XML end element, false
1115  * otherwise.
1116  */
1117 bool
isEnd() const1118 XMLToken::isEnd () const
1119 {
1120   return mIsEnd;
1121 }
1122 
1123 
1124 /*
1125  * @return @c true if this XMLToken is an XML end element for the given XML
1126  * start element, false otherwise.
1127  */
1128 bool
isEndFor(const XMLToken & element) const1129 XMLToken::isEndFor (const XMLToken& element) const
1130 {
1131   return
1132     isEnd()                        &&
1133     !isStart()                     &&
1134     element.isStart()              &&
1135     element.getName() == getName() &&
1136     element.getURI () == getURI ();
1137 }
1138 
1139 
1140 /*
1141  * @return @c true if this XMLToken is an end of file (input) marker, false
1142  * otherwise.
1143  */
1144 bool
isEOF() const1145 XMLToken::isEOF () const
1146 {
1147   return (mIsStart == false && mIsEnd == false && mIsText == false);
1148 }
1149 
1150 
1151 /*
1152  * @return @c true if this XMLToken is an XML start element, false
1153  * otherwise.
1154  */
1155 bool
isStart() const1156 XMLToken::isStart () const
1157 {
1158   return mIsStart;
1159 }
1160 
1161 
1162 /*
1163  * @return @c true if this XMLToken is text, false otherwise.
1164  */
1165 bool
isText() const1166 XMLToken::isText () const
1167 {
1168   return mIsText;
1169 }
1170 
1171 
1172 /*
1173  * Declares this XML start element is also an end element.
1174  */
1175 int
setEnd()1176 XMLToken::setEnd ()
1177 {
1178   mIsEnd = true;
1179   if (isEnd())
1180     return LIBSBML_OPERATION_SUCCESS;
1181   else
1182     return LIBSBML_OPERATION_FAILED;
1183 }
1184 
1185 
1186 /*
1187  * Declares this XML start/end element is no longer an end element.
1188  */
1189 int
unsetEnd()1190 XMLToken::unsetEnd ()
1191 {
1192   mIsEnd = false;
1193   if (!isEnd())
1194     return LIBSBML_OPERATION_SUCCESS;
1195   else
1196     return LIBSBML_OPERATION_FAILED;
1197 }
1198 
1199 
1200 /*
1201  * Declares this XMLToken is an end-of-file (input) marker.
1202  */
1203 int
setEOF()1204 XMLToken::setEOF ()
1205 {
1206   mIsStart = false;
1207   mIsEnd   = false;
1208   mIsText  = false;
1209 
1210   if (isEOF())
1211     return LIBSBML_OPERATION_SUCCESS;
1212   else
1213     return LIBSBML_OPERATION_FAILED;
1214 }
1215 
1216 
1217 /** @cond doxygenLibsbmlInternal */
1218 /*
1219  * Writes this XMLToken to stream.
1220  */
1221 void
write(XMLOutputStream & stream) const1222 XMLToken::write (XMLOutputStream& stream) const
1223 {
1224   if ( isEOF () ) return;
1225 
1226   if ( isText() )
1227   {
1228     stream << getCharacters();
1229     return;
1230   }
1231 
1232   if ( isStart() ) stream.startElement( mTriple );
1233   if ( isStart() ) stream << mNamespaces << mAttributes;
1234   if ( isEnd()   ) stream.endElement( mTriple );
1235 }
1236 /** @endcond */
1237 
1238 
1239 /*
1240  * Prints a string representation of the underlying token stream, for
1241  * debugging purposes.
1242  */
1243 string
toString()1244 XMLToken::toString ()
1245 {
1246   ostringstream stream;
1247 
1248   if ( isText() )
1249   {
1250     stream << getCharacters();
1251   }
1252   else
1253   {
1254     stream << '<';
1255     if ( !isStart() && isEnd() ) stream << '/';
1256 
1257     stream << getName();
1258 
1259     if (  isStart() && isEnd() ) stream << '/';
1260     stream << '>';
1261   }
1262 
1263   return stream.str();
1264 }
1265 
1266 
1267 /** @cond doxygenLibsbmlInternal */
1268 /*
1269  * Inserts this XMLToken into stream.
1270  */
1271 LIBLAX_EXTERN
1272 XMLOutputStream&
operator <<(XMLOutputStream & stream,const XMLToken & token)1273 operator<< (XMLOutputStream& stream, const XMLToken& token)
1274 {
1275   token.write(stream);
1276   return stream;
1277 }
1278 /** @endcond */
1279 
1280 
1281 #endif /* __cplusplus */
1282 /** @cond doxygenIgnored */
1283 LIBLAX_EXTERN
1284 XMLToken_t *
XMLToken_create(void)1285 XMLToken_create (void)
1286 {
1287   return new(nothrow) XMLToken;
1288 }
1289 
1290 
1291 LIBLAX_EXTERN
1292 XMLToken_t *
XMLToken_createWithTriple(const XMLTriple_t * triple)1293 XMLToken_createWithTriple (const XMLTriple_t *triple)
1294 {
1295   if (triple == NULL) return NULL;
1296   return new(nothrow) XMLToken(*triple);
1297 }
1298 
1299 
1300 LIBLAX_EXTERN
1301 XMLToken_t *
XMLToken_createWithTripleAttr(const XMLTriple_t * triple,const XMLAttributes_t * attr)1302 XMLToken_createWithTripleAttr (const XMLTriple_t *triple,
1303              const XMLAttributes_t *attr)
1304 {
1305   if (triple == NULL || attr == NULL) return NULL;
1306   return new(nothrow) XMLToken(*triple, *attr);
1307 }
1308 
1309 
1310 LIBLAX_EXTERN
1311 XMLToken_t *
XMLToken_createWithTripleAttrNS(const XMLTriple_t * triple,const XMLAttributes_t * attr,const XMLNamespaces_t * ns)1312 XMLToken_createWithTripleAttrNS (const XMLTriple_t *triple,
1313          const XMLAttributes_t *attr,
1314          const XMLNamespaces_t *ns)
1315 {
1316   if (triple == NULL || attr == NULL || ns == NULL) return NULL;
1317   return new(nothrow) XMLToken(*triple, *attr, *ns);
1318 }
1319 
1320 
1321 LIBLAX_EXTERN
1322 XMLToken_t *
XMLToken_createWithText(const char * text)1323 XMLToken_createWithText (const char *text)
1324 {
1325   return (text != NULL) ? new(nothrow) XMLToken(text) : new(nothrow) XMLToken;
1326 }
1327 
1328 LIBLAX_EXTERN
1329 void
XMLToken_free(XMLToken_t * token)1330 XMLToken_free (XMLToken_t *token)
1331 {
1332   if (token == NULL) return;
1333   delete static_cast<XMLToken*>( token );
1334 }
1335 
1336 
1337 LIBLAX_EXTERN
1338 XMLToken_t *
XMLToken_clone(const XMLToken_t * t)1339 XMLToken_clone (const XMLToken_t* t)
1340 {
1341   if (t == NULL) return NULL;
1342   return static_cast<XMLToken*>( t->clone() );
1343 }
1344 
1345 
1346 LIBLAX_EXTERN
1347 int
XMLToken_append(XMLToken_t * token,const char * text)1348 XMLToken_append (XMLToken_t *token, const char *text)
1349 {
1350   if (token != NULL && text != NULL)
1351   {
1352     return token->append(text);
1353   }
1354   else
1355   {
1356     return LIBSBML_OPERATION_FAILED;
1357   }
1358 }
1359 
1360 LIBLAX_EXTERN
1361 int
XMLToken_setCharacters(XMLToken_t * token,const char * text)1362 XMLToken_setCharacters(XMLToken_t *token, const char *text)
1363 {
1364   if (token != NULL && text != NULL)
1365   {
1366     return token->setCharacters(text);
1367   }
1368   else
1369   {
1370     return LIBSBML_OPERATION_FAILED;
1371   }
1372 }
1373 
1374 
1375 
1376 LIBLAX_EXTERN
1377 const char *
XMLToken_getCharacters(const XMLToken_t * token)1378 XMLToken_getCharacters (const XMLToken_t *token)
1379 {
1380   if (token == NULL) return NULL;
1381   return token->getCharacters().empty() ? NULL : token->getCharacters().c_str();
1382 }
1383 
1384 
1385 LIBLAX_EXTERN
1386 unsigned int
XMLToken_getColumn(const XMLToken_t * token)1387 XMLToken_getColumn (const XMLToken_t *token)
1388 {
1389   if (token == NULL) return 0;
1390   return token->getColumn();
1391 }
1392 
1393 
1394 LIBLAX_EXTERN
1395 unsigned int
XMLToken_getLine(const XMLToken_t * token)1396 XMLToken_getLine (const XMLToken_t *token)
1397 {
1398   if (token == NULL) return 0;
1399   return token->getLine();
1400 }
1401 
1402 
1403 
1404 LIBLAX_EXTERN
1405 const XMLAttributes_t *
XMLToken_getAttributes(const XMLToken_t * token)1406 XMLToken_getAttributes (const XMLToken_t *token)
1407 {
1408   if (token == NULL) return NULL;
1409   return &(token->getAttributes());
1410 }
1411 
1412 
1413 LIBLAX_EXTERN
1414 int
XMLToken_setAttributes(XMLToken_t * token,const XMLAttributes_t * attributes)1415 XMLToken_setAttributes(XMLToken_t *token, const XMLAttributes_t* attributes)
1416 {
1417   if (token == NULL || attributes == NULL) return LIBSBML_INVALID_OBJECT;
1418   return token->setAttributes(*attributes);
1419 }
1420 
1421 
1422 LIBLAX_EXTERN
1423 int
XMLToken_addAttr(XMLToken_t * token,const char * name,const char * value)1424 XMLToken_addAttr ( XMLToken_t *token,  const char* name, const char* value )
1425 {
1426   if (token == NULL) return LIBSBML_INVALID_OBJECT;
1427   return token->addAttr(name, value, "", "");
1428 }
1429 
1430 
1431 LIBLAX_EXTERN
1432 int
XMLToken_addAttrWithNS(XMLToken_t * token,const char * name,const char * value,const char * namespaceURI,const char * prefix)1433 XMLToken_addAttrWithNS ( XMLToken_t *token,  const char* name
1434                   , const char* value
1435                       , const char* namespaceURI
1436                   , const char* prefix      )
1437 {
1438   if (token == NULL) return LIBSBML_INVALID_OBJECT;
1439   return token->addAttr(name, value, namespaceURI, prefix);
1440 }
1441 
1442 
1443 
1444 LIBLAX_EXTERN
1445 int
XMLToken_addAttrWithTriple(XMLToken_t * token,const XMLTriple_t * triple,const char * value)1446 XMLToken_addAttrWithTriple (XMLToken_t *token, const XMLTriple_t *triple, const char* value)
1447 {
1448   if (token == NULL || triple == NULL) return LIBSBML_INVALID_OBJECT;
1449   return token->addAttr(*triple, value);
1450 }
1451 
1452 
1453 LIBLAX_EXTERN
1454 int
XMLToken_removeAttr(XMLToken_t * token,int n)1455 XMLToken_removeAttr (XMLToken_t *token, int n)
1456 {
1457   if (token == NULL) return LIBSBML_INVALID_OBJECT;
1458   return token->removeAttr(n);
1459 }
1460 
1461 
1462 LIBLAX_EXTERN
1463 int
XMLToken_removeAttrByName(XMLToken_t * token,const char * name)1464 XMLToken_removeAttrByName (XMLToken_t *token, const char* name)
1465 {
1466   if (token == NULL) return LIBSBML_INVALID_OBJECT;
1467   return token->removeAttr(name, "");
1468 }
1469 
1470 
1471 LIBLAX_EXTERN
1472 int
XMLToken_removeAttrByNS(XMLToken_t * token,const char * name,const char * uri)1473 XMLToken_removeAttrByNS (XMLToken_t *token, const char* name, const char* uri)
1474 {
1475   if (token == NULL) return LIBSBML_INVALID_OBJECT;
1476   return token->removeAttr(name, uri);
1477 }
1478 
1479 
1480 LIBLAX_EXTERN
1481 int
XMLToken_removeAttrByTriple(XMLToken_t * token,const XMLTriple_t * triple)1482 XMLToken_removeAttrByTriple (XMLToken_t *token, const XMLTriple_t *triple)
1483 {
1484   if (token == NULL) return LIBSBML_INVALID_OBJECT;
1485   return token->removeAttr(*triple);
1486 }
1487 
1488 
1489 LIBLAX_EXTERN
1490 int
XMLToken_clearAttributes(XMLToken_t * token)1491 XMLToken_clearAttributes(XMLToken_t *token)
1492 {
1493   if (token == NULL) return LIBSBML_INVALID_OBJECT;
1494   return token->clearAttributes();
1495 }
1496 
1497 
1498 
1499 LIBLAX_EXTERN
1500 int
XMLToken_getAttrIndex(const XMLToken_t * token,const char * name,const char * uri)1501 XMLToken_getAttrIndex (const XMLToken_t *token, const char* name, const char* uri)
1502 {
1503   if (token == NULL) return -1;
1504   return token->getAttrIndex(name, uri);
1505 }
1506 
1507 
1508 LIBLAX_EXTERN
1509 int
XMLToken_getAttrIndexByTriple(const XMLToken_t * token,const XMLTriple_t * triple)1510 XMLToken_getAttrIndexByTriple (const XMLToken_t *token, const XMLTriple_t *triple)
1511 {
1512   if (token == NULL || triple == NULL) return -1;
1513   return token->getAttrIndex(*triple);
1514 }
1515 
1516 
1517 LIBLAX_EXTERN
1518 int
XMLToken_getAttributesLength(const XMLToken_t * token)1519 XMLToken_getAttributesLength (const XMLToken_t *token)
1520 {
1521   if (token == NULL) return 0;
1522   return token->getAttributesLength();
1523 }
1524 
1525 
1526 LIBLAX_EXTERN
1527 char*
XMLToken_getAttrName(const XMLToken_t * token,int index)1528 XMLToken_getAttrName (const XMLToken_t *token, int index)
1529 {
1530   if (token == NULL) return NULL;
1531   const std::string str = token->getAttrName(index);
1532 
1533   return str.empty() ? NULL : safe_strdup(str.c_str());
1534 }
1535 
1536 
1537 LIBLAX_EXTERN
1538 char*
XMLToken_getAttrPrefix(const XMLToken_t * token,int index)1539 XMLToken_getAttrPrefix (const XMLToken_t *token, int index)
1540 {
1541   if (token == NULL) return NULL;
1542   const std::string str = token->getAttrPrefix(index);
1543 
1544   return str.empty() ? NULL : safe_strdup(str.c_str());
1545 }
1546 
1547 
1548 LIBLAX_EXTERN
1549 char*
XMLToken_getAttrPrefixedName(const XMLToken_t * token,int index)1550 XMLToken_getAttrPrefixedName (const XMLToken_t *token, int index)
1551 {
1552   if (token == NULL) return NULL;
1553   const std::string str = token->getAttrPrefixedName(index);
1554 
1555   return str.empty() ? NULL : safe_strdup(str.c_str());
1556 }
1557 
1558 
1559 LIBLAX_EXTERN
1560 char*
XMLToken_getAttrURI(const XMLToken_t * token,int index)1561 XMLToken_getAttrURI (const XMLToken_t *token, int index)
1562 {
1563   if (token == NULL) return NULL;
1564   const std::string str = token->getAttrURI(index);
1565 
1566   return str.empty() ? NULL : safe_strdup(str.c_str());
1567 }
1568 
1569 
1570 LIBLAX_EXTERN
1571 char*
XMLToken_getAttrValue(const XMLToken_t * token,int index)1572 XMLToken_getAttrValue (const XMLToken_t *token, int index)
1573 {
1574   if (token == NULL) return NULL;
1575   const std::string str = token->getAttrValue(index);
1576 
1577   return str.empty() ? NULL : safe_strdup(str.c_str());
1578 }
1579 
1580 
1581 LIBLAX_EXTERN
1582 char*
XMLToken_getAttrValueByName(const XMLToken_t * token,const char * name)1583 XMLToken_getAttrValueByName (const XMLToken_t *token, const char* name)
1584 {
1585   if (token == NULL) return NULL;
1586   const std::string str = token->getAttrValue(name, "");
1587 
1588   return str.empty() ? NULL : safe_strdup(str.c_str());
1589 }
1590 
1591 
1592 LIBLAX_EXTERN
1593 char*
XMLToken_getAttrValueByNS(const XMLToken_t * token,const char * name,const char * uri)1594 XMLToken_getAttrValueByNS (const XMLToken_t *token, const char* name, const char* uri)
1595 {
1596   if (token == NULL) return NULL;
1597   const std::string str = token->getAttrValue(name, uri);
1598 
1599   return str.empty() ? NULL : safe_strdup(str.c_str());
1600 }
1601 
1602 
1603 LIBLAX_EXTERN
1604 char*
XMLToken_getAttrValueByTriple(const XMLToken_t * token,const XMLTriple_t * triple)1605 XMLToken_getAttrValueByTriple (const XMLToken_t *token, const XMLTriple_t *triple)
1606 {
1607   if (token == NULL || triple == NULL) return NULL;
1608   const std::string str = token->getAttrValue(*triple);
1609 
1610   return str.empty() ? NULL : safe_strdup(str.c_str());
1611 }
1612 
1613 
1614 LIBLAX_EXTERN
1615 int
XMLToken_hasAttr(const XMLToken_t * token,int index)1616 XMLToken_hasAttr (const XMLToken_t *token, int index)
1617 {
1618   if (token == NULL) return (int) false;
1619   return token->hasAttr(index);
1620 }
1621 
1622 
1623 LIBLAX_EXTERN
1624 int
XMLToken_hasAttrWithName(const XMLToken_t * token,const char * name)1625 XMLToken_hasAttrWithName (const XMLToken_t *token, const char* name)
1626 {
1627   if (token == NULL) return (int) false;
1628   return token->hasAttr(name, "");
1629 }
1630 
1631 
1632 LIBLAX_EXTERN
1633 int
XMLToken_hasAttrWithNS(const XMLToken_t * token,const char * name,const char * uri)1634 XMLToken_hasAttrWithNS (const XMLToken_t *token, const char* name, const char* uri)
1635 {
1636   if (token == NULL) return (int) false;
1637   return token->hasAttr(name, uri);
1638 }
1639 
1640 
1641 LIBLAX_EXTERN
1642 int
XMLToken_hasAttrWithTriple(const XMLToken_t * token,const XMLTriple_t * triple)1643 XMLToken_hasAttrWithTriple (const XMLToken_t *token, const XMLTriple_t *triple)
1644 {
1645   if (token == NULL || triple == NULL) return (int) false;
1646   return token->hasAttr(*triple);
1647 }
1648 
1649 
1650 LIBLAX_EXTERN
1651 int
XMLToken_isAttributesEmpty(const XMLToken_t * token)1652 XMLToken_isAttributesEmpty (const XMLToken_t *token)
1653 {
1654   if (token == NULL) return (int) false;
1655   return token->isAttributesEmpty();
1656 }
1657 
1658 
1659 
1660 LIBLAX_EXTERN
1661 const XMLNamespaces_t *
XMLToken_getNamespaces(const XMLToken_t * token)1662 XMLToken_getNamespaces (const XMLToken_t *token)
1663 {
1664   if (token == NULL) return NULL;
1665   return &(token->getNamespaces());
1666 }
1667 
1668 
1669 LIBLAX_EXTERN
1670 int
XMLToken_setNamespaces(XMLToken_t * token,const XMLNamespaces_t * namespaces)1671 XMLToken_setNamespaces(XMLToken_t *token, const XMLNamespaces_t* namespaces)
1672 {
1673   if (token == NULL || namespaces == NULL) return LIBSBML_INVALID_OBJECT;
1674   return token->setNamespaces(*namespaces);
1675 }
1676 
1677 
1678 LIBLAX_EXTERN
1679 int
XMLToken_addNamespace(XMLToken_t * token,const char * uri,const char * prefix)1680 XMLToken_addNamespace (XMLToken_t *token, const char* uri, const char* prefix)
1681 {
1682   if (token == NULL) return LIBSBML_INVALID_OBJECT;
1683   return token->addNamespace(uri, prefix);
1684 }
1685 
1686 
1687 LIBLAX_EXTERN
1688 int
XMLToken_removeNamespace(XMLToken_t * token,int index)1689 XMLToken_removeNamespace (XMLToken_t *token, int index)
1690 {
1691   if (token == NULL) return LIBSBML_INVALID_OBJECT;
1692   return token->removeNamespace(index);
1693 }
1694 
1695 
1696 LIBLAX_EXTERN
1697 int
XMLToken_removeNamespaceByPrefix(XMLToken_t * token,const char * prefix)1698 XMLToken_removeNamespaceByPrefix (XMLToken_t *token, const char* prefix)
1699 {
1700   if (token == NULL) return LIBSBML_INVALID_OBJECT;
1701   return token->removeNamespace(prefix);
1702 }
1703 
1704 
1705 LIBLAX_EXTERN
1706 int
XMLToken_clearNamespaces(XMLToken_t * token)1707 XMLToken_clearNamespaces (XMLToken_t *token)
1708 {
1709   if (token == NULL) return LIBSBML_INVALID_OBJECT;
1710   return token->clearNamespaces();
1711 }
1712 
1713 
1714 LIBLAX_EXTERN
1715 int
XMLToken_getNamespaceIndex(const XMLToken_t * token,const char * uri)1716 XMLToken_getNamespaceIndex (const XMLToken_t *token, const char* uri)
1717 {
1718   if (token == NULL) return -1;
1719   return token->getNamespaceIndex(uri);
1720 }
1721 
1722 
1723 LIBLAX_EXTERN
1724 int
XMLToken_getNamespaceIndexByPrefix(const XMLToken_t * token,const char * prefix)1725 XMLToken_getNamespaceIndexByPrefix (const XMLToken_t *token, const char* prefix)
1726 {
1727   if (token == NULL) return -1;
1728   return token->getNamespaceIndexByPrefix(prefix);
1729 }
1730 
1731 
1732 LIBLAX_EXTERN
1733 int
XMLToken_getNamespacesLength(const XMLToken_t * token)1734 XMLToken_getNamespacesLength (const XMLToken_t *token)
1735 {
1736   if (token == NULL) return 0;
1737   return token->getNamespacesLength();
1738 }
1739 
1740 
1741 LIBLAX_EXTERN
1742 char*
XMLToken_getNamespacePrefix(const XMLToken_t * token,int index)1743 XMLToken_getNamespacePrefix (const XMLToken_t *token, int index)
1744 {
1745   if (token == NULL) return NULL;
1746   const std::string str = token->getNamespacePrefix(index);
1747 
1748   return str.empty() ? NULL : safe_strdup(str.c_str());
1749 }
1750 
1751 
1752 LIBLAX_EXTERN
1753 char*
XMLToken_getNamespacePrefixByURI(const XMLToken_t * token,const char * uri)1754 XMLToken_getNamespacePrefixByURI (const XMLToken_t *token, const char* uri)
1755 {
1756   if (token == NULL) return NULL;
1757   const std::string str = token->getNamespacePrefix(uri);
1758 
1759   return str.empty() ? NULL : safe_strdup(str.c_str());
1760 }
1761 
1762 
1763 LIBLAX_EXTERN
1764 char*
XMLToken_getNamespaceURI(const XMLToken_t * token,int index)1765 XMLToken_getNamespaceURI (const XMLToken_t *token, int index)
1766 {
1767   if (token == NULL) return NULL;
1768   const std::string str = token->getNamespaceURI(index);
1769 
1770   return str.empty() ? NULL : safe_strdup(str.c_str());
1771 }
1772 
1773 
1774 LIBLAX_EXTERN
1775 char*
XMLToken_getNamespaceURIByPrefix(const XMLToken_t * token,const char * prefix)1776 XMLToken_getNamespaceURIByPrefix (const XMLToken_t *token, const char* prefix)
1777 {
1778   if (token == NULL) return NULL;
1779   const std::string str = token->getNamespaceURI(prefix);
1780 
1781   return str.empty() ? NULL : safe_strdup(str.c_str());
1782 }
1783 
1784 
1785 LIBLAX_EXTERN
1786 int
XMLToken_isNamespacesEmpty(const XMLToken_t * token)1787 XMLToken_isNamespacesEmpty (const XMLToken_t *token)
1788 {
1789   if (token == NULL) return (int) false;
1790    return static_cast<int>(token->isNamespacesEmpty());
1791 }
1792 
1793 
1794 LIBLAX_EXTERN
1795 int
XMLToken_hasNamespaceURI(const XMLToken_t * token,const char * uri)1796 XMLToken_hasNamespaceURI(const XMLToken_t *token, const char* uri)
1797 {
1798   if (token == NULL) return (int)false;
1799   return static_cast<int>(token->hasNamespaceURI(uri));
1800 }
1801 
1802 
1803 LIBLAX_EXTERN
1804 int
XMLToken_hasNamespacePrefix(const XMLToken_t * token,const char * prefix)1805 XMLToken_hasNamespacePrefix(const XMLToken_t *token, const char* prefix)
1806 {
1807   if (token == NULL) return (int)false;
1808   return static_cast<int>(token->hasNamespacePrefix(prefix));
1809 }
1810 
1811 
1812 LIBLAX_EXTERN
1813 int
XMLToken_hasNamespaceNS(const XMLToken_t * token,const char * uri,const char * prefix)1814 XMLToken_hasNamespaceNS(const XMLToken_t *token, const char* uri, const char* prefix)
1815 {
1816   if (token == NULL) return (int) false;
1817   return static_cast<int>(token->hasNamespaceNS(uri, prefix));
1818 }
1819 
1820 
1821 LIBLAX_EXTERN
1822 int
XMLToken_setTriple(XMLToken_t * token,const XMLTriple_t * triple)1823 XMLToken_setTriple(XMLToken_t *token, const XMLTriple_t *triple)
1824 {
1825   if (token == NULL || triple == NULL) return LIBSBML_INVALID_OBJECT;
1826   return token->setTriple(*triple);
1827 }
1828 
1829 
1830 LIBLAX_EXTERN
1831 const char *
XMLToken_getName(const XMLToken_t * token)1832 XMLToken_getName (const XMLToken_t *token)
1833 {
1834   if (token == NULL) return NULL;
1835   return token->getName().empty() ? NULL : token->getName().c_str();
1836 }
1837 
1838 
1839 LIBLAX_EXTERN
1840 const char *
XMLToken_getPrefix(const XMLToken_t * token)1841 XMLToken_getPrefix (const XMLToken_t *token)
1842 {
1843   if (token == NULL) return NULL;
1844   return token->getPrefix().empty() ? NULL : token->getPrefix().c_str();
1845 }
1846 
1847 
1848 LIBLAX_EXTERN
1849 const char *
XMLToken_getURI(const XMLToken_t * token)1850 XMLToken_getURI (const XMLToken_t *token)
1851 {
1852   if (token == NULL) return NULL;
1853   return token->getURI().empty() ? NULL : token->getURI().c_str();
1854 }
1855 
1856 
1857 LIBLAX_EXTERN
1858 int
XMLToken_isElement(const XMLToken_t * token)1859 XMLToken_isElement (const XMLToken_t *token)
1860 {
1861   if (token == NULL) return (int)false;
1862   return static_cast<int>( token->isElement() );
1863 }
1864 
1865 
1866 LIBLAX_EXTERN
1867 int
XMLToken_isEnd(const XMLToken_t * token)1868 XMLToken_isEnd (const XMLToken_t *token)
1869 {
1870   if (token == NULL) return (int)false;
1871   return static_cast<int>( token->isEnd() );
1872 }
1873 
1874 
1875 LIBLAX_EXTERN
1876 int
XMLToken_isEndFor(const XMLToken_t * token,const XMLToken_t * element)1877 XMLToken_isEndFor (const XMLToken_t *token, const XMLToken_t *element)
1878 {
1879   if (token == NULL || element== NULL) return (int)false;
1880   return static_cast<int>( token->isEndFor(*element) );
1881 }
1882 
1883 
1884 LIBLAX_EXTERN
1885 int
XMLToken_isEOF(const XMLToken_t * token)1886 XMLToken_isEOF (const XMLToken_t *token)
1887 {
1888   if (token == NULL) return (int) false;
1889   return static_cast<int>( token->isEOF() );
1890 }
1891 
1892 
1893 LIBLAX_EXTERN
1894 int
XMLToken_isStart(const XMLToken_t * token)1895 XMLToken_isStart (const XMLToken_t *token)
1896 {
1897   if (token == NULL) return (int) false;
1898   return static_cast<int>( token->isStart() );
1899 }
1900 
1901 
1902 LIBLAX_EXTERN
1903 int
XMLToken_isText(const XMLToken_t * token)1904 XMLToken_isText (const XMLToken_t *token)
1905 {
1906   if (token == NULL) return (int) false;
1907   return static_cast<int>( token->isText() );
1908 }
1909 
1910 
1911 LIBLAX_EXTERN
1912 int
XMLToken_setEnd(XMLToken_t * token)1913 XMLToken_setEnd (XMLToken_t *token)
1914 {
1915   if (token == NULL) return LIBSBML_INVALID_OBJECT;
1916   return token->setEnd();
1917 }
1918 
1919 
1920 LIBLAX_EXTERN
1921 int
XMLToken_setEOF(XMLToken_t * token)1922 XMLToken_setEOF (XMLToken_t *token)
1923 {
1924   if (token == NULL) return LIBSBML_INVALID_OBJECT;
1925   return token->setEOF();
1926 }
1927 
1928 
1929 LIBLAX_EXTERN
1930 int
XMLToken_unsetEnd(XMLToken_t * token)1931 XMLToken_unsetEnd (XMLToken_t *token)
1932 {
1933   if (token == NULL) return LIBSBML_INVALID_OBJECT;
1934   return token->unsetEnd();
1935 }
1936 /** @endcond */
1937 
1938 LIBSBML_CPP_NAMESPACE_END
1939 
1940