1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
|
/*
Copyright (C) 2000-2007
Code contributed by Greg Collecutt, Joseph Hope, Andrew Reid and Paul Cochrane
This file is part of xmds.
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 the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
$Id: xml_basics.h 1595 2007-11-17 13:41:07Z paultcochrane $
*/
/*! @file xml_basics.h
@brief The most basic XML character and string processing routines.
Note that only UTF8 encoding is supported here.
*/
#ifndef STDIO
#include<stdio.h>
#define STDIO
#endif
// ***************************************************************************
// ***************************************************************************
// XMLException
// ***************************************************************************
// ***************************************************************************
//! XMLException class
class XMLException {
public :
//! Enumerator containing the exception error codes
enum {
UNKNOWN_ENCODING_ERR = 1,
UNEXPECTED_EOF_ERR = 2,
RANGE_ERR = 3,
INVALID_CHAR_ERR = 4,
UNKNOWN_ERR = 0
};
//! The error code? Possibly?
unsigned short code;
//! Constructor of an XMLException object
XMLException();
//! Constructor of an XMLException object
XMLException(
const unsigned short& error);
//! Destructor
~XMLException();
//! Gets an xml error
const char* getError() const;
};
// ***************************************************************************
// ***************************************************************************
// XMLChar
// ***************************************************************************
// ***************************************************************************
//! Namespace for an xml character
namespace XMLChar {
//! Determines if character is a character
bool isChar(
const char& ch);
//! Determines if character is character data
bool isCharData(
const char& ch);
//! Determines if character is whitespace
bool isWhiteSpace(
const char& ch);
//! Determines if character is a latin letter
bool isLatinLetter(
const char& ch);
//! Determines if character is a latin digit
bool isLatinDigit(
const char& ch);
//! Determines if character is a latin hex digit
bool isLatinHexDigit(
const char& ch);
//! Determines if character is a letter
bool isLetter(
const char& ch);
//! Determines if character is a base character
bool isBaseChar(
const char& ch);
//! Determines if character is a digit
bool isDigit(
const char& ch);
//! Determines if character is a name character
bool isNameChar(
const char& ch);
//! Determines if character is a NC name character
bool isNCNameChar(
const char& ch);
//! Determines if character is a public id character
bool isPubidChar(
const char& ch);
}
// ***************************************************************************
// ***************************************************************************
// XMLString
// ***************************************************************************
// ***************************************************************************
//! XMLString class
class XMLString {
private :
char* _data; //!< Internal variable for data
unsigned long _length; //!< Internal variable for length of an XML string
mutable char* _c_str; //!< Internal variable for a C string
mutable bool _c_str_valid; //!< Internal variable showing if a C string is valid
public:
//! Constructor of an XMLString object
XMLString();
//! Constructor of an XMLString object
XMLString(
const char* s);
//! Constructor of an XMLString object
XMLString(
const XMLString& s);
//! Destructor
~XMLString();
//! Assignment operator for XMLString object
XMLString& operator=(
const XMLString& s);
//! Assignment operator for XMLString object
XMLString& operator=(
const char* s);
//! Returns the length of an XMLString
unsigned long length() const;
//! Converts an XMLString to a C string
const char* c_str() const;
//! Returns data at index (buh?)
char data(
const unsigned long& index) const;
//! Equality operator
bool operator==(
const XMLString& s) const;
//! Inequality operator
bool operator!=(
const XMLString& s) const;
//! += operator
XMLString& operator+=(
const XMLString& s);
//! Loads an xml string from file infile
long loadFromFile(
FILE* infile);
//! Returns a substring of an XML string starting at begin and ending at end_plus_one
void subString(
XMLString& subS,
const unsigned long& begin,
const unsigned long& end_plus_one) const;
//! Inserts string at offset
void insertString(
const unsigned long& offset,
const XMLString& s);
//! Deletes count data (characters?) starting at offset
void deleteData(
const unsigned long& offset,
const unsigned long& count);
//! Replaces count data (characters?) starting at offset
void replaceData(
const unsigned long& offset,
unsigned long count,
const XMLString& s);
//! Determines if string has illegal characters
bool hasIllegalCharacters() const;
//! Determines if starts with xml
bool beginsWithxml() const;
//! Determins if starts with XxMmLl (what is this supposed to mean?)
bool beginsWithXxMmLl() const;
//! Determines if is xml (I think)
bool eqxml() const;
//! Determines if is xml namespace (I think)
bool eqxmlns() const;
//! Determines if is a name
bool isName() const;
//! Determines if is a NC name
bool isNCName() const;
//! Determines if namespace is well formed
bool isNSWellFormed() const;
//! Determines if is a version number
bool isVersionNum() const;
//! Determines if is an encoding name
bool isEncName() const;
//! Determines if is a public id literal
bool isPubidLiteral() const;
//! Determines if is a split namespace name
bool splitNSName(
XMLString& prefix,
XMLString& localPart) const;
//! Determines if is a qualified name
bool isQualifiedName();
//! Determines if is all whitespace
bool isAllWhiteSpace() const;
//! Determines if is as unsigned long
bool asULong(
unsigned long& outULong) const;
//! Determines if is as double
bool asDouble(
double& outDouble) const;
//! Changes to Latin alphanumeric (I think)
void goLatinAlphaNumeric();
//! Changes to Latin alphanumeric with '_' replaced with '0' (for Mathematica)
void goLatinAlphaNumericNoUnderScore();
};
/*
* Local variables:
* c-indentation-style: bsd
* c-basic-offset: 2
* indent-tabs-mode: nil
* End:
*
* vim: tabstop=2 expandtab shiftwidth=2:
*/
|