00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 #include <ximol/parser/utils.hpp>
00112 #include <ximol/str_cast.hpp>
00113 #include <ximol/parser/def_signs.hpp>
00114 #include <ximol/encoders/encoders.hpp>
00115 #include <ximol/translation.hpp>
00116 #include <ximol/sstream.hpp>
00117 #include <ximol/error.hpp>
00118 #include <ximol/io.hpp>
00119
00120 #define XBET(lower,upper) ( ((xchar_t)lower <= c) && (c <= (xchar_t)upper) )
00121 #define XEQ(val) ((xchar_t)val == c)
00122
00123
00124 XIMOL_PARSER_BEGIN_NAMESPACE
00125
00126
00127
00128
00129 void write_xchar(xostream& xos, xchar_t xc)
00130 {
00131 xos.rdbuf()->sputc(xc);
00132 }
00133
00134
00135
00136
00137 template <class T>
00138 void clear_string(T &xstr)
00139 {
00140 if (!xstr.empty()) xstr.erase(xstr.begin(),xstr.end());
00141 }
00142
00143
00144
00145
00146 xistream& read_xchar(xistream& xis,
00147 xchar_t xc,
00148 const ::std::wstring & error_msg)
00149 {
00150 xchar_t xc_read;
00151 if ( (xis.get(xc_read)) && (xc==xc_read) ) return xis;
00152
00153
00154 xis.setstate(std::ios::failbit);
00155 XIMOL_THROW << _(L"Reading this char '%o' and waiting for this char '%o'. ",(char)(xc_read),(char)(xc))
00156 << error_msg << XIMOL_AS_ERROR;
00157 return xis;
00158 }
00159
00160
00161
00162
00163 xistream& read_xchar(xistream& xis,
00164 xchar_t & xc,
00165 bool (*is_good_xchar)(xchar_t),
00166 const ::std::wstring & error_msg)
00167 {
00168 if ( (xis.get(xc)) && (is_good_xchar(xc)) ) return xis;
00169
00170
00171 xis.setstate(std::ios::failbit);
00172 XIMOL_THROW << ( (xis.good()) ? _(L"Reading this char '%o'.",(char)(xc)):_(L"Can not read a char."))
00173 << error_msg << XIMOL_AS_ERROR;
00174 return xis;
00175 }
00176
00177
00178
00179
00180 xistream& read_xstring(xistream& xis,
00181 xstring & xstr,
00182 bool (*is_good_xchar)(xchar_t),
00183 bool erase_string)
00184 {
00185 if (! (xis.good()) ) return xis;
00186 if (erase_string) clear_string(xstr);
00187
00188 xchar_t xc;
00189 while ( (xc=xis.front()) && (is_good_xchar(xc)) && (xis.good()))
00190 {
00191 xstr+=xc;
00192 xis.pop_front();
00193 }
00194
00195 return xis;
00196 }
00197
00198
00199
00200
00201 bool is_xstring(const xstring & xstr, bool (*is_good_xchar)(xchar_t))
00202 {
00203 xstring::const_iterator i(xstr.begin()),i_end(xstr.end());
00204 for(;i!=i_end;++i)
00205 if (!is_good_xchar(*i)) return false;
00206 return true;
00207 }
00208
00209
00210
00211
00212 xistream& read_xstring(xistream& xistream_, const ::std::string& str_,
00213 const ::std::wstring& strErrorMsg_, size_t size_)
00214 {
00215 ::std::string::const_iterator i(str_.begin()), i_end(str_.end());
00216 ::std::wstring const new_err_msg =
00217 _(L"Parsing for this string '%o'. %o", str_, strErrorMsg_);
00218
00219
00220 while ((size_>0)&&(i != i_end)) {
00221 --size_;
00222 ++i;
00223 }
00224
00225
00226 for(; i != i_end; ++i)
00227 read_xchar(xistream_, *i, new_err_msg);
00228
00229 return xistream_;
00230 }
00231
00232
00233
00234
00235 xostream& write_string_with_forbidden_serie(xostream& xos,
00236 const xstring & xstr,
00237 bool (*is_good_xchar)(xchar_t),
00238 const ::std::string& forbidden_string,
00239 const ::std::string& entity_test,
00240 const ::std::string& entity_definition)
00241 {
00242 if (! (xos.good()) ) return xos;
00243 if (is_string_with_forbidden_serie(xstr,is_good_xchar,forbidden_string))
00244 {
00245 xos << xstr;
00246 return xos;
00247 }
00248
00249
00250 xos.setstate(std::ios::failbit);
00251 XIMOL_THROW << _(L"'%o' is not a %o.",str< ::std::string>::cast(xstr),entity_test)
00252 << _(L"XML Definition : %o",entity_definition)
00253 << XIMOL_AS_ERROR;
00254 return xos;
00255 }
00256
00257
00258
00259
00260 xistream& read_string_with_forbidden_serie(xistream& xis,
00261 xstring & xstr,
00262 bool (*is_good_xchar)(xchar_t),
00263 const ::std::string& forbidden_string)
00264 {
00265 if (! (xis.good()) ) return xis;
00266 clear_string(xstr);
00267 xchar_t xc;
00268 int nb_forbidden_char=0;
00269 int fs_length=static_cast<int>(forbidden_string.length());
00270 xchar_t next_forbidden_char=(xchar_t)(forbidden_string[nb_forbidden_char]);
00271
00272 while ( (xis.good())
00273 &&(nb_forbidden_char<fs_length)
00274 &&(xis.get(xc))
00275 &&(is_good_xchar(xc))
00276 )
00277 {
00278 if (xc==next_forbidden_char)
00279 {
00280 ++nb_forbidden_char;
00281 next_forbidden_char=(xchar_t)(forbidden_string[nb_forbidden_char]);
00282 } else {
00283 if (nb_forbidden_char>0) {
00284 int i;
00285 for(i=0;i<nb_forbidden_char;++i)
00286 xstr+=forbidden_string[i];
00287 nb_forbidden_char=0;
00288 next_forbidden_char=(xchar_t)(forbidden_string[nb_forbidden_char]);
00289 }
00290 xstr+=xc;
00291 }
00292 }
00293 if ( (xis.good())
00294 &&( ((nb_forbidden_char==fs_length)&&(0!=fs_length))
00295 ||(! is_good_xchar(xc))
00296 )
00297 )
00298 {
00299 int i;
00300 for(i=nb_forbidden_char-1;i>=0;--i)
00301 xis.putback(forbidden_string[i]);
00302 if (!is_good_xchar(xc)) xis.putback(xc);
00303 }
00304 return xis;
00305 }
00306
00307
00308
00309
00310 bool is_string_with_forbidden_serie(const xstring & xstr,
00311 bool (*is_good_xchar)(xchar_t),
00312 const ::std::string& forbidden_string)
00313 {
00314 xistringstream xis(xstr.c_str());
00315 xstring result;
00316 read_string_with_forbidden_serie(xis,result,is_good_xchar,forbidden_string);
00317 return (result.length()==xstr.length());
00318 }
00319
00320
00321
00322
00323 bool is_in_range(xchar_t c, xchar_t lower, xchar_t upper)
00324 {
00325 return XBET(lower,upper);
00326 }
00327
00328
00329
00330
00331 bool is_space(xchar_t c)
00332 {
00333 return ( XEQ(0x20) || XEQ(0x9) || XEQ(0xD) || XEQ(0xA) );
00334 }
00335
00336
00337
00338
00339 bool is_digit(xchar_t c)
00340 {
00341 return ( XBET(0x0030,0x0039)
00342 || XBET(0x0660,0x0669)
00343 || XBET(0x06F0,0x06F9)
00344 || XBET(0x0966,0x096F)
00345 || XBET(0x09E6,0x09EF)
00346 || XBET(0x0A66,0x0A6F)
00347 || XBET(0x0AE6,0x0AEF)
00348 || XBET(0x0B66,0x0B6F)
00349 || XBET(0x0BE7,0x0BEF)
00350 || XBET(0x0C66,0x0C6F)
00351 || XBET(0x0CE6,0x0CEF)
00352 || XBET(0x0D66,0x0D6F)
00353 || XBET(0x0E50,0x0E59)
00354 || XBET(0x0ED0,0x0ED9)
00355 || XBET(0x0F20,0x0F29) );
00356
00357 }
00358
00359
00360
00361
00362 bool is_char(xchar_t c)
00363 {
00364 return ( XEQ(0x9)
00365 || XEQ(0xA)
00366 || XEQ(0xD)
00367 || XBET(0x20,0xD7FF)
00368 || XBET(0xE000,0xFFFD)
00369 || XBET(0x10000,0x10FFFF) );
00370 }
00371
00372
00373
00374
00375 bool is_letter(xchar_t c)
00376 {
00377 return ( is_base_char(c) || is_ideographic(c) );
00378 }
00379
00380
00381
00382
00383 bool is_combining_char(xchar_t c)
00384 {
00385 return ( XBET(0x0300,0x0345) || XBET(0x0360,0x0361) || XBET(0x0483,0x0486)
00386 || XBET(0x0591,0x05A1) || XBET(0x05A3,0x05B9) || XBET(0x05BB,0x05BD)
00387 || XEQ(0x05BF) || XBET(0x05C1,0x05C2) || XEQ(0x05C4)
00388 || XBET(0x064B,0x0652) || XEQ(0x0670) || XBET(0x06D6,0x06DC)
00389 || XBET(0x06DD,0x06DF) || XBET(0x06E0,0x06E4) || XBET(0x06E7,0x06E8)
00390 || XBET(0x06EA,0x06ED) || XBET(0x0901,0x0903) || XEQ(0x093C)
00391 || XBET(0x093E,0x094C) || XEQ(0x094D) || XBET(0x0951,0x0954)
00392 || XBET(0x0962,0x0963) || XBET(0x0981,0x0983)
00393 || XEQ(0x09BC) || XEQ(0x09BE) || XEQ(0x09BF) || XBET(0x09C0,0x09C4)
00394 || XBET(0x09C7,0x09C8) || XBET(0x09CB,0x09CD) || XEQ(0x09D7)
00395 || XBET(0x09E2,0x09E3) || XEQ(0x0A02) || XEQ(0x0A3C) || XEQ(0x0A3E)
00396 || XEQ(0x0A3F)
00397 || XBET(0x0A40,0x0A42) || XBET(0x0A47,0x0A48) || XBET(0x0A4B,0x0A4D)
00398 || XBET(0x0A70,0x0A71) || XBET(0x0A81,0x0A83) || XEQ(0x0ABC)
00399 || XBET(0x0ABE,0x0AC5) || XBET(0x0AC7,0x0AC9) || XBET(0x0ACB,0x0ACD)
00400 || XBET(0x0B01,0x0B03) || XEQ(0x0B3C) || XBET(0x0B3E,0x0B43)
00401 || XBET(0x0B47,0x0B48) || XBET(0x0B4B,0x0B4D) || XBET(0x0B56,0x0B57)
00402 || XBET(0x0B82,0x0B83) || XBET(0x0BBE,0x0BC2) || XBET(0x0BC6,0x0BC8)
00403 || XBET(0x0BCA,0x0BCD) || XEQ(0x0BD7) || XBET(0x0C01,0x0C03)
00404 || XBET(0x0C3E,0x0C44) || XBET(0x0C46,0x0C48) || XBET(0x0C4A,0x0C4D)
00405 || XBET(0x0C55,0x0C56) || XBET(0x0C82,0x0C83) || XBET(0x0CBE,0x0CC4)
00406 || XBET(0x0CC6,0x0CC8) || XBET(0x0CCA,0x0CCD) || XBET(0x0CD5,0x0CD6)
00407 || XBET(0x0D02,0x0D03) || XBET(0x0D3E,0x0D43) || XBET(0x0D46,0x0D48)
00408 || XBET(0x0D4A,0x0D4D) || XEQ(0x0D57) || XEQ(0x0E31)
00409 || XBET(0x0E34,0x0E3A)
00410 || XBET(0x0E47,0x0E4E) || XEQ(0x0EB1) || XBET(0x0EB4,0x0EB9)
00411 || XBET(0x0EBB,0x0EBC) || XBET(0x0EC8,0x0ECD) || XBET(0x0F18,0x0F19)
00412 || XEQ(0x0F35) || XEQ(0x0F37) || XEQ(0x0F39) || XEQ(0x0F3E) || XEQ(0x0F3F)
00413 || XBET(0x0F71,0x0F84) || XBET(0x0F86,0x0F8B) || XBET(0x0F90,0x0F95)
00414 || XEQ(0x0F97) || XBET(0x0F99,0x0FAD) || XBET(0x0FB1,0x0FB7) || XEQ(0x0FB9)
00415 || XBET(0x20D0,0x20DC) || XEQ(0x20E1) || XBET(0x302A,0x302F) || XEQ(0x3099)
00416 || XEQ(0x309A) );
00417 }
00418
00419
00420
00421
00422 bool is_base_char(xchar_t c)
00423 {
00424 return ( XBET(0x0041,0x005A) || XBET(0x0061,0x007A) || XBET(0x00C0,0x00D6)
00425 || XBET(0x00D8,0x00F6) || XBET(0x00F8,0x00FF) || XBET(0x0100,0x0131)
00426 || XBET(0x0134,0x013E) || XBET(0x0141,0x0148) || XBET(0x014A,0x017E)
00427 || XBET(0x0180,0x01C3) || XBET(0x01CD,0x01F0) || XBET(0x01F4,0x01F5)
00428 || XBET(0x01FA,0x0217) || XBET(0x0250,0x02A8) || XBET(0x02BB,0x02C1)
00429 || XEQ(0x0386) || XBET(0x0388,0x038A) || XEQ(0x038C) || XBET(0x038E,0x03A1)
00430 || XBET(0x03A3,0x03CE) || XBET(0x03D0,0x03D6) || XEQ(0x03DA) || XEQ(0x03DC)
00431 || XEQ(0x03DE) || XEQ(0x03E0) || XBET(0x03E2,0x03F3) || XBET(0x0401,0x040C)
00432 || XBET(0x040E,0x044F) || XBET(0x0451,0x045C) || XBET(0x045E,0x0481)
00433 || XBET(0x0490,0x04C4) || XBET(0x04C7,0x04C8) || XBET(0x04CB,0x04CC)
00434 || XBET(0x04D0,0x04EB) || XBET(0x04EE,0x04F5) || XBET(0x04F8,0x04F9)
00435 || XBET(0x0531,0x0556) || XEQ(0x0559) || XBET(0x0561,0x0586)
00436 || XBET(0x05D0,0x05EA) || XBET(0x05F0,0x05F2) || XBET(0x0621,0x063A)
00437 || XBET(0x0641,0x064A) || XBET(0x0671,0x06B7) || XBET(0x06BA,0x06BE)
00438 || XBET(0x06C0,0x06CE) || XBET(0x06D0,0x06D3) || XEQ(0x06D5)
00439 || XBET(0x06E5,0x06E6) || XBET(0x0905,0x0939) || XEQ(0x093D)
00440 || XBET(0x0958,0x0961) || XBET(0x0985,0x098C) || XBET(0x098F,0x0990)
00441 || XBET(0x0993,0x09A8) || XBET(0x09AA,0x09B0) || XEQ(0x09B2)
00442 || XBET(0x09B6,0x09B9) || XBET(0x09DC,0x09DD) || XBET(0x09DF,0x09E1)
00443 || XBET(0x09F0,0x09F1) || XBET(0x0A05,0x0A0A) || XBET(0x0A0F,0x0A10)
00444 || XBET(0x0A13,0x0A28) || XBET(0x0A2A,0x0A30) || XBET(0x0A32,0x0A33)
00445 || XBET(0x0A35,0x0A36) || XBET(0x0A38,0x0A39) || XBET(0x0A59,0x0A5C)
00446 || XEQ(0x0A5E) || XBET(0x0A72,0x0A74) || XBET(0x0A85,0x0A8B) || XEQ(0x0A8D)
00447 || XBET(0x0A8F,0x0A91) || XBET(0x0A93,0x0AA8) || XBET(0x0AAA,0x0AB0)
00448 || XBET(0x0AB2,0x0AB3) || XBET(0x0AB5,0x0AB9) || XEQ(0x0ABD) || XEQ(0x0AE0)
00449 || XBET(0x0B05,0x0B0C) || XBET(0x0B0F,0x0B10) || XBET(0x0B13,0x0B28)
00450 || XBET(0x0B2A,0x0B30) || XBET(0x0B32,0x0B33) || XBET(0x0B36,0x0B39)
00451 || XEQ(0x0B3D) || XBET(0x0B5C,0x0B5D) || XBET(0x0B5F,0x0B61)
00452 || XBET(0x0B85,0x0B8A) || XBET(0x0B8E,0x0B90) || XBET(0x0B92,0x0B95)
00453 || XBET(0x0B99,0x0B9A) || XEQ(0x0B9C) || XBET(0x0B9E,0x0B9F)
00454 || XBET(0x0BA3,0x0BA4) || XBET(0x0BA8,0x0BAA) || XBET(0x0BAE,0x0BB5)
00455 || XBET(0x0BB7,0x0BB9) || XBET(0x0C05,0x0C0C) || XBET(0x0C0E,0x0C10)
00456 || XBET(0x0C12,0x0C28) || XBET(0x0C2A,0x0C33) || XBET(0x0C35,0x0C39)
00457 || XBET(0x0C60,0x0C61) || XBET(0x0C85,0x0C8C) || XBET(0x0C8E,0x0C90)
00458 || XBET(0x0C92,0x0CA8) || XBET(0x0CAA,0x0CB3) || XBET(0x0CB5,0x0CB9)
00459 || XEQ(0x0CDE) || XBET(0x0CE0,0x0CE1) || XBET(0x0D05,0x0D0C)
00460 || XBET(0x0D0E,0x0D10) || XBET(0x0D12,0x0D28)
00461 || XBET(0x0D2A,0x0D39) || XBET(0x0D60,0x0D61)
00462 || XBET(0x0E01,0x0E2E) || XEQ(0x0E30) || XBET(0x0E32,0x0E33)
00463 || XBET(0x0E40,0x0E45) || XBET(0x0E81,0x0E82) || XEQ(0x0E84)
00464 || XBET(0x0E87,0x0E88) || XEQ(0x0E8A) || XEQ(0x0E8D) || XBET(0x0E94,0x0E97)
00465 || XBET(0x0E99,0x0E9F) || XBET(0x0EA1,0x0EA3) || XEQ(0x0EA5) || XEQ(0x0EA7)
00466 || XBET(0x0EAA,0x0EAB) || XBET(0x0EAD,0x0EAE) || XEQ(0x0EB0)
00467 || XBET(0x0EB2,0x0EB3) || XEQ(0x0EBD) || XBET(0x0EC0,0x0EC4)
00468 || XBET(0x0F40,0x0F47) || XBET(0x0F49,0x0F69) || XBET(0x10A0,0x10C5)
00469 || XBET(0x10D0,0x10F6) || XEQ(0x1100) || XBET(0x1102,0x1103)
00470 || XBET(0x1105,0x1107) || XEQ(0x1109) || XBET(0x110B,0x110C)
00471 || XBET(0x110E,0x1112) || XEQ(0x113C) || XEQ(0x113E) || XEQ(0x1140) || XEQ(0x114C)
00472 || XEQ(0x114E) || XEQ(0x1150) || XBET(0x1154,0x1155) || XEQ(0x1159)
00473 || XBET(0x115F,0x1161) || XEQ(0x1163) || XEQ(0x1165) || XEQ(0x1167) || XEQ(0x1169)
00474 || XBET(0x116D,0x116E) || XBET(0x1172,0x1173) || XEQ(0x1175) || XEQ(0x119E)
00475 || XEQ(0x11A8) || XEQ(0x11AB) || XBET(0x11AE,0x11AF) || XBET(0x11B7,0x11B8)
00476 || XEQ(0x11BA) || XBET(0x11BC,0x11C2) || XEQ(0x11EB) || XEQ(0x11F0) || XEQ(0x11F9)
00477 || XBET(0x1E00,0x1E9B) || XBET(0x1EA0,0x1EF9) || XBET(0x1F00,0x1F15)
00478 || XBET(0x1F18,0x1F1D) || XBET(0x1F20,0x1F45) || XBET(0x1F48,0x1F4D)
00479 || XBET(0x1F50,0x1F57) || XEQ(0x1F59) || XEQ(0x1F5B) || XEQ(0x1F5D)
00480 || XBET(0x1F5F,0x1F7D) || XBET(0x1F80,0x1FB4) || XBET(0x1FB6,0x1FBC)
00481 || XEQ(0x1FBE) || XBET(0x1FC2,0x1FC4) || XBET(0x1FC6,0x1FCC)
00482 || XBET(0x1FD0,0x1FD3) || XBET(0x1FD6,0x1FDB) || XBET(0x1FE0,0x1FEC)
00483 || XBET(0x1FF2,0x1FF4) || XBET(0x1FF6,0x1FFC) || XEQ(0x2126)
00484 || XBET(0x212A,0x212B) || XEQ(0x212E) || XBET(0x2180,0x2182)
00485 || XBET(0x3041,0x3094) || XBET(0x30A1,0x30FA) || XBET(0x3105,0x312C)
00486 || XBET(0xAC00,0xD7A3) );
00487 }
00488
00489
00490
00491
00492 bool is_ideographic(xchar_t c)
00493 {
00494 return ( XBET(0x4E00,0x9FA5) || XEQ(0x3007) || XBET(0x3021,0x3029) );
00495 }
00496
00497
00498
00499
00500 bool is_extender(xchar_t c)
00501 {
00502 return ( XEQ(0x00B7) || XEQ(0x02D0) || XEQ(0x02D1)
00503 || XEQ(0x0387) || XEQ(0x0640) || XEQ(0x0E46)
00504 || XEQ(0x0EC6) || XEQ(0x3005) || XBET(0x3031,0x3035)
00505 || XBET(0x309D,0x309E) || XBET(0x30FC,0x30FE));
00506 }
00507
00508
00509
00510
00511 bool is_name_char(xchar_t c)
00512 {
00513 return ( is_letter(c) || is_digit(c)
00514 || XEQ(0x002e) || XEQ(0x002d) || XEQ(0x005f) || XEQ(0x003a)
00515 || is_combining_char(c) || is_extender(c) );
00516 }
00517
00518
00519
00520
00521 bool IsNCNameChar(xchar_t c)
00522 {
00523 return ( is_letter(c) || is_digit(c)
00524 || XEQ(XCHAR_FULL_STOP) || XEQ(XCHAR_HYPHEN_MINUS) || XEQ(XCHAR_LOW_LINE)
00525 || is_combining_char(c) || is_extender(c) );
00526 }
00527
00528
00529
00530
00531 bool is_pubid_char(xchar_t c){
00532 return ( XEQ(0x0020) || XEQ(0x000D) || XEQ(0x000A)
00533 || XBET(0x0061,0x007a)
00534 || XBET(0x003F,0x005a)
00535 || XBET(0x0027,0x003B)
00536 || XEQ(0x003d)
00537 || XEQ(0x0021)
00538 || XBET(0x0023,0x0025)
00539 || XEQ(0x005f)
00540 );
00541 }
00542
00543
00544
00545
00546 xostream& write_space(xostream& xos)
00547 {
00548 write_xchar(xos,(xchar_t)(0x0020));
00549 return xos;
00550 }
00551
00552
00553
00554
00555 xistream& read_space(xistream& xis)
00556 {
00557 xchar_t xc;
00558 read_xchar(xis,xc,is_space,_(L"Waiting for a space. XML Definition : S::= (#x20 | #x9 | #xD | #xA)"));
00559 return read_optionnal_space(xis);
00560 }
00561
00562
00563
00564
00565 xistream& read_optionnal_space(xistream& xis)
00566 {
00567 xstring xstr;
00568 read_xstring(xis,xstr,is_space);
00569 return xis;
00570 }
00571
00572
00573
00574
00575
00576 xostream& write_name(xostream& xos, const xstring & xstr)
00577 {
00578 if (! (xos.good()) ) return xos;
00579 if (is_name(xstr))
00580 {
00581 xos << xstr;
00582 return xos;
00583 }
00584
00585
00586 xos.setstate(std::ios::failbit);
00587 XIMOL_THROW << _(L"'%o' is not a name.",str< ::std::string>::cast(xstr))
00588 << _(L"XML Definition : name ::= (Letter | '_' | ':') (NameChar)*")
00589 << XIMOL_AS_ERROR;
00590 return xos;
00591 }
00592
00593
00594
00595
00596 bool is_first_char_name(xchar_t xc)
00597 {
00598 return ( ((xc)==XCHAR_LOW_LINE)
00599 || ((xc)==XCHAR_COLON)
00600 || (is_letter(xc))
00601 );
00602 }
00603
00604
00605
00606
00607
00608 xistream& read_name(xistream& xis, xstring & xstr)
00609 {
00610 if (! (xis.good()) ) return xis;
00611 clear_string(xstr);
00612 xchar_t xc;
00613 read_xchar(xis,xc,is_first_char_name,_(L"Parsing the first char of a name. XML Definition : name ::= (Letter | '_' | ':') (NameChar)*"));
00614
00615 xstr+=xc;
00616 read_xstring(xis,xstr,is_name_char,false);
00617
00618 return xis;
00619 }
00620
00621
00622
00623
00624
00625 bool is_name(const xstring & xstr)
00626 {
00627 if (xstr.empty()) return false;
00628 xstring::const_iterator i=xstr.begin(), i_end=xstr.end();
00629 if ( ! is_first_char_name(*i)) return false;
00630 ++i;
00631 for(;i!=i_end;++i) if (!is_name_char(*i)) return false;
00632 return true;
00633 }
00634
00635
00636
00637
00638
00639 xostream& write_ncname(xostream& xos, const xstring & xstr)
00640 {
00641 if (! (xos.good()) ) return xos;
00642 if (is_ncname(xstr))
00643 {
00644 xos << xstr;
00645 return xos;
00646 }
00647
00648
00649 xos.setstate(std::ios::failbit);
00650 XIMOL_THROW << _(L"'%o' is not a name.",str< ::std::string>::cast(xstr))
00651 << _(L"XML Definition : NCName ::= (Letter | '_') (NCNameChar)*")
00652 << XIMOL_AS_ERROR;
00653 return xos;
00654 }
00655
00656
00657
00658
00659 bool is_first_char_ncname(xchar_t xc)
00660 {
00661 return ( ((xc)==XCHAR_LOW_LINE)
00662 || ((xc)==XCHAR_COLON)
00663 || (is_letter(xc))
00664 );
00665 }
00666
00667
00668
00669
00670
00671 xistream& read_ncname(xistream& xis, xstring & xstr)
00672 {
00673 if (! (xis.good()) ) return xis;
00674 clear_string(xstr);
00675 xchar_t xc;
00676 read_xchar(xis,xc,is_first_char_ncname,_(L"Parsing the first char of a NCName. XML Definition : name ::= (Letter | '_' | ':') (NameChar)*"));
00677
00678 xstr+=xc;
00679 read_xstring(xis,xstr,IsNCNameChar,false);
00680
00681 return xis;
00682 }
00683
00684
00685
00686
00687
00688 bool is_ncname(const xstring & xstr)
00689 {
00690 if (xstr.empty()) return false;
00691 xstring::const_iterator i=xstr.begin(), i_end=xstr.end();
00692 if ( ! is_first_char_ncname(*i)) return false;
00693 ++i;
00694 for(;i!=i_end;++i) if (!IsNCNameChar(*i)) return false;
00695 return true;
00696 }
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708 xostream& write_qname(xostream& xos, const xstring & localPart, const xstring & prefix)
00709 {
00710 if (! (xos.good()) ) return xos;
00711 if (! prefix.empty())
00712 {
00713 write_ncname(xos,prefix);
00714 write_xchar(xos,XCHAR_COLON);
00715 }
00716 write_ncname(xos,localPart);
00717 return xos;
00718 }
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730 xistream& read_qname(xistream& xis, xstring & localPart, xstring & prefix)
00731 {
00732 if (! (xis.good()) ) return xis;
00733 clear_string(prefix);
00734 read_ncname(xis,localPart);
00735 if (xis.front()==XCHAR_COLON)
00736 {
00737 xis.pop_front();
00738 prefix=localPart;
00739 read_ncname(xis,localPart);
00740 }
00741 return xis;
00742 }
00743
00744
00745
00746
00747 bool is_qname(const xstring & localPart, const xstring & prefix)
00748 {
00749 return ((is_ncname(localPart))&&(prefix.empty() || is_ncname(prefix)));
00750 }
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763 xostream& write_ns_att_name(xostream& xos, const xstring & xstr)
00764 {
00765 if (! (xos.good()) ) return xos;
00766 if (is_ns_att_name(xstr))
00767 {
00768 write_xchar(xos,XCHAR_LATIN_SMALL_LETTER_X);
00769 write_xchar(xos,XCHAR_LATIN_SMALL_LETTER_M);
00770 write_xchar(xos,XCHAR_LATIN_SMALL_LETTER_L);
00771 write_xchar(xos,XCHAR_LATIN_SMALL_LETTER_N);
00772 write_xchar(xos,XCHAR_LATIN_SMALL_LETTER_S);
00773 if (! xstr.empty()) {
00774 write_xchar(xos,XCHAR_COLON);
00775 xos << xstr;
00776 }
00777 return xos;
00778 }
00779
00780
00781 xos.setstate(std::ios::failbit);
00782 XIMOL_THROW << _(L"'%o' is not a name.",str< ::std::string>::cast(xstr))
00783 << _(L"XML Definition : NSAttName ::= PrefixedAttName | DefaultAttName \nPrefixedAttName ::= 'xmlns:' NCName\nDefaultAttName ::= 'xmlns' ")
00784 << XIMOL_AS_ERROR;
00785 return xos;
00786 }
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799 xistream& read_ns_att_name(xistream& xis, xstring & xstr, int nb_read)
00800 {
00801 if (! (xis.good()) ) return xis;
00802 switch (nb_read){
00803 case 0: read_xchar(xis,XCHAR_LATIN_SMALL_LETTER_X,_(L"XML Definition : NSAttName ::= PrefixedAttName | DefaultAttName \nPrefixedAttName ::= 'xmlns:' NCName\nDefaultAttName ::= 'xmlns' "));
00804 case 1: read_xchar(xis,XCHAR_LATIN_SMALL_LETTER_M,_(L"XML Definition : NSAttName ::= PrefixedAttName | DefaultAttName \nPrefixedAttName ::= 'xmlns:' NCName\nDefaultAttName ::= 'xmlns' "));
00805 case 2: read_xchar(xis,XCHAR_LATIN_SMALL_LETTER_L,_(L"XML Definition : NSAttName ::= PrefixedAttName | DefaultAttName \nPrefixedAttName ::= 'xmlns:' NCName\nDefaultAttName ::= 'xmlns' "));
00806 case 3: read_xchar(xis,XCHAR_LATIN_SMALL_LETTER_N,_(L"XML Definition : NSAttName ::= PrefixedAttName | DefaultAttName \nPrefixedAttName ::= 'xmlns:' NCName\nDefaultAttName ::= 'xmlns' "));
00807 case 4: read_xchar(xis,XCHAR_LATIN_SMALL_LETTER_S,_(L"XML Definition : NSAttName ::= PrefixedAttName | DefaultAttName \nPrefixedAttName ::= 'xmlns:' NCName\nDefaultAttName ::= 'xmlns' "));
00808 }
00809 clear_string(xstr);
00810 xchar_t xc=xis.front();
00811 if (xc==XCHAR_COLON)
00812 {
00813 xis.pop_front();
00814 read_ncname(xis,xstr);
00815 }
00816 return xis;
00817 }
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830 bool is_ns_att_name(const xstring & xstr)
00831 {
00832 if (xstr.empty()) return true;
00833 return is_ncname(xstr);
00834 }
00835
00836
00837
00838
00839 bool IsNotAndOrInf(xchar_t xc)
00840 {
00841 return ((is_char(xc)) &&
00842 (xc != XCHAR_AMPERSAND) &&
00843 (xc != XCHAR_LESS_THAN_SIGN));
00844 }
00845
00846
00847
00848
00849
00850 xostream& write_char_data(xostream& xos, const xstring & xstr)
00851 {
00852 if (! (xos.good()) ) return xos;
00853 if (is_char_data(xstr))
00854 {
00855 xos << xstr;
00856 return xos;
00857 }
00858
00859
00860 xos.setstate(std::ios::failbit);
00861 XIMOL_THROW << _(L"'%o' is not a CharData.",str< ::std::string>::cast(xstr))
00862 << _(L"XML Definition : CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*) ")
00863 << XIMOL_AS_ERROR;
00864 return xos;
00865 }
00866
00867
00868
00869
00870
00871
00872
00873
00874 xistream& read_char_data(xistream& xis, xstring & xstr)
00875 {
00876 return read_string_with_forbidden_serie(xis,xstr,IsNotAndOrInf,"]]>");
00877 }
00878
00879
00880
00881
00882
00883 bool is_char_data(const xstring & xstr)
00884 {
00885 return is_string_with_forbidden_serie(xstr,IsNotAndOrInf,"]]>");
00886 }
00887
00888
00889
00890
00891
00892 xostream& write_nm_token(xostream& xos, const xstring & xstr)
00893 {
00894 if (! (xos.good()) ) return xos;
00895 if (is_nm_token(xstr))
00896 {
00897 xos << xstr;
00898 return xos;
00899 }
00900
00901
00902 xos.setstate(std::ios::failbit);
00903 XIMOL_THROW << _(L"'%o' is not a Nmtoken.",str< ::std::string>::cast(xstr))
00904 << _(L"XML Definition : Nmtoken ::= (NameChar)+")
00905 << XIMOL_AS_ERROR;
00906 return xos;
00907 }
00908
00909
00910
00911
00912
00913 xistream& read_nm_token(xistream& xis, xstring & xstr)
00914 {
00915 clear_string(xstr);
00916 xchar_t xc;
00917 read_xchar(xis,xc,is_name_char,_(L"Parsing the first char of a Nmtoken. XML Definition : Nmtoken ::= (NameChar)+"));
00918 xstr+=xc;
00919 return read_xstring(xis,xstr,is_name_char,false);
00920 }
00921
00922
00923
00924
00925
00926 bool is_nm_token(const xstring & xstr)
00927 {
00928 if (xstr.empty()) return false;
00929 xstring::const_iterator i=xstr.begin(), i_end=xstr.end();
00930 if ( ! (is_name_char(*i)) ) return false;
00931 for(;i!=i_end;++i) if (!is_name_char(*i)) return false;
00932 return true;
00933 }
00934
00935
00936
00937
00938
00939
00940
00941 xostream& write_char_ref(xostream& xos, xchar_t xc)
00942 {
00943 if (! (xos.good()) ) return xos;
00944 if (! is_char(xc))
00945 {
00946 xos.setstate(std::ios::failbit);
00947 XIMOL_THROW << _(L"write a char reference, '%o' is not a Standard Char.",xc)
00948 << XIMOL_AS_ERROR;
00949 return xos;
00950 }
00951 write_xchar(xos, XCHAR_AMPERSAND);
00952 write_xchar(xos, XCHAR_NUMBER_SIGN);
00953 ::std::dec(xos);
00954 xos << static_cast<unsigned>(xc);
00955 write_xchar(xos, XCHAR_SEMICOLON);
00956 return xos;
00957 }
00958
00959
00960
00961
00962
00963
00964
00965
00966 xistream& read_char_ref(xistream& xis, xchar_t & xc_read, int nb_read)
00967 {
00968 if (! (xis.good()) ) return xis;
00969 xchar_t xc;
00970 switch (nb_read){
00971 case 0: read_xchar(xis,XCHAR_AMPERSAND ,_(L"XML Definition : CharRef ::= ('&#' [0-9]+ ';') | ('&#x' [0-9a-fA-F]+ ';')"));
00972 case 1: read_xchar(xis,XCHAR_NUMBER_SIGN,_(L"XML Definition : CharRef ::= ('&#' [0-9]+ ';') | ('&#x' [0-9a-fA-F]+ ';')"));
00973 }
00974
00975 xc=xis.front();
00976 long nb_char;
00977 bool is_hex=false;
00978 if ((xc)==XCHAR_LATIN_SMALL_LETTER_X)
00979 {
00980 is_hex=true;
00981 xis.pop_front();
00982 }
00983
00984 ::std::basic_stringstream<xchar_t> buf;
00985 while ( (xis.get(xc))
00986 &&( (is_digit(xc))
00987 ||(is_in_range(xc,XCHAR_LATIN_CAPITAL_LETTER_A,XCHAR_LATIN_CAPITAL_LETTER_F))
00988 ||(is_in_range(xc,XCHAR_LATIN_SMALL_LETTER_A,XCHAR_LATIN_SMALL_LETTER_F))
00989 ))
00990 buf << xc;
00991 xis.putback(xc);
00992 buf >> ((is_hex)?(std::hex):(std::dec))>> nb_char;
00993 xc_read=(xchar_t)nb_char;
00994
00995
00996 return read_xchar(xis,XCHAR_SEMICOLON,_(L"XML Definition : CharRef ::= ('&#' [0-9]+ ';') | ('&#x' [0-9a-fA-F]+ ';')"));
00997 }
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008 xstring replace_char_ref(const xstring& xstr)
01009 {
01010 xstring result;
01011 xstring::const_iterator i(xstr.begin()), i_end(xstr.end());
01012 while (i!=i_end)
01013 {
01014 if (*i == XCHAR_AMPERSAND)
01015 {
01016 xstring temp(i,i_end);
01017 xistringstream xistr(temp);
01018 xchar_t xc;
01019 try {
01020 read_char_ref(xistr,xc);
01021 result+=xc;
01022 } catch (...) {
01023 result+=*i;
01024 }
01025 ++i;
01026 }
01027 else
01028 {
01029 result+=*i;
01030 ++i;
01031 }
01032 }
01033 return result;
01034 }
01035
01036
01037
01038
01039
01040
01041
01042 xostream& write_entity_ref(xostream& xos, const xstring & xstr)
01043 {
01044 if (! (xos.good()) ) return xos;
01045
01046 write_xchar(xos,XCHAR_AMPERSAND);
01047 write_name(xos,xstr);
01048 write_xchar(xos,XCHAR_SEMICOLON);
01049 return xos;
01050
01051 }
01052
01053
01054
01055
01056
01057
01058
01059 xistream& read_entity_ref(xistream& xis, int nb_read)
01060 {
01061 if (! (xis.good()) ) return xis;
01062
01063 switch (nb_read) {
01064 case 0: read_xchar(xis,XCHAR_AMPERSAND,_(L"XML Definition : EntityRef ::= '&' name ';'"));
01065 }
01066
01067 xstring name;
01068 read_name(xis,name);
01069
01070
01071 read_xchar(xis,XCHAR_SEMICOLON,_(L"XML Definition : EntityRef ::= '&' name ';'"));
01072
01073 xis.putback(xis.context.get_entity(name));
01074 return xis;
01075 }
01076
01077
01078
01079
01080
01081
01082
01083 xostream& write_pe_reference(xostream& xos, const xstring & xstr)
01084 {
01085 if (! (xos.good()) ) return xos;
01086
01087 write_xchar(xos,XCHAR_PERCENT_SIGN);
01088 write_name(xos,xstr);
01089 write_xchar(xos,XCHAR_SEMICOLON);
01090 return xos;
01091 }
01092
01093
01094
01095
01096
01097
01098
01099 xistream& read_pe_reference(xistream& xis, xstring & xstr, int nb_read)
01100 {
01101 if (! (xis.good()) ) return xis;
01102 clear_string(xstr);
01103
01104 switch (nb_read) {
01105 case 0: read_xchar(xis,XCHAR_PERCENT_SIGN,_(L"XML Definition : PEReference ::= '%' name ';'"));
01106 }
01107
01108 read_name(xis,xstr);
01109
01110 read_xchar(xis,XCHAR_SEMICOLON,_(L"XML Definition : PEReference ::= '%' name ';'"));
01111
01112 xstr=xis.context.get_parameter_entity(xstr);
01113 return xis;
01114 }
01115
01116
01117
01118
01119
01120
01121 xistream& read_reference(xistream& xis, xstring & xstr, int nb_read)
01122 {
01123 if (! (xis.good()) ) return xis;
01124 clear_string(xstr);
01125
01126 switch (nb_read){
01127 case 0: read_xchar(xis,XCHAR_AMPERSAND,_(L"XML Definition : Reference ::= EntityRef | CharRef\nXML Definition : EntityRef ::= '&' name ';'\nXML Definition : CharRef ::= ('&#' [0-9]+ ';') | ('&#x' [0-9a-fA-F]+ ';')") );
01128 }
01129
01130 xchar_t xc=xis.front();
01131
01132 if ((xc)==XCHAR_NUMBER_SIGN)
01133 {
01134 read_char_ref(xis,xc,1);
01135 xstr+=xc;
01136 } else {
01137 read_entity_ref(xis,1);
01138 }
01139
01140 return xis;
01141 }
01142
01143
01144
01145
01146
01147
01148
01149 xostream& write_pubid_literal(xostream& xos, const xstring & xstr)
01150 {
01151 if (! (xos.good()) ) return xos;
01152 xstring::const_iterator i=xstr.begin(), i_end=xstr.end();
01153 write_xchar(xos,XCHAR_QUOTATION_MARK);
01154
01155 for(;i!=i_end;++i)
01156 {
01157 if (is_pubid_char(*i))
01158 write_xchar(xos,*i);
01159 else {
01160 xos.setstate(std::ios::failbit);
01161 XIMOL_THROW << _(L"write pubid_literal, '%o' is not a PubidChar.",(char)*i)
01162 << _(L"XML Definition : pubid_literal ::= '\"' PubidChar* '\"' | \"'\" (PubidChar - \"'\")* \"'\"")
01163 << _(L"XML Definition : PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%] ")
01164 << XIMOL_AS_ERROR;
01165 }
01166 }
01167 write_xchar(xos,XCHAR_QUOTATION_MARK);
01168 return xos;
01169 }
01170
01171
01172
01173
01174 bool IsQuote(xchar_t c)
01175 {
01176 return ( XEQ(0x0022) || XEQ(0x0027) );
01177 }
01178
01179
01180
01181
01182
01183
01184
01185 xistream& read_pubid_literal(xistream& xis, xstring & xstr)
01186 {
01187 if (! (xis.good()) ) return xis;
01188
01189 xchar_t xquote;
01190
01191 read_xchar(xis,xquote,IsQuote,_(L"pubid_literal parsing first char.\nXML Definition : pubid_literal ::= '\"' PubidChar* '\"' | \"'\" (PubidChar - \"'\")* \"'\""));
01192
01193 if (xquote==XCHAR_APOSTROPHE)
01194 {
01195 read_string_with_forbidden_serie(xis,xstr,is_pubid_char,"'");
01196 read_xchar(xis,XCHAR_APOSTROPHE,_(L"pubid_literal parsing last char (').\nXML Definition : pubid_literal ::= '\"' PubidChar* '\"' | \"'\" (PubidChar - \"'\")* \"'\""));
01197 } else {
01198 read_string_with_forbidden_serie(xis,xstr,is_pubid_char,"\"");
01199 read_xchar(xis,XCHAR_QUOTATION_MARK,_(L"pubid_literal parsing last char (\").\nXML Definition : pubid_literal ::= '\"' PubidChar* '\"' | \"'\" (PubidChar - \"'\")* \"'\""));
01200 }
01201 return xis;
01202 }
01203
01204
01205
01206
01207
01208
01209
01210 xostream& write_system_literal(xostream& xos, const xstring & xstr, xchar_t quote)
01211 {
01212 if (! (xos.good()) ) return xos;
01213 xstring::const_iterator i=xstr.begin(), i_end=xstr.end();
01214 write_xchar(xos,quote);
01215
01216 for(;i!=i_end;++i)
01217 {
01218 if ( (is_char(*i)) && (*i!=quote) )
01219 write_xchar(xos,*i);
01220 else {
01221 xos.setstate(std::ios::failbit);
01222 XIMOL_THROW << _(L"write system_literal, '%o' is not a Char or equal to the quote '%o'.",(char)*i,(char)quote)
01223 << _(L"XML Definition : system_literal ::= ('\"' [^\"]* '\"') | (\"'\" [^']* \"'\")")
01224 << XIMOL_AS_ERROR;
01225 }
01226 }
01227 write_xchar(xos,quote);
01228 return xos;
01229 }
01230
01231
01232
01233
01234
01235
01236
01237 xistream& read_system_literal(xistream& xis, xstring & xstr)
01238 {
01239 if (! (xis.good()) ) return xis;
01240 clear_string(xstr);
01241 xchar_t xquote;
01242
01243 read_xchar(xis,xquote,IsQuote,_(L"system_literal parsing first char.\nXML Definition : system_literal ::= ('\"' [^\"]* '\"') | (\"'\" [^']* \"'\")"));
01244 if (xquote==XCHAR_APOSTROPHE)
01245 {
01246 read_string_with_forbidden_serie(xis,xstr,is_char,"'");
01247 read_xchar(xis,XCHAR_APOSTROPHE,_(L"system_literal parsing last char (').\nXML Definition : system_literal ::= ('\"' [^\"]* '\"') | (\"'\" [^']* \"'\")"));
01248 } else {
01249 read_string_with_forbidden_serie(xis,xstr,is_char,"\"");
01250 read_xchar(xis,XCHAR_QUOTATION_MARK,_(L"system_literal parsing last char (\").\nXML Definition : system_literal ::= ('\"' [^\"]* '\"') | (\"'\" [^']* \"'\")"));
01251 }
01252 return xis;
01253 }
01254
01255
01256
01257
01258
01259
01260
01261
01262 xostream& write_entity_value(xostream& xos, const xstring & xstr, xchar_t quote)
01263 {
01264 if (! (xos.good()) ) return xos;
01265 xstring::const_iterator i=xstr.begin(), i_end=xstr.end();
01266 write_xchar(xos,quote);
01267
01268 for(;i!=i_end;++i)
01269 {
01270 if ( (*i!=XCHAR_PERCENT_SIGN)
01271 &&(*i!=XCHAR_AMPERSAND)
01272 &&(*i!=quote))
01273 write_xchar(xos,*i);
01274 else
01275 write_char_ref(xos,*i);
01276 }
01277 write_xchar(xos,quote);
01278 return xos;
01279 }
01280
01281
01282
01283
01284 xstring ToQuoteRef(const xstring & xstr)
01285 {
01286 xstring::const_iterator i=xstr.begin(), i_end=xstr.end();
01287 xstring result;
01288 for(;i!=i_end;++i) switch (*i)
01289 {
01290 case XCHAR_QUOTATION_MARK: result+=str< ::std::wstring>::cast("""); break;
01291 case XCHAR_APOSTROPHE: result+=str< ::std::wstring>::cast("'"); break;
01292 default: result+=*i;
01293 }
01294 return result;
01295 }
01296
01297
01298
01299
01300
01301
01302
01303
01304 xistream& read_entity_value(xistream& xis, xstring & xstr)
01305 {
01306 if (! (xis.good()) ) return xis;
01307 clear_string(xstr);
01308 xchar_t xc,xquote;
01309 xstring xtemp;
01310
01311 read_xchar(xis,xquote,IsQuote,_(L"entity_value parsing first char.\nXML Definition : entity_value ::= '\"' ([^%&\"] | PEReference | Reference)* '\"' | \"'\" ([^%&'] | PEReference | Reference)* \"'\" "));
01312
01313 while ( (xis.get(xc)) && (xc!=xquote) && (is_char(xc)) )
01314 {
01315 switch (xc)
01316 {
01317 case XCHAR_AMPERSAND :
01318 if ((xis.get(xc))&&(is_char(xc)))
01319 {
01320 if (xc==XCHAR_NUMBER_SIGN) {
01321 read_char_ref(xis,xc,2);
01322 xstr+=xc;
01323 } else {
01324 xis.putback(xc);
01325 read_name(xis,xtemp);
01326 read_xchar(xis,XCHAR_SEMICOLON,_(L"XML Definition : PEReference ::= '%' name ';'"));
01327 xstr+=XCHAR_AMPERSAND + xtemp + XCHAR_SEMICOLON;
01328 }
01329 } else {
01330 XIMOL_THROW << _(L"entity_value parsing : '%o' is not a Char.",(char)(xc))
01331 << _(L"XML Definition : entity_value ::= '\"' ([^%&\"] | PEReference | Reference)* '\"' | \"'\" ([^%&'] | PEReference | Reference)* \"'\" ")
01332 << XIMOL_AS_ERROR;
01333 }
01334 break;
01335 case XCHAR_PERCENT_SIGN :
01336 read_pe_reference(xis,xtemp,1);
01337 xis.putback(ToQuoteRef(xtemp));
01338 break;
01339 default: xstr+=xc;
01340 }
01341 }
01342
01343 if ((xis.good()) && (xc==xquote)) return xis;
01344
01345
01346 xis.setstate(std::ios::failbit);
01347 XIMOL_THROW << _(L"entity_value parsing : '%o' is not a quote.",(char)(xc))
01348 << _(L"XML Definition : entity_value ::= '\"' ([^%&\"] | PEReference | Reference)* '\"' | \"'\" ([^%&'] | PEReference | Reference)* \"'\" ")
01349 << XIMOL_AS_ERROR;
01350 return xis;
01351 }
01352
01353
01354
01355
01356
01357
01358
01359
01360 xostream& write_att_value(xostream& xos, const xstring & xstr, xchar_t quote)
01361 {
01362 if (! (xos.good()) ) return xos;
01363 xstring::const_iterator i=xstr.begin(), i_end=xstr.end();
01364 write_xchar(xos,quote);
01365
01366 for(;i!=i_end;++i)
01367 {
01368 if (is_char(*i))
01369 {
01370 if ((*i!=XCHAR_LESS_THAN_SIGN) &&
01371 (*i!=XCHAR_AMPERSAND) &&
01372 (*i!=quote) )
01373 write_xchar(xos,*i);
01374 else write_char_ref(xos,*i);
01375 } else {
01376 xos.setstate(std::ios::failbit);
01377 XIMOL_THROW << _(L"write AttValue, '%o' is not a Char.",(char)*i)
01378 << _(L"XML Definition : AttValue ::= '\"' ([^<&\"] | Reference)* '\"' | \"'\" ([^<&'] | Reference)* \"'\"")
01379 << XIMOL_AS_ERROR;
01380
01381 }
01382 }
01383 write_xchar(xos,quote);
01384 return xos;
01385 }
01386
01387
01388
01389
01390
01391
01392
01393
01394 xistream& read_att_value(xistream& xis, xstring & xstr)
01395 {
01396 if (! (xis.good()) ) return xis;
01397 clear_string(xstr);
01398 xchar_t xc,xquote;
01399 xstring xtemp;
01400
01401 read_xchar(xis,xquote,IsQuote,_(L"AttValue parsing first char.\nXML Definition : AttValue ::= '\"' ([^<&\"] | Reference)* '\"' | \"'\" ([^<&'] | Reference)* \"'\""));
01402
01403 while ( (xis.get(xc)) && (xc!=xquote) && (is_char(xc)))
01404 {
01405 switch (xc)
01406 {
01407 case XCHAR_AMPERSAND :
01408 if ((xis.get(xc))&&(is_char(xc)))
01409 {
01410 if (xc==XCHAR_NUMBER_SIGN) {
01411 read_char_ref(xis,xc,2);
01412 xstr+=xc;
01413 } else {
01414 read_reference(xis,xtemp,1);
01415 xis.putback(ToQuoteRef(xtemp));
01416 }
01417 } else {
01418 XIMOL_THROW << _(L"AttValue parsing : '%o' is not a Char.",(char)(xc))
01419 << _(L"XML Definition : AttValue ::= '\"' ([^<&\"] | Reference)* '\"' | \"'\" ([^<&'] | Reference)* \"'\"")
01420 << XIMOL_AS_ERROR;
01421 }
01422 break;
01423 default: xstr+=xc;
01424 }
01425 }
01426
01427 if ((xis.good()) && (xc==xquote)) return xis;
01428
01429
01430 xis.setstate(std::ios::failbit);
01431 XIMOL_THROW << _(L"AttValue parsing : '%o' is not a quote.",(char)(xc))
01432 << _(L"XML Definition : AttValue ::= '\"' ([^<&\"] | Reference)* '\"' | \"'\" ([^<&'] | Reference)* \"'\"")
01433 << XIMOL_AS_ERROR;
01434 return xis;
01435 }
01436
01437
01438
01439
01440
01441
01442
01443 xostream& write_attribute(xostream& xos, const xstring & name, const xstring & att_value, const xstring & short_ns, xchar_t quote)
01444 {
01445 write_qname(xos,name,short_ns);
01446 write_eq(xos);
01447 write_att_value(xos,att_value,quote);
01448 return xos;
01449 }
01450
01451
01452
01453
01454
01455
01456
01457 xistream& read_attribute(xistream& xis, xstring & name, xstring & att_value, xstring & short_ns)
01458 {
01459 read_qname(xis,name,short_ns);
01460 read_eq(xis);
01461 read_att_value(xis,att_value);
01462 return xis;
01463 }
01464
01465
01466
01467
01468
01469
01470 bool is_comment(const xstring & xstr)
01471 {
01472 if (xstr.empty()) return true;
01473 bool first_test=is_string_with_forbidden_serie(xstr,is_char,"--");
01474 bool second_test=true;
01475 if (xstr[xstr.length()-1]==XCHAR_HYPHEN_MINUS) second_test=false;
01476 return ( first_test && second_test );
01477 }
01478
01479
01480
01481
01482
01483
01484 xostream& write_comment(xostream& xos, const xstring & xstr)
01485 {
01486 if (! (xos.good()) ) return xos;
01487 xstring::const_iterator i=xstr.begin(), i_end=xstr.end();
01488 write_xchar(xos,XCHAR_LESS_THAN_SIGN);
01489 write_xchar(xos,XCHAR_EXCLAMATION_MARK);
01490 write_xchar(xos,XCHAR_HYPHEN_MINUS);
01491 write_xchar(xos,XCHAR_HYPHEN_MINUS);
01492
01493 if (is_comment(xstr)) xos<<xstr;
01494 else {
01495 xos.setstate(std::ios::failbit);
01496 XIMOL_THROW << _(L"write comment, '%o' is not a comment.",str< ::std::string>::cast(xstr))
01497 << _(L"XML Definition : comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'")
01498 << XIMOL_AS_ERROR;
01499 }
01500 write_xchar(xos,XCHAR_HYPHEN_MINUS);
01501 write_xchar(xos,XCHAR_HYPHEN_MINUS);
01502 write_xchar(xos,XCHAR_GREATER_THAN_SIGN);
01503 return xos;
01504 }
01505
01506
01507
01508
01509
01510
01511 xistream& read_comment(xistream& xis, xstring & xstr, int nb_read)
01512 {
01513 if (! (xis.good()) ) return xis;
01514 clear_string(xstr);
01515
01516 switch(nb_read){
01517 case 0: read_xchar(xis,XCHAR_LESS_THAN_SIGN, _(L"comment parsing a '<'.XML Definition : comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'") );
01518 case 1: read_xchar(xis,XCHAR_EXCLAMATION_MARK,_(L"comment parsing a '!'.XML Definition : comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'") );
01519 case 2: read_xchar(xis,XCHAR_HYPHEN_MINUS, _(L"comment parsing a '-'.XML Definition : comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'") );
01520 case 3: read_xchar(xis,XCHAR_HYPHEN_MINUS, _(L"comment parsing a '-'.XML Definition : comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'") );
01521 }
01522
01523 read_string_with_forbidden_serie(xis,xstr,is_char,"--");
01524
01525 read_xchar(xis,XCHAR_HYPHEN_MINUS, _(L"comment parsing a '-'.XML Definition : comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'") );
01526 read_xchar(xis,XCHAR_HYPHEN_MINUS, _(L"comment parsing a '-'.XML Definition : comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'") );
01527 read_xchar(xis,XCHAR_GREATER_THAN_SIGN,_(L"comment parsing a '>'.XML Definition : comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'") );
01528 return xis;
01529 }
01530
01531
01532
01533
01534 xistream& read_comment(xistream& xis, int nb_read)
01535 {
01536 xstring dummy;
01537 return read_comment(xis,dummy,nb_read);
01538 }
01539
01540
01541
01542
01543
01544
01545 bool is_pi_target(const xstring & xstr)
01546 {
01547 if (! is_name(xstr)) return false;
01548 xstring::const_iterator i(xstr.begin()), i_end(xstr.end());
01549 int nb_char_forbidden=0;
01550 while ((i!=i_end) && (nb_char_forbidden<3))
01551 {
01552 if ((nb_char_forbidden==0)&&
01553 ((*i==XCHAR_LATIN_CAPITAL_LETTER_X)||(*i==XCHAR_LATIN_SMALL_LETTER_X)))
01554 ++nb_char_forbidden;
01555 if ((nb_char_forbidden==1)&&
01556 ((*i==XCHAR_LATIN_CAPITAL_LETTER_M)||(*i==XCHAR_LATIN_SMALL_LETTER_M)))
01557 ++nb_char_forbidden;
01558 else nb_char_forbidden=0;
01559 if ((nb_char_forbidden==2)&&
01560 ((*i==XCHAR_LATIN_CAPITAL_LETTER_L)||(*i==XCHAR_LATIN_SMALL_LETTER_L)))
01561 ++nb_char_forbidden;
01562 else nb_char_forbidden=0;
01563 ++i;
01564 }
01565 if (nb_char_forbidden==3) return false;
01566 return true;
01567 }
01568
01569
01570
01571
01572
01573
01574 xostream& write_pi_target(xostream& xos, const xstring & xstr)
01575 {
01576 if (is_pi_target(xstr)) return write_name(xos,xstr);
01577 xos.setstate(std::ios::failbit);
01578 XIMOL_THROW << _(L"write pi_target, '%o' is not a pi_target.",str< ::std::string>::cast(xstr))
01579 << _(L"XML Definition : pi_target ::= name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))")
01580 << _(L"XML Definition : name ::= (Letter | '_' | ':') (NameChar)*")
01581 << XIMOL_AS_ERROR;
01582 return xos;
01583 }
01584
01585
01586
01587
01588
01589
01590 xistream& read_pi_target(xistream& xis, xstring & xstr)
01591 {
01592 read_name(xis,xstr);
01593 if (is_pi_target(xstr)) return xis;
01594 xis.setstate(std::ios::failbit);
01595 XIMOL_THROW << _(L"Parse pi_target, '%o' is not a pi_target.",str< ::std::string>::cast(xstr))
01596 << _(L"XML Definition : pi_target ::= name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))")
01597 << _(L"XML Definition : name ::= (Letter | '_' | ':') (NameChar)*")
01598 << XIMOL_AS_ERROR;
01599 return xis;
01600 }
01601
01602
01603
01604
01605
01606
01607 xostream& write_pi(xostream& xos, const xstring & pi_target, const xstring & xext)
01608 {
01609 if (! (xos.good()) ) return xos;
01610 write_xchar(xos,XCHAR_LESS_THAN_SIGN);
01611 write_xchar(xos,XCHAR_QUESTION_MARK);
01612 write_pi_target(xos,pi_target);
01613 if (xext.length()>0)
01614 {
01615 write_space(xos);
01616 if (is_string_with_forbidden_serie(xext,is_char,"?>"))
01617 {
01618 xos<<xext;
01619 } else {
01620 xos.setstate(std::ios::failbit);
01621 XIMOL_THROW << _(L"Writing PI, '%o' is not a PI extension.",str< ::std::string>::cast(xext))
01622 << _(L"XML Definition : PI ::= '<?' pi_target (S (Char* - (Char* '?>' Char*)))? '?>'")
01623 << XIMOL_AS_ERROR;
01624 return xos;
01625 }
01626 }
01627 write_xchar(xos,XCHAR_QUESTION_MARK);
01628 write_xchar(xos,XCHAR_LESS_THAN_SIGN);
01629 return xos;
01630 }
01631
01632
01633
01634
01635
01636
01637 xistream& read_pi(xistream& xis, xstring & xstr,xstring & xext, int nb_read)
01638 {
01639 if (! (xis.good()) ) return xis;
01640 clear_string(xstr);
01641 clear_string(xext);
01642
01643 switch(nb_read){
01644 case 0: read_xchar(xis,XCHAR_LESS_THAN_SIGN, _(L"comment parsing a '<'.XML Definition : PI ::= '<?' pi_target (S (Char* - (Char* '?>' Char*)))? '?>'") );
01645 case 1: read_xchar(xis,XCHAR_QUESTION_MARK, _(L"comment parsing a '?'.XML Definition : PI ::= '<?' pi_target (S (Char* - (Char* '?>' Char*)))? '?>'") );
01646 }
01647
01648 read_pi_target(xis,xstr);
01649 read_optionnal_space(xis);
01650 read_string_with_forbidden_serie(xis,xext,is_char,"?>");
01651
01652 read_xchar(xis,XCHAR_QUESTION_MARK,
01653 _(L"comment parsing a '>'.XML Definition : PI ::= '<?' pi_target (S (Char* - (Char* '?>' Char*)))? '?>'") );
01654 read_xchar(xis,XCHAR_GREATER_THAN_SIGN,
01655 _(L"comment parsing a '>'.XML Definition : PI ::= '<?' pi_target (S (Char* - (Char* '?>' Char*)))? '?>'") );
01656 return xis;
01657 }
01658
01659
01660
01661
01662
01663
01664 xistream& read_pi(xistream& xis, int nb_read)
01665 {
01666 xstring xstr,xext;
01667 read_pi(xis,xstr,xext,nb_read);
01668 xis.context.add_processing_instruction(xstr,xext);
01669 return xis;
01670 }
01671
01672
01673
01674
01675
01676
01677 xostream& write_cd_end(xostream& xos)
01678 {
01679 write_xchar(xos,XCHAR_RIGHT_SQUARE_BRACKET);
01680 write_xchar(xos,XCHAR_RIGHT_SQUARE_BRACKET);
01681 write_xchar(xos,XCHAR_GREATER_THAN_SIGN);
01682 return xos;
01683 }
01684
01685
01686
01687
01688
01689
01690 xistream& read_cd_end(xistream& xis, int nb_read)
01691 {
01692 if (! (xis.good()) ) return xis;
01693 switch(nb_read){
01694 case 0: read_xchar(xis,XCHAR_RIGHT_SQUARE_BRACKET, _(L"comment parsing a ']'.XML Definition : cd_end ::= ']]>'") );
01695 case 1: read_xchar(xis,XCHAR_RIGHT_SQUARE_BRACKET, _(L"comment parsing a ']'.XML Definition : cd_end ::= ']]>'") );
01696 case 2: read_xchar(xis,XCHAR_GREATER_THAN_SIGN, _(L"comment parsing a '>'.XML Definition : cd_end ::= ']]>'") );
01697 }
01698 return xis;
01699 }
01700
01701
01702
01703
01704
01705
01706 xostream& write_cd_start(xostream& xos)
01707 {
01708 write_xchar(xos,XCHAR_LESS_THAN_SIGN);
01709 write_xchar(xos,XCHAR_EXCLAMATION_MARK);
01710 write_xchar(xos,XCHAR_LEFT_SQUARE_BRACKET);
01711 write_xchar(xos,XCHAR_LATIN_CAPITAL_LETTER_C);
01712 write_xchar(xos,XCHAR_LATIN_CAPITAL_LETTER_D);
01713 write_xchar(xos,XCHAR_LATIN_CAPITAL_LETTER_A);
01714 write_xchar(xos,XCHAR_LATIN_CAPITAL_LETTER_T);
01715 write_xchar(xos,XCHAR_LATIN_CAPITAL_LETTER_A);
01716 write_xchar(xos,XCHAR_LEFT_SQUARE_BRACKET);
01717 return xos;
01718 }
01719
01720
01721
01722
01723
01724
01725 xistream& read_cd_start(xistream& xis, int nb_read)
01726 {
01727 if (! (xis.good()) ) return xis;
01728
01729 switch(nb_read){
01730 case 0: read_xchar(xis,XCHAR_LESS_THAN_SIGN, _(L"comment parsing a '<'.XML Definition : cd_start ::= '<![CDATA['") );
01731 case 1: read_xchar(xis,XCHAR_EXCLAMATION_MARK, _(L"comment parsing a '!'.XML Definition : cd_start ::= '<![CDATA['") );
01732 case 2: read_xchar(xis,XCHAR_LEFT_SQUARE_BRACKET, _(L"comment parsing a '['.XML Definition : cd_start ::= '<![CDATA['") );
01733 case 3: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_C, _(L"comment parsing a 'C'.XML Definition : cd_start ::= '<![CDATA['") );
01734 case 4: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_D, _(L"comment parsing a 'D'.XML Definition : cd_start ::= '<![CDATA['") );
01735 case 5: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_A, _(L"comment parsing a 'A'.XML Definition : cd_start ::= '<![CDATA['") );
01736 case 6: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_T, _(L"comment parsing a 'T'.XML Definition : cd_start ::= '<![CDATA['") );
01737 case 7: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_A, _(L"comment parsing a 'A'.XML Definition : cd_start ::= '<![CDATA['") );
01738 case 8: read_xchar(xis,XCHAR_LEFT_SQUARE_BRACKET, _(L"comment parsing a '['.XML Definition : cd_start ::= '<![CDATA['") );
01739 }
01740 return xis;
01741 }
01742
01743
01744
01745
01746
01747
01748 xostream& write_cdata(xostream& xos, const xstring & xstr)
01749 {
01750 if (is_string_with_forbidden_serie(xstr,is_char,"]]>"))
01751 {
01752 xos<<xstr;
01753 return xos;
01754 }
01755
01756
01757 xos.setstate(std::ios::failbit);
01758 XIMOL_THROW << _(L"write CData '%o'.",str< ::std::string>::cast(xstr))
01759 << _(L"XML Definition : CData ::= (Char* - (Char* ']]>' Char*))")
01760 << XIMOL_AS_ERROR;
01761 return xos;
01762 }
01763
01764
01765
01766
01767
01768
01769 xistream& read_cdata(xistream& xis, xstring & xstr)
01770 {
01771 return read_string_with_forbidden_serie(xis,xstr,is_char,"]]>");
01772 }
01773
01774
01775
01776
01777
01778
01779
01780 xostream& write_cd_sect(xostream& xos, const xstring & xstr)
01781 {
01782 write_cd_start(xos);
01783 write_cdata(xos,xstr);
01784 write_cd_end(xos);
01785 return xos;
01786 }
01787
01788
01789
01790
01791
01792
01793 xistream& read_cd_sect(xistream& xis, xstring & xstr, int nb_char)
01794 {
01795 read_cd_start(xis,nb_char);
01796 read_cdata(xis,xstr);
01797 read_cd_end(xis);
01798 return xis;
01799 }
01800
01801
01802
01803
01804
01805
01806 xostream& write_eq(xostream& xos)
01807 {
01808 write_xchar(xos,XCHAR_EQUALS_SIGN);
01809 return xos;
01810 }
01811
01812
01813
01814
01815
01816
01817 xistream& read_eq(xistream& xis)
01818 {
01819 read_optionnal_space(xis);
01820 read_xchar(xis,XCHAR_EQUALS_SIGN,_(L"Parsing an equality"));
01821 read_optionnal_space(xis);
01822 return xis;
01823 }
01824
01825
01826
01827
01828 bool IsVersionNumChar(xchar_t c)
01829 {
01830 return ( XBET(0x0041,0x005a)
01831 || XBET(0x0061,0x007a)
01832 || XBET(0x0030,0x0039)
01833 || XEQ(0x005f)
01834 || XEQ(0x002e)
01835 || XEQ(0x003a)
01836 || XEQ(0x002d)
01837 );
01838 }
01839
01840
01841
01842
01843
01844
01845 bool is_version_num(const xstring & xstr)
01846 {
01847 if (xstr.empty()) return false;
01848 return is_xstring(xstr,IsVersionNumChar);
01849 }
01850
01851
01852
01853
01854
01855
01856 xostream& write_version_num(xostream& xos, const xstring & xstr)
01857 {
01858 if (is_version_num(xstr))
01859 {
01860 xos<<xstr;
01861 return xos;
01862 }
01863
01864
01865 xos.setstate(std::ios::failbit);
01866 XIMOL_THROW << _(L"write VersionNum '%o'.",str< ::std::string>::cast(xstr))
01867 << _(L"XML Definition : VersionNum ::= ([a-zA-Z0-9_.:] | '-')+")
01868 << XIMOL_AS_ERROR;
01869 return xos;
01870 }
01871
01872
01873
01874
01875
01876
01877 xistream& read_version_num(xistream& xis, xstring & xstr)
01878 {
01879 read_xstring(xis,xstr,IsVersionNumChar);
01880 if (!xstr.empty()) return xis;
01881
01882
01883 xis.setstate(std::ios::failbit);
01884 XIMOL_THROW << _(L"Parsing VersionNum, and it seem to be empty.")
01885 << _(L"XML Definition : VersionNum ::= ([a-zA-Z0-9_.:] | '-')+")
01886 << XIMOL_AS_ERROR;
01887 return xis;
01888 }
01889
01890
01891
01892
01893
01894
01895 xostream& write_version_info(xostream& xos, const xstring & xstr)
01896 {
01897 write_space(xos);
01898 xos<<"version";
01899 write_eq(xos);
01900 write_xchar(xos,XCHAR_APOSTROPHE);
01901 write_version_num(xos,xstr);
01902 write_xchar(xos,XCHAR_APOSTROPHE);
01903 xos.context.set_version_num(xstr);
01904 return xos;
01905 }
01906
01907
01908
01909
01910
01911
01912 xistream& read_version_info(xistream& xis, xstring & xstr, bool read_first_space)
01913 {
01914 if (read_first_space) read_space(xis);
01915 read_xstring(xis,"version",_(L"Parsing version number."));
01916 read_eq(xis);
01917
01918 xchar_t xquote;
01919 read_xchar(xis,xquote,IsQuote,_(L"Version parsing first quote.\nXML Definition : VersionInfo ::= S 'version' Eq (\"'\" VersionNum \"'\" | '\"' VersionNum '\"')"));
01920 read_version_num(xis,xstr);
01921 read_xchar(xis,xquote,_(L"Version parsing last quote.\nXML Definition : VersionInfo ::= S 'version' Eq (\"'\" VersionNum \"'\" | '\"' VersionNum '\"')"));
01922
01923 xis.context.set_version_num(xstr);
01924
01925 return xis;
01926 }
01927
01928
01929
01930
01931
01932
01933 xistream& read_version_info(xistream& xis, bool read_first_space)
01934 {
01935 xstring xstr;
01936 read_version_info(xis,xstr);
01937 xis.context.set_version_num(xstr);
01938 return xis;
01939 }
01940
01941
01942
01943
01944 bool IsFirstEncNameChar(xchar_t c)
01945 {
01946 return ( XBET(0x0041,0x005a)
01947 || XBET(0x0061,0x007a)
01948 );
01949 }
01950
01951
01952
01953
01954 bool IsSecondEncNameChar(xchar_t c)
01955 {
01956 return ( XBET(0x0041,0x005a)
01957 || XBET(0x0061,0x007a)
01958 || XBET(0x0030,0x0039)
01959 || XEQ(0x005f)
01960 || XEQ(0x002e)
01961 || XEQ(0x002d)
01962 );
01963 }
01964
01965
01966
01967
01968
01969
01970 bool is_enc_name(const xstring & xstr)
01971 {
01972 if (xstr.empty()) return false;
01973 return ( (IsFirstEncNameChar(xstr[0]))
01974 &&(is_xstring(xstr,IsSecondEncNameChar)));
01975 }
01976
01977
01978
01979
01980
01981
01982 xostream& write_enc_name(xostream& xos, const xstring & xstr)
01983 {
01984 if (is_enc_name(xstr))
01985 {
01986 xos<<xstr;
01987 return xos;
01988 }
01989
01990
01991 xos.setstate(std::ios::failbit);
01992 XIMOL_THROW << _(L"write EncName '%o'.",str< ::std::string>::cast(xstr))
01993 << _(L"XML Definition : EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*")
01994 << XIMOL_AS_ERROR;
01995 return xos;
01996 }
01997
01998
01999
02000
02001
02002
02003 xistream& read_enc_name(xistream& xis, xstring & xstr)
02004 {
02005 if (! (xis.good()) ) return xis;
02006 clear_string(xstr);
02007 xchar_t xc;
02008 read_xchar(xis,xc,IsFirstEncNameChar,_(L"Parsing first char of EncName.\nXML Definition : EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*"));
02009 xstr+=xc;
02010 read_xstring(xis,xstr,IsSecondEncNameChar,false);
02011
02012 return xis;
02013 }
02014
02015
02016
02017
02018
02019
02020 xostream& write_encoding_decl(xostream& xos, const xstring & xstr)
02021 {
02022 write_space(xos);
02023 xos<<"encoding";
02024 write_eq(xos);
02025 write_xchar(xos,XCHAR_APOSTROPHE);
02026 write_enc_name(xos,xstr);
02027 write_xchar(xos,XCHAR_APOSTROPHE);
02028 xos.context.set_encoding_decl(xstr);
02029 return xos;
02030 }
02031
02032
02033
02034
02035
02036
02037 xistream& read_encoding_decl(xistream& xis, xstring & xstr, bool read_first_space)
02038 {
02039 if (read_first_space) read_space(xis);
02040 read_xstring(xis,"encoding",_(L"Parsing encoding declaration."));
02041 read_eq(xis);
02042
02043 xchar_t xquote;
02044 read_xchar(xis,xquote,IsQuote,_(L"Encoding declaration parsing first quote.\nXML Definition : EncodingDecl ::= S 'encoding' Eq ('\"' EncName '\"' | \"'\" EncName \"'\" )"));
02045 read_enc_name(xis,xstr);
02046 xis.context.set_encoding_decl(xstr);
02047
02048 read_xchar(xis,xquote,_(L"Encoding declaration parsing first quote.\nXML Definition : EncodingDecl ::= S 'encoding' Eq ('\"' EncName '\"' | \"'\" EncName \"'\" )"));
02049 return xis;
02050 }
02051
02052
02053
02054
02055
02056
02057 xostream& write_sd_decl(xostream& xos, bool standalone)
02058 {
02059 write_space(xos);
02060 xos<<"standalone";
02061 write_eq(xos);
02062 write_xchar(xos,XCHAR_APOSTROPHE);
02063 if (standalone) xos<<"yes";
02064 else xos<<"no";
02065 write_xchar(xos,XCHAR_APOSTROPHE);
02066 xos.context.set_sd_decl(standalone);
02067 return xos;
02068 }
02069
02070
02071
02072
02073
02074
02075 xistream& read_sd_decl(xistream& xis, bool & standalone, bool read_first_space)
02076 {
02077 if (read_first_space) read_space(xis);
02078 read_xstring(xis,"standalone",_(L"Parsing standalone declaration."));
02079 read_eq(xis);
02080
02081 xchar_t xquote;
02082 read_xchar(xis,xquote,IsQuote,_(L"Standalone declaration parsing first quote.\nXML Definition : SDDecl ::= S 'standalone' Eq ((\"'\" ('yes' | 'no') \"'\") | ('\"' ('yes' | 'no') '\"'))"));
02083 xstring xstr;
02084 xstring xyes=str< ::std::wstring>::cast("yes");
02085 xstring xno=str< ::std::wstring>::cast("no");
02086
02087 read_xstring(xis,xstr,IsFirstEncNameChar);
02088
02089 read_xchar(xis,xquote,IsQuote,_(L"Standalone declaration parsing last quote.\nXML Definition : SDDecl ::= S 'standalone' Eq ((\"'\" ('yes' | 'no') \"'\") | ('\"' ('yes' | 'no') '\"'))"));
02090
02091 standalone=(xstr==xyes);
02092 xis.context.set_sd_decl(standalone);
02093
02094 if (xstr==xyes) { return xis; }
02095 if (xstr==xno) { return xis; }
02096
02097
02098 xis.setstate(std::ios::failbit);
02099 XIMOL_THROW << _(L"Parsing SDDecl, and it seem to be wrong ('%o').",str< ::std::string>::cast(xstr))
02100 << _(L"XML Definition : SDDecl ::= S 'standalone' Eq ((\"'\" ('yes' | 'no') \"'\") | ('\"' ('yes' | 'no') '\"'))")
02101 << XIMOL_AS_ERROR;
02102 return xis;
02103 }
02104
02105
02106
02107
02108
02109
02110 xostream& write_xml_decl(xostream& xos,
02111 const xstring& version_info,
02112 const xstring& encoding_decl,
02113 const xstring& standalone_decl)
02114 {
02115 xos<<"<?xml";
02116 write_version_info(xos,str< ::std::wstring>::cast(version_info));
02117 if (!encoding_decl.empty()) write_encoding_decl(xos,str< ::std::wstring>::cast(encoding_decl));
02118 if (standalone_decl==str< ::std::wstring>::cast("yes")) write_sd_decl(xos,true);
02119 if (standalone_decl==str< ::std::wstring>::cast("no")) write_sd_decl(xos,false);
02120 write_space(xos);
02121 xos<<"?>";
02122 if (!encoding_decl.empty())
02123 xos.encoding(str< ::std::string>::cast(xos.context.get_encoding_decl()).c_str());
02124 return xos;
02125 }
02126
02127
02128
02129
02130
02131
02132
02133
02134
02135 xostream& write_xml_decl(xostream& xos)
02136 {
02137 return write_xml_decl(xos,
02138 xos.context.get_version_num(),
02139 xos.context.get_encoding_decl(),
02140 xos.context.get_sd_decl()?( str< ::std::wstring>::cast("yes")): (str< ::std::wstring>::cast("no")));
02141 }
02142
02143
02144
02145
02146 bool IsCharESQ(xchar_t c)
02147 {
02148 return ( XEQ(0x0065) || XEQ(0x0073) || XEQ(0x003f) );
02149 }
02150
02151
02152
02153
02154 bool IsCharSQ(xchar_t c)
02155 {
02156 return ( XEQ(0x0073) || XEQ(0x003f) );
02157 }
02158
02159
02160
02161
02162
02163
02164 xistream& read_xml_decl(xistream& xis,
02165 xstring& version_info,
02166 xstring& encoding_decl,
02167 bool & standalone_decl,
02168 int nb_read)
02169 {
02170 if (! (xis.good()) ) return xis;
02171 clear_string(version_info);
02172 clear_string(encoding_decl);
02173 standalone_decl=false;
02174
02175 switch(nb_read){
02176 case 0: read_xchar(xis,XCHAR_LESS_THAN_SIGN, _(L"comment parsing a '<'.XML Definition : XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'") );
02177 case 1: read_xchar(xis,XCHAR_QUESTION_MARK, _(L"comment parsing a '?'.XML Definition : XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'") );
02178 case 2: read_xchar(xis,XCHAR_LATIN_SMALL_LETTER_X, _(L"comment parsing a 'x'.XML Definition : XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'") );
02179 case 3: read_xchar(xis,XCHAR_LATIN_SMALL_LETTER_M, _(L"comment parsing a 'm'.XML Definition : XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'") );
02180 case 4: read_xchar(xis,XCHAR_LATIN_SMALL_LETTER_L, _(L"comment parsing a 'l'.XML Definition : XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'") );
02181 }
02182 read_version_info(xis,version_info);
02183 read_optionnal_space(xis);
02184
02185 xchar_t xc;
02186 read_xchar(xis,xc,IsCharESQ,_(L"comment parsing a ('e'|'s'|'?').XML Definition : XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'") );
02187 xis.putback(xc);
02188
02189 if (xc==XCHAR_LATIN_SMALL_LETTER_E)
02190 {
02191 read_encoding_decl(xis,encoding_decl,false);
02192 read_optionnal_space(xis);
02193 read_xchar(xis,xc,IsCharSQ,_(L"comment parsing a ('s'|'?').XML Definition : XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'") );
02194 xis.putback(xc);
02195 }
02196
02197 if (xc==XCHAR_LATIN_SMALL_LETTER_S)
02198 {
02199 read_sd_decl(xis,standalone_decl,false);
02200 }
02201
02202 read_optionnal_space(xis);
02203
02204 read_xstring(xis,"?>",_(L"comment parsing a '?>'.XML Definition : XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'") );
02205
02206 if (!encoding_decl.empty())
02207 xis.encoding(str< ::std::string>::cast(xis.context.get_encoding_decl()).c_str());
02208 return xis;
02209 }
02210
02211
02212
02213
02214
02215
02216
02217
02218
02219 xistream& read_xml_decl(xistream& xis, int nb_read)
02220 {
02221 xstring version_info;
02222 xstring encoding_decl;
02223 bool standalone_decl;
02224 return read_xml_decl(xis,version_info,encoding_decl,standalone_decl,nb_read);
02225 }
02226
02227
02228
02229
02230
02231
02232 xostream& write_external_id(xostream& xos, const xstring& system_literal, const xstring& pub_id_literal)
02233 {
02234 if (!pub_id_literal.empty())
02235 {
02236 xos<<"PUBLIC";
02237 write_space(xos);
02238 write_pubid_literal(xos,pub_id_literal);
02239 } else {
02240 xos<<"SYSTEM";
02241 }
02242 write_space(xos);
02243 write_system_literal(xos,system_literal);
02244
02245 return xos;
02246 }
02247
02248
02249
02250
02251 bool IsExternalCharSP(xchar_t c)
02252 {
02253 return ( XEQ(0x0053) || XEQ(0x0050) );
02254 }
02255
02256
02257
02258
02259
02260
02261 xistream& read_external_id(xistream& xis, xstring& system_literal, xstring& pub_id_literal)
02262 {
02263 if (! (xis.good()) ) return xis;
02264 clear_string(system_literal);
02265 clear_string(pub_id_literal);
02266
02267 xchar_t xc;
02268 read_xchar(xis,xc,IsExternalCharSP,_(L"Parsing a char 'S' or 'P' for an external id.\nXML Definition : ExternalID ::= 'SYSTEM' S system_literal | 'PUBLIC' S pubid_literal S system_literal "));
02269 xis.putback(xc);
02270
02271 if (xc==XCHAR_LATIN_CAPITAL_LETTER_P)
02272 {
02273 read_xstring(xis,"PUBLIC",_(L"Parsing 'PUBLIC' for an external id.\nXML Definition : ExternalID ::= 'SYSTEM' S system_literal | 'PUBLIC' S pubid_literal S system_literal "));
02274 read_space(xis);
02275 read_pubid_literal(xis,pub_id_literal);
02276 } else {
02277 read_xstring(xis,"SYSTEM",_(L"Parsing 'SYSTEM' for an external id.\nXML Definition : ExternalID ::= 'SYSTEM' S system_literal | 'PUBLIC' S pubid_literal S system_literal "));
02278 }
02279
02280 read_space(xis);
02281 read_system_literal(xis,system_literal);
02282
02283 return xis;
02284 }
02285
02286
02287
02288
02289
02290
02291 xostream& write_public_id(xostream& xos, const xstring& pub_id_literal)
02292 {
02293 xos<<"PUBLIC";
02294 write_space(xos);
02295 write_pubid_literal(xos,pub_id_literal);
02296 return xos;
02297 }
02298
02299
02300
02301
02302
02303
02304 xistream& read_public_id(xistream& xis, xstring& pub_id_literal)
02305 {
02306 if (! (xis.good()) ) return xis;
02307 clear_string(pub_id_literal);
02308
02309 read_xstring(xis,"PUBLIC",_(L"Parsing 'PUBLIC' for a public id.\nXML Definition : PublicID ::= 'PUBLIC' S pubid_literal "));
02310 read_space(xis);
02311 read_pubid_literal(xis,pub_id_literal);
02312
02313 return xis;
02314 }
02315
02316
02317
02318
02319
02320
02321 xostream& write_notation_decl(xostream& xos, const xstring& name, const xstring& system_literal, const xstring& pub_id_literal)
02322 {
02323 xos<<"<!NOTATION";
02324 write_space(xos);
02325 write_name(xos,name);
02326 write_space(xos);
02327 if (system_literal.empty()) write_public_id(xos,pub_id_literal);
02328 else write_external_id(xos,system_literal,pub_id_literal);
02329 write_xchar(xos,XCHAR_GREATER_THAN_SIGN);
02330 return xos;
02331 }
02332
02333
02334
02335
02336
02337
02338 xistream& read_notation_decl(xistream& xis, xstring& name, xstring& system_literal, xstring& pub_id_literal, int nb_read)
02339 {
02340 if (! (xis.good()) ) return xis;
02341 clear_string(name);
02342 clear_string(system_literal);
02343 clear_string(pub_id_literal);
02344
02345
02346 switch(nb_read){
02347 case 0: read_xchar(xis,XCHAR_LESS_THAN_SIGN, _(L"comment parsing a '<'.XML Definition : NotationDecl ::= '<!NOTATION' S name S (ExternalID | PublicID) S? '>'") );
02348 case 1: read_xchar(xis,XCHAR_EXCLAMATION_MARK, _(L"comment parsing a '!'.XML Definition : NotationDecl ::= '<!NOTATION' S name S (ExternalID | PublicID) S? '>'") );
02349 case 2: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_N, _(L"comment parsing a 'N'.XML Definition : NotationDecl ::= '<!NOTATION' S name S (ExternalID | PublicID) S? '>'") );
02350 case 3: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_O, _(L"comment parsing a 'O'.XML Definition : NotationDecl ::= '<!NOTATION' S name S (ExternalID | PublicID) S? '>'") );
02351 case 4: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_T, _(L"comment parsing a 'T'.XML Definition : NotationDecl ::= '<!NOTATION' S name S (ExternalID | PublicID) S? '>'") );
02352 case 5: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_A, _(L"comment parsing a 'A'.XML Definition : NotationDecl ::= '<!NOTATION' S name S (ExternalID | PublicID) S? '>'") );
02353 case 6: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_T, _(L"comment parsing a 'T'.XML Definition : NotationDecl ::= '<!NOTATION' S name S (ExternalID | PublicID) S? '>'") );
02354 case 7: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_I, _(L"comment parsing a 'I'.XML Definition : NotationDecl ::= '<!NOTATION' S name S (ExternalID | PublicID) S? '>'") );
02355 case 8: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_O, _(L"comment parsing a 'O'.XML Definition : NotationDecl ::= '<!NOTATION' S name S (ExternalID | PublicID) S? '>'") );
02356 case 9: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_N, _(L"comment parsing a 'N'.XML Definition : NotationDecl ::= '<!NOTATION' S name S (ExternalID | PublicID) S? '>'") );
02357 }
02358
02359 read_space(xis);
02360 read_name(xis,name);
02361 read_space(xis);
02362 xchar_t xc;
02363 read_xchar(xis,xc,IsExternalCharSP,_(L"Parsing a char 'S' or 'P' for a notation declaration.\nXML Definition : NotationDecl ::= '<!NOTATION' S name S (ExternalID | PublicID) S? '>' "));
02364 xis.putback(xc);
02365
02366 if (xc==XCHAR_LATIN_CAPITAL_LETTER_P)
02367 {
02368 read_xstring(xis,"PUBLIC",_(L"Parsing 'PUBLIC' for a notation declaration.\nXML Definition : NotationDecl ::= '<!NOTATION' S name S (ExternalID | PublicID) S? '>' "));
02369 read_space(xis);
02370 read_pubid_literal(xis,pub_id_literal);
02371 read_optionnal_space(xis);
02372 xchar_t xc;
02373 if (xis.get(xc))
02374 {
02375 xis.putback(xc);
02376 if (xc!=XCHAR_GREATER_THAN_SIGN) read_system_literal(xis,system_literal);
02377 }
02378 } else {
02379 read_xstring(xis,"SYSTEM",_(L"Parsing 'SYSTEM' for a notation declaration.\nXML Definition : NotationDecl ::= '<!NOTATION' S name S (ExternalID | PublicID) S? '>' "));
02380 read_space(xis);
02381 read_system_literal(xis,system_literal);
02382 }
02383
02384 read_optionnal_space(xis);
02385 read_xchar(xis,XCHAR_GREATER_THAN_SIGN,_(L"Parsing a char '>' for a notation declaration.\nXML Definition : NotationDecl ::= '<!NOTATION' S name S (ExternalID | PublicID) S? '>' "));
02386
02387 return xis;
02388 }
02389
02390
02391
02392
02393
02394
02395
02396
02397
02398 xistream& read_notation_decl(xistream& xis, int nb_read)
02399 {
02400 xstring name, system_literal, pub_id_literal;
02401 read_notation_decl(xis,name,system_literal,pub_id_literal,nb_read);
02402 xis.context.add_notation_decl(name,system_literal,pub_id_literal);
02403 return xis;
02404 }
02405
02406
02407
02408
02409
02410
02411
02412 xostream& write_open_stag(xostream& xos, const xstring& name, const XIMOL_XML_NAMESPACE_PATH::attributes& att, const xstring& uri)
02413 {
02414 if (xos.context.is_open_stag())
02415 write_stag(xos,xos.context.get_level_tag(),xos.context.get_level_short_ns_tag());
02416
02417 xos.context.add_new_level(uri,name,att).set_open_stag();
02418 return xos;
02419 }
02420
02421
02422
02423
02424
02425
02426
02427 xostream& write_open_stag(xostream& xos, const xstring& name, const xstring& uri)
02428 {
02429 XIMOL_XML_NAMESPACE_PATH::attributes att;
02430 return write_open_stag(xos,name,att,uri);
02431 }
02432
02433
02434
02435
02436
02437
02438
02439 xostream& write_stag(xostream& xos, const xstring& name, const XIMOL_XML_NAMESPACE_PATH::attributes& att, const xstring& uri)
02440 {
02441 write_xchar(xos,XCHAR_LESS_THAN_SIGN);
02442 if (xos.context.is_open_stag())
02443 {
02444
02445 xos.context.add_level_attributes(att);
02446 } else {
02447 xos.context.add_new_level(uri,name,att);
02448 }
02449 write_qname(xos,xos.context.get_level_tag(),xos.context.get_level_short_ns_tag());
02450 xos << xos.context.get_level_attributes();
02451 write_xchar(xos,XCHAR_GREATER_THAN_SIGN);
02452
02453 xos.context.close_open_stag();
02454 return xos;
02455 }
02456
02457
02458
02459
02460
02461
02462
02463 xostream& write_stag(xostream& xos, const xstring& name)
02464 {
02465 XIMOL_XML_NAMESPACE_PATH::attributes att;
02466 return write_stag(xos,name,att);
02467 }
02468
02469
02470
02471
02472
02473
02474
02475 xostream& write_stag(xostream& xos, const xstring& name, const xstring& uri)
02476 {
02477 XIMOL_XML_NAMESPACE_PATH::attributes att;
02478 return write_stag(xos,name,att,uri);
02479 }
02480
02481
02482
02483
02484
02485
02486
02487 xistream& read_open_stag(xistream& xis, xstring& name, XIMOL_XML_NAMESPACE_PATH::attributes& att, xstring& uri, int nb_read)
02488 {
02489 if (! (xis.good()) ) return xis;
02490 clear_string(uri);
02491 clear_string(name);
02492 att.clear();
02493
02494 if (xis.context.is_open_stag())
02495 {
02496 name=xis.context.get_level_tag();
02497 uri=xis.context.get_level_ns_tag();
02498 att=xis.context.get_level_attributes();
02499 return xis;
02500 }
02501
02502 switch(nb_read){
02503 case 0: read_xchar(xis,XCHAR_LESS_THAN_SIGN, _(L"comment parsing a '<'.XML Definition : stag ::= '<' name (S Attribute)* S? '>'") );
02504 }
02505
02506 xstring short_ns;
02507 read_qname(xis,name,short_ns);
02508 read_optionnal_space(xis);
02509 xis>>att;
02510 read_optionnal_space(xis);
02511
02512 XIMOL_XML_NAMESPACE_PATH::attributes::const_ns_iterator itr_uri =
02513 att.find_namespace(short_ns);
02514
02515 if(itr_uri != att.ns_end())
02516 uri = itr_uri->first;
02517
02518 if(uri.empty()) uri = xis.context.get_namespace(short_ns);
02519 if(uri.empty()) uri = short_ns;
02520
02521 if(uri.empty()) {
02522 itr_uri = att.find_namespace();
02523
02524 if(itr_uri != att.ns_end())
02525 uri = itr_uri->first;
02526 }
02527
02528 if(uri.empty()) uri = xis.context.get_default_namespace();
02529
02530 xis.context.add_new_level(uri,name,att).set_open_stag();
02531
02532 xchar_t xc;
02533 if (! xis.get(xc))
02534 XIMOL_THROW << _(L"Parsing a char '>' for a notation declaration.\nSTag ::= '<' name (S Attribute)* S? '>'")
02535 << XIMOL_AS_ERROR;
02536
02537 if (xc==XCHAR_SOLIDUS)
02538 {
02539 xis.context.set_open_etag();
02540 } else {
02541 xis.putback(xc);
02542 }
02543
02544 read_xchar(xis,XCHAR_GREATER_THAN_SIGN,_(L"Parsing a char '>' for a notation declaration.\nSTag ::= '<' name (S Attribute)* S? '>'"));
02545
02546 return xis;
02547 }
02548
02549
02550
02551
02552
02553
02554
02555 xistream& read_open_stag(xistream& xis, xstring& name, xstring & uri, int nb_read)
02556 {
02557 XIMOL_XML_NAMESPACE_PATH::attributes att;
02558 return read_open_stag(xis,name,att,uri,nb_read);
02559 }
02560
02561
02562
02563
02564
02565
02566
02567 xistream& read_open_stag(xistream& xis, xstring& name, int nb_read)
02568 {
02569 xstring uri;
02570 return read_open_stag(xis,name,uri,nb_read);
02571 }
02572
02573
02574
02575
02576
02577
02578
02579 xistream& read_stag(xistream& xis, xstring& name, XIMOL_XML_NAMESPACE_PATH::attributes& att, xstring& uri, int nb_read)
02580 {
02581 if (! (xis.good()) ) return xis;
02582 clear_string(uri);
02583 clear_string(name);
02584 att.clear();
02585
02586 if (xis.context.is_open_stag())
02587 {
02588 name=xis.context.get_level_tag();
02589 uri=xis.context.get_level_ns_tag();
02590 att=xis.context.get_level_attributes();
02591 } else {
02592 read_open_stag(xis,name,att,uri,nb_read);
02593 }
02594
02595 xis.context.close_open_stag();
02596
02597 return xis;
02598 }
02599
02600
02601
02602
02603
02604
02605
02606 xistream& read_stag(xistream& xis, xstring& name, xstring& uri, int nb_read)
02607 {
02608 XIMOL_XML_NAMESPACE_PATH::attributes att;
02609 return read_stag(xis,name,att,uri,nb_read);
02610 }
02611
02612
02613
02614
02615
02616
02617
02618 xistream& read_stag(xistream& xis, xstring& name, XIMOL_XML_NAMESPACE_PATH::attributes& att, int nb_read)
02619 {
02620 xstring uri;
02621 return read_stag(xis,name,att,uri,nb_read);
02622 }
02623
02624
02625
02626
02627
02628
02629
02630 xistream& read_stag(xistream& xis, xstring& name, int nb_read)
02631 {
02632 xstring uri;
02633 return read_stag(xis,name,uri,nb_read);
02634 }
02635
02636
02637
02638
02639
02640
02641
02642 xostream& write_etag(xostream& xos, const xstring& name)
02643 {
02644 write_xchar(xos,XCHAR_LESS_THAN_SIGN);
02645 write_xchar(xos,XCHAR_SOLIDUS);
02646 write_qname(xos,name,xos.context.get_level_short_ns_tag());
02647 xos.context.destroy_level();
02648 write_xchar(xos,XCHAR_GREATER_THAN_SIGN);
02649 return xos;
02650 }
02651
02652
02653
02654
02655
02656
02657
02658 xostream& write_etag(xostream& xos, const xstring& name, const xstring& uri)
02659 {
02660 write_xchar(xos,XCHAR_LESS_THAN_SIGN);
02661 write_xchar(xos,XCHAR_SOLIDUS);
02662 write_qname(xos,name,xos.context.get_short_namespace(uri));
02663 xos.context.destroy_level();
02664 write_xchar(xos,XCHAR_GREATER_THAN_SIGN);
02665 return xos;
02666 }
02667
02668
02669
02670
02671
02672
02673
02674 xostream& write_etag(xostream& xos)
02675 {
02676 write_xchar(xos,XCHAR_LESS_THAN_SIGN);
02677 write_xchar(xos,XCHAR_SOLIDUS);
02678 write_qname(xos,xos.context.get_level_tag(),xos.context.get_level_short_ns_tag());
02679 xos.context.destroy_level();
02680 write_xchar(xos,XCHAR_GREATER_THAN_SIGN);
02681 return xos;
02682 }
02683
02684
02685
02686
02687
02688
02689
02690 xistream& read_etag(xistream& xis, xstring& name, xstring& uri, int nb_read)
02691 {
02692 if (! (xis.good()) ) return xis;
02693 clear_string(uri);
02694 clear_string(name);
02695
02696 if (xis.context.is_open_etag())
02697 {
02698 uri=xis.context.get_level_ns_tag();
02699 name=xis.context.get_level_tag();
02700 xis.context.close_open_etag();
02701 xis.context.destroy_level();
02702 return xis;
02703 }
02704
02705
02706 switch(nb_read){
02707 case 0: read_xchar(xis,XCHAR_LESS_THAN_SIGN, _(L"comment parsing a '<'.XML Definition : stag ::= '<' name (S Attribute)* S? '>'") );
02708 case 1: read_xchar(xis,XCHAR_SOLIDUS, _(L"comment parsing a '/'.XML Definition : stag ::= '<' name (S Attribute)* S? '>'") );
02709 }
02710 xstring short_ns;
02711 read_qname(xis,name,short_ns);
02712 uri=xis.context.get_namespace(short_ns);
02713
02714 read_optionnal_space(xis);
02715 read_xchar(xis,XCHAR_GREATER_THAN_SIGN,_(L"Parsing a char '>' for a notation declaration.\nSTag ::= '<' name (S Attribute)* S? '>'"));
02716
02717 xis.context.destroy_level();
02718
02719 return xis;
02720 }
02721
02722
02723
02724
02725
02726
02727
02728 xistream& read_etag(xistream& xis, xstring& name, int nb_read)
02729 {
02730 xstring uri;
02731 return read_etag(xis,name,uri,nb_read);
02732 }
02733
02734
02735
02736
02737
02738
02739
02740 xistream& read_etag(xistream& xis, int nb_read)
02741 {
02742 if (! (xis.good()) ) return xis;
02743 xstring tag,result_tag(xis.context.get_level_tag()),uri,result_uri(xis.context.get_level_ns_tag());
02744
02745 read_etag(xis,tag,uri,nb_read);
02746
02747 if ((tag==result_tag)&&
02748 (uri==result_uri))
02749 return xis;
02750
02751 xis.setstate(std::ios::failbit);
02752 return xis;
02753 }
02754
02755
02756
02757
02758
02759
02760
02761
02762
02763 xostream& write_pe_def(xostream& xos, const xstring& entity_value, const xstring& system_literal, const xstring& pub_id_literal)
02764 {
02765 if (! entity_value.empty()) return write_entity_value(xos,entity_value);
02766 return write_external_id(xos,system_literal,pub_id_literal);
02767 }
02768
02769
02770
02771
02772
02773
02774
02775
02776
02777 xistream& read_pe_def(xistream& xis, xstring& entity_value, xstring& system_literal, xstring& pub_id_literal)
02778 {
02779 if (! (xis.good()) ) return xis;
02780 clear_string(entity_value);
02781 clear_string(system_literal);
02782 clear_string(pub_id_literal);
02783
02784 xchar_t xc;
02785 if ( (xis.get(xc))
02786 &&( (xc==XCHAR_LATIN_CAPITAL_LETTER_P)
02787 ||(xc==XCHAR_LATIN_CAPITAL_LETTER_S)
02788 ))
02789 {
02790 xis.putback(xc);
02791 read_external_id(xis,system_literal,pub_id_literal);
02792 } else {
02793 xis.putback(xc);
02794 read_entity_value(xis,entity_value);
02795 }
02796
02797 return xis;
02798 }
02799
02800
02801
02802
02803
02804
02805
02806
02807
02808 xostream& write_ndata_decl(xostream& xos, const xstring& name)
02809 {
02810 write_space(xos);
02811 write_xchar(xos,XCHAR_LATIN_CAPITAL_LETTER_N);
02812 write_xchar(xos,XCHAR_LATIN_CAPITAL_LETTER_D);
02813 write_xchar(xos,XCHAR_LATIN_CAPITAL_LETTER_A);
02814 write_xchar(xos,XCHAR_LATIN_CAPITAL_LETTER_T);
02815 write_xchar(xos,XCHAR_LATIN_CAPITAL_LETTER_A);
02816 write_space(xos);
02817 write_name(xos,name);
02818 return xos;
02819 }
02820
02821
02822
02823
02824
02825
02826
02827
02828
02829 xistream& read_ndata_decl(xistream& xis, xstring& name, int nb_read)
02830 {
02831 switch (nb_read) {
02832 case 0: read_space(xis);
02833 case 1: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_N, _(L"comment parsing a 'N'.XML Definition : NDataDecl ::= S 'NDATA' S name ") );
02834 case 2: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_D, _(L"comment parsing a 'D'.XML Definition : NDataDecl ::= S 'NDATA' S name ") );
02835 case 3: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_A, _(L"comment parsing a 'A'.XML Definition : NDataDecl ::= S 'NDATA' S name ") );
02836 case 4: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_T, _(L"comment parsing a 'T'.XML Definition : NDataDecl ::= S 'NDATA' S name ") );
02837 case 5: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_A, _(L"comment parsing a 'A'.XML Definition : NDataDecl ::= S 'NDATA' S name ") );
02838 case 6: read_space(xis);
02839 }
02840
02841 read_name(xis,name);
02842 return xis;
02843 }
02844
02845
02846
02847
02848
02849
02850
02851
02852
02853 xostream& write_entity_def(xostream& xos, const xstring& entity_value, const xstring& system_literal, const xstring& pub_id_literal, const xstring& ndata_name)
02854 {
02855 if (! entity_value.empty()) return write_entity_value(xos,entity_value);
02856 write_external_id(xos,system_literal,pub_id_literal);
02857 if (! ndata_name.empty()) write_ndata_decl(xos,ndata_name);
02858 return xos;
02859 }
02860
02861
02862
02863
02864
02865
02866
02867
02868
02869 xistream& read_entity_def(xistream& xis, xstring& entity_value, xstring& system_literal, xstring& pub_id_literal, xstring& ndata_name)
02870 {
02871 if (! (xis.good()) ) return xis;
02872 clear_string(entity_value);
02873 clear_string(system_literal);
02874 clear_string(pub_id_literal);
02875 clear_string(ndata_name);
02876
02877 xchar_t xc;
02878 if ( (xis.get(xc))
02879 &&( (xc==XCHAR_LATIN_CAPITAL_LETTER_P)
02880 ||(xc==XCHAR_LATIN_CAPITAL_LETTER_S)
02881 ))
02882 {
02883 xis.putback(xc);
02884 read_external_id(xis,system_literal,pub_id_literal);
02885 read_optionnal_space(xis);
02886 if (! xis.get(xc)) return xis;
02887 xis.putback(xc);
02888 if (xc!=XCHAR_LATIN_CAPITAL_LETTER_N) return xis;
02889 read_ndata_decl(xis,ndata_name,1);
02890
02891 } else {
02892 xis.putback(xc);
02893 read_entity_value(xis,entity_value);
02894 }
02895
02896 return xis;
02897 }
02898
02899
02900
02901
02902
02903
02904
02905
02906
02907 xostream& write_pe_decl(xostream& xos, const xstring& entity_name, const xstring& entity_value, const xstring& system_literal, const xstring & pubid_literal)
02908 {
02909 xos<<"<!ENTITY";
02910 write_space(xos);
02911 write_xchar(xos,XCHAR_PERCENT_SIGN);
02912 write_space(xos);
02913 write_name(xos,entity_name);
02914 write_space(xos);
02915 write_pe_def(xos,entity_value,system_literal,pubid_literal);
02916 write_xchar(xos,XCHAR_GREATER_THAN_SIGN);
02917 return xos;
02918 }
02919
02920
02921
02922
02923
02924
02925
02926
02927
02928 xistream& read_pe_decl(xistream& xis, xstring& entity_name, xstring& entity_value, xstring& system_literal, xstring & pubid_literal, int nb_read)
02929 {
02930
02931 switch (nb_read){
02932 case 0: read_xchar(xis,XCHAR_LESS_THAN_SIGN, _(L"comment parsing a '<'.XML Definition : PEDecl ::= '<!ENTITY' S '%' S name S PEDef S? '>'") );
02933 case 1: read_xchar(xis,XCHAR_EXCLAMATION_MARK, _(L"comment parsing a '!'.XML Definition : PEDecl ::= '<!ENTITY' S '%' S name S PEDef S? '>'") );
02934 case 2: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_E, _(L"comment parsing a 'E'.XML Definition : PEDecl ::= '<!ENTITY' S '%' S name S PEDef S? '>'") );
02935 case 3: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_N, _(L"comment parsing a 'N'.XML Definition : PEDecl ::= '<!ENTITY' S '%' S name S PEDef S? '>'") );
02936 case 4: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_T, _(L"comment parsing a 'T'.XML Definition : PEDecl ::= '<!ENTITY' S '%' S name S PEDef S? '>'") );
02937 case 5: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_I, _(L"comment parsing a 'I'.XML Definition : PEDecl ::= '<!ENTITY' S '%' S name S PEDef S? '>'") );
02938 case 6: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_T, _(L"comment parsing a 'T'.XML Definition : PEDecl ::= '<!ENTITY' S '%' S name S PEDef S? '>'") );
02939 case 7: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_Y, _(L"comment parsing a 'Y'.XML Definition : PEDecl ::= '<!ENTITY' S '%' S name S PEDef S? '>'") );
02940 case 8: read_space(xis);
02941 case 9: read_xchar(xis,XCHAR_PERCENT_SIGN, _(L"comment parsing a '%'.XML Definition : PEDecl ::= '<!ENTITY' S '%' S name S PEDef S? '>'") );
02942 case 10: read_space(xis);
02943 }
02944
02945 read_name(xis,entity_name);
02946 read_space(xis);
02947 read_pe_def(xis,entity_value,system_literal,pubid_literal);
02948 read_optionnal_space(xis);
02949 read_xchar(xis,XCHAR_GREATER_THAN_SIGN, _(L"comment parsing a '>'.XML Definition : PEDecl ::= '<!ENTITY' S '%' S name S PEDef S? '>'") );
02950
02951 xis.context.add_paramter_entity(entity_name,entity_value,system_literal,pubid_literal);
02952 return xis;
02953 }
02954
02955
02956
02957
02958
02959
02960
02961
02962
02963 xistream& read_pe_decl(xistream& xis,int nb_read)
02964 {
02965 xstring name, entity_value,system_literal,pubidliteral;
02966 return read_pe_decl(xis,name, entity_value,system_literal,pubidliteral,nb_read);
02967 }
02968
02969
02970
02971
02972
02973
02974
02975
02976
02977 xostream& write_ge_decl(xostream& xos, const xstring& entity_name, const xstring& entity_value, const xstring& system_literal, const xstring & pubid_literal, const xstring & ndata_name)
02978 {
02979 xos<<"<!ENTITY";
02980 write_space(xos);
02981 write_name(xos,entity_name);
02982 write_space(xos);
02983 write_entity_def(xos,entity_value,system_literal,pubid_literal,ndata_name);
02984 write_xchar(xos,XCHAR_GREATER_THAN_SIGN);
02985 return xos;
02986 }
02987
02988
02989
02990
02991
02992
02993
02994
02995
02996 xistream& read_ge_decl(xistream& xis, xstring& entity_name, xstring& entity_value, xstring& system_literal, xstring & pubid_literal, xstring & ndata_name, int nb_read)
02997 {
02998
02999 switch (nb_read){
03000 case 0: read_xchar(xis,XCHAR_LESS_THAN_SIGN, _(L"comment parsing a '<'.XML Definition : PEDecl ::= '<!ENTITY' S '%' S name S PEDef S? '>'") );
03001 case 1: read_xchar(xis,XCHAR_EXCLAMATION_MARK, _(L"comment parsing a '!'.XML Definition : PEDecl ::= '<!ENTITY' S '%' S name S PEDef S? '>'") );
03002 case 2: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_E, _(L"comment parsing a 'E'.XML Definition : PEDecl ::= '<!ENTITY' S '%' S name S PEDef S? '>'") );
03003 case 3: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_N, _(L"comment parsing a 'N'.XML Definition : PEDecl ::= '<!ENTITY' S '%' S name S PEDef S? '>'") );
03004 case 4: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_T, _(L"comment parsing a 'T'.XML Definition : PEDecl ::= '<!ENTITY' S '%' S name S PEDef S? '>'") );
03005 case 5: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_I, _(L"comment parsing a 'I'.XML Definition : PEDecl ::= '<!ENTITY' S '%' S name S PEDef S? '>'") );
03006 case 6: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_T, _(L"comment parsing a 'T'.XML Definition : PEDecl ::= '<!ENTITY' S '%' S name S PEDef S? '>'") );
03007 case 7: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_Y, _(L"comment parsing a 'Y'.XML Definition : PEDecl ::= '<!ENTITY' S '%' S name S PEDef S? '>'") );
03008 case 8: read_space(xis);
03009 }
03010
03011 read_name(xis,entity_name);
03012 read_space(xis);
03013 read_entity_def(xis,entity_value,system_literal,pubid_literal,ndata_name);
03014 read_optionnal_space(xis);
03015 read_xchar(xis,XCHAR_GREATER_THAN_SIGN, _(L"comment parsing a '>'.XML Definition : PEDecl ::= '<!ENTITY' S '%' S name S PEDef S? '>'") );
03016
03017 xis.context.add_entity(entity_name,entity_value,system_literal,pubid_literal,ndata_name);
03018 return xis;
03019 }
03020
03021
03022
03023
03024
03025
03026
03027
03028
03029 xistream& read_ge_decl(xistream& xis,int nb_read)
03030 {
03031 xstring name, entity_value,system_literal,pubidliteral,ndata_name;
03032 return read_ge_decl(xis,name, entity_value,system_literal,pubidliteral,ndata_name,nb_read);
03033 }
03034
03035
03036
03037
03038
03039
03040
03041
03042
03043 xistream& read_misc(xistream& xis)
03044 {
03045 xchar_t xc;
03046 if (! xis.get(xc))
03047 XIMOL_THROW << _(L"Reading Misc, and there is no more char aviable")
03048 <<XIMOL_AS_ERROR;
03049 if (is_space(xc)) return read_optionnal_space(xis);
03050 if (xc==XCHAR_LESS_THAN_SIGN)
03051 {
03052 xc=xis.front();
03053 xis.putback(XCHAR_LESS_THAN_SIGN);
03054 if (xc==XCHAR_EXCLAMATION_MARK) return read_comment(xis);
03055 if (xc==XCHAR_QUESTION_MARK) return read_pi(xis);
03056 }
03057 return xis;
03058 }
03059
03060
03061
03062
03063
03064
03065
03066
03067
03068 xostream& write_prolog(xostream& xos)
03069 {
03070 write_xml_decl(xos);
03071 return xos;
03072 }
03073
03074
03075
03076
03077 class codecvt_ximol_raw_data
03078 :public ::std::codecvt<wchar_t, char, mbstate_t>
03079 {
03080 public:
03081 typedef wchar_t intern_type;
03082
03083 typedef char extern_type;
03084 typedef mbstate_t state_type;
03085 public:
03086 explicit codecvt_ximol_raw_data(size_t refs = 0)
03087 :std::codecvt<wchar_t, char, mbstate_t>(refs)
03088 {}
03089 virtual ~codecvt_ximol_raw_data(){}
03090 protected:
03091 virtual result do_out (state_type& state,
03092 const intern_type* from,
03093 const intern_type* from_end,
03094 const intern_type*& from_next,
03095 extern_type* to,
03096 extern_type* to_limit,
03097 extern_type*& to_next) const
03098 {
03099 ptrdiff_t len = XIMOL_MIN(from_end - from, to_limit - to);
03100 ::std::copy(from, from + len, to);
03101 to_next = to + len;
03102 return ok;
03103 }
03104 virtual result do_in (state_type& state,
03105 const extern_type* from,
03106 const extern_type* from_end,
03107 const extern_type*& from_next,
03108 intern_type* to,
03109 intern_type* to_limit,
03110 intern_type*& to_next) const
03111 {
03112 ptrdiff_t len = XIMOL_MIN((from_end - from), (to_limit - to));
03113 ::std::copy((unsigned char*)from, (unsigned char*)(from + len), to);
03114 from_next = from + len;
03115 to_next = to + len;
03116 return ok;
03117 }
03118
03119 virtual result do_unshift (state_type& state,
03120 extern_type* to,
03121 extern_type* to_limit,
03122 extern_type*& to_next) const
03123 {to_next = to; return noconv;}
03124
03125 virtual int do_encoding () const throw ()
03126 {return 1;}
03127
03128 virtual bool do_always_noconv() const throw ()
03129 {return false;}
03130
03131 virtual int do_length (const state_type& state,
03132 const extern_type* from,
03133 const extern_type* end,
03134 size_t max) const
03135 {return (int)XIMOL_MIN((size_t) (end - from), max);}
03136
03137 virtual int do_max_length () const throw (){return 1;}
03138
03139 private:
03140 codecvt_ximol_raw_data(const codecvt_ximol_raw_data&){}
03141 codecvt_ximol_raw_data& operator = (const codecvt_ximol_raw_data&){ return *this; }
03142 };
03143
03144 void BeforeBOM(xistream& xis)
03145 {
03146 typedef ::std::codecvt<xchar_t, char, mbstate_t> FacetType;
03147 xis.imbue(XIMOL_ADD_FACET(xis.getloc(), static_cast<FacetType*>(new codecvt_ximol_raw_data())));
03148
03149
03150
03151
03152
03153
03154
03155
03156 }
03157
03158 void AfterBOM(xistream& xis)
03159 {
03160 XIMOL_ENCODERS_USING_NAMESPACE;
03161
03162 prepare_ios(xis,"UTF-8");
03163
03164
03165
03166
03167
03168
03169
03170
03171 }
03172
03173
03174
03175
03176
03177
03178
03179 size_t read_bom(xistream& xis)
03180 {
03181 BeforeBOM(xis);
03182 xchar_t BOM[5];
03183 xis.get(BOM[0]);
03184
03185 switch (BOM[0])
03186 {
03187 case 0x00:
03188 xis.get(BOM[1]);
03189 switch (BOM[1])
03190 {
03191 case 0x00:
03192 xis.get(BOM[2]);
03193 xis.get(BOM[3]);
03194 if (BOM[3]==0x3C) xis.putback(0x3C);
03195 AfterBOM(xis);
03196 xis.encoding("UCS-4BE");
03197 return 0;
03198 break;
03199 default:
03200 xis.putback(BOM[1]);
03201 AfterBOM(xis);
03202 xis.encoding("UTF-16BE");
03203 return 0;
03204 }
03205 break;
03206
03207
03208 case 0x2B:
03209 xis.get(BOM[1]);
03210 if (BOM[1]!=0x2F)
03211 {
03212 xis.putback(BOM[1]);
03213 xis.putback(BOM[0]);
03214 AfterBOM(xis);
03215 xis.encoding("UTF-8");
03216 return 0;
03217 }
03218 xis.get(BOM[2]);
03219 if (BOM[2]!=0x76)
03220 {
03221 xis.putback(BOM[2]);
03222 xis.putback(BOM[1]);
03223 xis.putback(BOM[0]);
03224 AfterBOM(xis);
03225 xis.encoding("UTF-8");
03226 return 0;
03227 }
03228 xis.get(BOM[3]);
03229 if (BOM[3]!=0x38)
03230 {
03231 xis.putback(BOM[3]);
03232 xis.putback(BOM[2]);
03233 xis.putback(BOM[1]);
03234 xis.putback(BOM[0]);
03235 AfterBOM(xis);
03236 xis.encoding("UTF-8");
03237 return 0;
03238 }
03239 xis.get(BOM[4]);
03240 if (BOM[4]!=0x2D)
03241 {
03242 xis.putback(BOM[4]);
03243 xis.putback(BOM[3]);
03244 xis.putback(BOM[2]);
03245 xis.putback(BOM[1]);
03246 xis.putback(BOM[0]);
03247 AfterBOM(xis);
03248 xis.encoding("UTF-8");
03249 return 0;
03250 }
03251
03252 AfterBOM(xis);
03253 xis.encoding("UTF-7");
03254 return 0;
03255
03256 case 0x3C:
03257 xis.get(BOM[1]);
03258 switch (BOM[1])
03259 {
03260 case 0x00:
03261 xis.get(BOM[2]);
03262 xis.get(BOM[3]);
03263 if (BOM[2]==0x00) {
03264 xis.putback(0x3C);
03265 AfterBOM(xis);
03266 xis.encoding("UCS-4LE");
03267 return 0;
03268 }
03269 xis.putback(BOM[3]);
03270 AfterBOM(xis);
03271 xis.encoding("UTF-16LE");
03272 return 1;
03273 break;
03274 default:
03275 xis.putback(BOM[1]);
03276 AfterBOM(xis);
03277 xis.encoding("UTF-8");
03278 return 1;
03279 }
03280 break;
03281 case 0xEF:
03282 xis.get(BOM[1]);
03283 xis.get(BOM[2]);
03284 if ((BOM[1]!=0xBB) || (BOM[2]!=0xBF))
03285 XIMOL_THROW << _(L"Bad Byte Order Mark for UTF-8.")
03286 << XIMOL_AS_ERROR;
03287 AfterBOM(xis);
03288 xis.encoding("UTF-8");
03289 return 0;
03290 break;
03291 case 0xFE:
03292 xis.get(BOM[1]);
03293 if (BOM[1]!=0xFF)
03294 XIMOL_THROW << _(L"Bad Byte Order Mark for UTF-16.")
03295 << XIMOL_AS_ERROR;
03296 AfterBOM(xis);
03297 xis.encoding("UTF-16BE");
03298 return 0;
03299 break;
03300 case 0xFF:
03301 xis.get(BOM[1]);
03302 xis.get(BOM[2]);
03303 xis.get(BOM[3]);
03304 if (BOM[1]!=0xFE)
03305 XIMOL_THROW << _(L"Bad Byte Order Mark for UTF-16.")
03306 << XIMOL_AS_ERROR;
03307 if (BOM[2]==0x00)
03308 {
03309 AfterBOM(xis);
03310 xis.encoding("UCS-4LE");
03311 return 0;
03312 }
03313 xis.putback( * ((xchar_t*)(&(BOM[2]))) );
03314 AfterBOM(xis);
03315 xis.encoding("UTF-16LE");
03316 return 0;
03317 break;
03318 }
03319 xis.putback(BOM[0]);
03320 AfterBOM(xis);
03321 xis.encoding("UTF-8");
03322 return 0;
03323 }
03324
03325
03326
03327
03328 xistream& read_prolog_question(xistream& xis, int nb_read)
03329 {
03330
03331 switch (nb_read){
03332 case 0: read_xchar(xis,XCHAR_LESS_THAN_SIGN, _(L"comment parsing a '<'.") );
03333 case 1: read_xchar(xis,XCHAR_QUESTION_MARK, _(L"comment parsing a '?'.") );
03334 }
03335 xchar_t xc(xis.front());
03336 switch(xc)
03337 {
03338 case XCHAR_LATIN_CAPITAL_LETTER_X:
03339 case XCHAR_LATIN_SMALL_LETTER_X:
03340 read_xml_decl(xis,2);
03341
03342 break;
03343 default:
03344 read_pi(xis,2);
03345 }
03346 return xis;
03347 }
03348
03349
03350
03351
03352
03353
03354
03355
03356
03357 xistream& read_doctype_decl(xistream& xis, int nb_read)
03358 {
03359 if (! (xis.good()) ) return xis;
03360
03361
03362 switch (nb_read){
03363 case 0: read_xchar(xis,XCHAR_LESS_THAN_SIGN, _(L"comment parsing a '<'.XML Definition : doctypedecl ::= '<!DOCTYPE' S name (S ExternalID)? S? ('[' (markupdecl | DeclSep)* ']' S?)? '>'") );
03364 case 1: read_xchar(xis,XCHAR_EXCLAMATION_MARK, _(L"comment parsing a '!'.XML Definition : doctypedecl ::= '<!DOCTYPE' S name (S ExternalID)? S? ('[' (markupdecl | DeclSep)* ']' S?)? '>'") );
03365 case 2: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_D, _(L"comment parsing a 'D'.XML Definition : doctypedecl ::= '<!DOCTYPE' S name (S ExternalID)? S? ('[' (markupdecl | DeclSep)* ']' S?)? '>'") );
03366 case 3: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_O, _(L"comment parsing a 'O'.XML Definition : doctypedecl ::= '<!DOCTYPE' S name (S ExternalID)? S? ('[' (markupdecl | DeclSep)* ']' S?)? '>'") );
03367 case 4: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_C, _(L"comment parsing a 'C'.XML Definition : doctypedecl ::= '<!DOCTYPE' S name (S ExternalID)? S? ('[' (markupdecl | DeclSep)* ']' S?)? '>'") );
03368 case 5: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_T, _(L"comment parsing a 'T'.XML Definition : doctypedecl ::= '<!DOCTYPE' S name (S ExternalID)? S? ('[' (markupdecl | DeclSep)* ']' S?)? '>'") );
03369 case 6: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_Y, _(L"comment parsing a 'Y'.XML Definition : doctypedecl ::= '<!DOCTYPE' S name (S ExternalID)? S? ('[' (markupdecl | DeclSep)* ']' S?)? '>'") );
03370 case 7: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_P, _(L"comment parsing a 'P'.XML Definition : doctypedecl ::= '<!DOCTYPE' S name (S ExternalID)? S? ('[' (markupdecl | DeclSep)* ']' S?)? '>'") );
03371 case 8: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_E, _(L"comment parsing a 'E'.XML Definition : doctypedecl ::= '<!DOCTYPE' S name (S ExternalID)? S? ('[' (markupdecl | DeclSep)* ']' S?)? '>'") );
03372 case 9: read_space(xis);
03373 }
03374
03375 xstring name;
03376 read_name(xis,name);
03377 xis.context.set_doc_type_name(name);
03378 read_optionnal_space(xis);
03379
03380 xchar_t xc(xis.front());
03381 if (xc==XCHAR_GREATER_THAN_SIGN) return xis;
03382 if (xc!=XCHAR_LEFT_SQUARE_BRACKET)
03383 {
03384 xstring sys,pubid;
03385 read_external_id(xis,sys,pubid);
03386 xis.context.set_doctype_external_id(sys,pubid);
03387 read_optionnal_space(xis);
03388 xc=xis.front();
03389 }
03390 xis.pop_front();
03391 if (xc==XCHAR_GREATER_THAN_SIGN) return xis;
03392 if (xc!=XCHAR_LEFT_SQUARE_BRACKET)
03393 XIMOL_THROW << _(L"Error in the doctypedecl of the stream. witing for '['.")
03394 << XIMOL_AS_ERROR;
03395 bool loop_cont=true;
03396 while (loop_cont) {
03397 read_optionnal_space(xis);
03398 xc=xis.front();
03399 switch (xc)
03400 {
03401 case XCHAR_PERCENT_SIGN:
03402 read_pe_reference(xis,name);
03403 xis.putback(name);
03404 break;
03405 case XCHAR_RIGHT_SQUARE_BRACKET:
03406 xis.get(xc);
03407 loop_cont=false;
03408 break;
03409 case XCHAR_LESS_THAN_SIGN:
03410 xis.pop_front();
03411 xis.get(xc);
03412 switch(xc)
03413 {
03414 case XCHAR_QUESTION_MARK:
03415 read_pi(xis,2);
03416 break;
03417 case XCHAR_EXCLAMATION_MARK:
03418 read_doctype_element(xis,2);
03419 break;
03420 default:
03421 XIMOL_THROW << _(L"Error in the doctypedecl of the stream. witing for '?' or '!'.")
03422 << XIMOL_AS_ERROR;
03423 }
03424 break;
03425 default:
03426 XIMOL_THROW << _(L"Error in the doctypedecl of the stream. witing for '<' or '%' or ']'.")
03427 << XIMOL_AS_ERROR;
03428 }
03429 }
03430 read_xchar(xis,XCHAR_GREATER_THAN_SIGN, _(L"comment parsing a '>'.XML Definition : doctypedecl ::= '<!DOCTYPE' S name (S ExternalID)? S? ('[' (markupdecl | DeclSep)* ']' S?)? '>'") );
03431 return xis;
03432 }
03433
03434
03435
03436
03437 xistream& read_prolog_exclamation(xistream& xis, int nb_read)
03438 {
03439
03440 switch (nb_read){
03441 case 0: read_xchar(xis,XCHAR_LESS_THAN_SIGN, _(L"comment parsing a '<'.") );
03442 case 1: read_xchar(xis,XCHAR_EXCLAMATION_MARK, _(L"comment parsing a '!'.") );
03443 }
03444
03445 xchar_t xc(xis.front());
03446 switch(xc)
03447 {
03448 case XCHAR_HYPHEN_MINUS:
03449 read_comment(xis,2);
03450 break;
03451 case XCHAR_LATIN_CAPITAL_LETTER_D:
03452 read_doctype_decl(xis,2);
03453 }
03454 return xis;
03455 }
03456
03457
03458
03459
03460 xistream& read_doctype_element(xistream& xis, int nb_read)
03461 {
03462
03463 switch (nb_read) {
03464 case 0: read_xchar(xis,XCHAR_LESS_THAN_SIGN, _(L"comment parsing a '<'.") );
03465 case 1: read_xchar(xis,XCHAR_EXCLAMATION_MARK, _(L"comment parsing a '!'.") );
03466 }
03467 xchar_t xc(xis.front());
03468 switch(xc)
03469 {
03470 case XCHAR_HYPHEN_MINUS:
03471 read_comment(xis,2);
03472 break;
03473 case XCHAR_LATIN_CAPITAL_LETTER_N:
03474 read_notation_decl(xis,2);
03475 break;
03476 case XCHAR_LATIN_CAPITAL_LETTER_E:
03477 xis.pop_front();
03478 xis.get(xc);
03479 switch(xc)
03480 {
03481 case XCHAR_LATIN_CAPITAL_LETTER_L:
03482 read_element_decl(xis,4);
03483 break;
03484 case XCHAR_LATIN_CAPITAL_LETTER_N:
03485 read_entity_decl(xis,4);
03486 break;
03487 default:
03488 XIMOL_THROW << _(L"Error in the doctypedecl of the stream. witing for 'N' or 'L'.")
03489 << XIMOL_AS_ERROR;
03490 }
03491 break;
03492 case XCHAR_LATIN_CAPITAL_LETTER_A:
03493 read_att_list_decl(xis,2);
03494 break;
03495 default:
03496 XIMOL_THROW << _(L"Error in the doctypedecl of the stream. witing for '-' or 'A' or 'E' or 'N'.")
03497 << XIMOL_AS_ERROR;
03498 }
03499 return xis;
03500 }
03501
03502
03503
03504
03505
03506
03507
03508
03509
03510 xistream& read_prolog(xistream& xis)
03511 {
03512 int nb_read=0;
03513 nb_read=static_cast<int>(read_bom(xis));
03514 xchar_t xc;
03515 if (nb_read>=1) xis.putback(XCHAR_LESS_THAN_SIGN);
03516 bool loop_cont=true;
03517 while (loop_cont) {
03518 read_optionnal_space(xis);
03519 if ((! xis.get(xc)) || (xc != XCHAR_LESS_THAN_SIGN))
03520 break;
03521
03522 xc=xis.front();
03523 xis.putback(XCHAR_LESS_THAN_SIGN);
03524 switch (xc)
03525 {
03526 case XCHAR_QUESTION_MARK:
03527 read_prolog_question(xis);
03528 break;
03529
03530 case XCHAR_EXCLAMATION_MARK:
03531 read_prolog_exclamation(xis);
03532 break;
03533 default:
03534 loop_cont=false;
03535 }
03536 }
03537 return xis;
03538 }
03539
03540
03541
03542
03543
03544
03545
03546
03547
03548 xistream& read_element_decl(xistream& xis, int nb_read)
03549 {
03550 if (! (xis.good()) ) return xis;
03551
03552
03553 switch (nb_read) {
03554 case 0: read_xchar(xis,XCHAR_LESS_THAN_SIGN, _(L"comment parsing a '<'.XML Definition : elementdecl ::= '<!ELEMENT' S name S contentspec S? '>'") );
03555 case 1: read_xchar(xis,XCHAR_EXCLAMATION_MARK, _(L"comment parsing a '!'.XML Definition : elementdecl ::= '<!ELEMENT' S name S contentspec S? '>'") );
03556 case 2: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_E, _(L"comment parsing a 'E'.XML Definition : elementdecl ::= '<!ELEMENT' S name S contentspec S? '>'") );
03557 case 3: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_L, _(L"comment parsing a 'L'.XML Definition : elementdecl ::= '<!ELEMENT' S name S contentspec S? '>'") );
03558 case 4: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_E, _(L"comment parsing a 'E'.XML Definition : elementdecl ::= '<!ELEMENT' S name S contentspec S? '>'") );
03559 case 5: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_M, _(L"comment parsing a 'M'.XML Definition : elementdecl ::= '<!ELEMENT' S name S contentspec S? '>'") );
03560 case 6: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_E, _(L"comment parsing a 'E'.XML Definition : elementdecl ::= '<!ELEMENT' S name S contentspec S? '>'") );
03561 case 7: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_N, _(L"comment parsing a 'N'.XML Definition : elementdecl ::= '<!ELEMENT' S name S contentspec S? '>'") );
03562 case 8: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_T, _(L"comment parsing a 'T'.XML Definition : elementdecl ::= '<!ELEMENT' S name S contentspec S? '>'") );
03563 case 9: read_space(xis);
03564 }
03565
03566
03567 xchar_t xc;
03568 while ( (xis.get(xc)) && (xc!=XCHAR_GREATER_THAN_SIGN) )
03569 ;
03570 return xis;
03571 }
03572
03573
03574
03575
03576
03577
03578
03579
03580
03581 xistream& read_att_list_decl(xistream& xis, int nb_read)
03582 {
03583 if (! (xis.good()) ) return xis;
03584
03585
03586 switch (nb_read) {
03587 case 0: read_xchar(xis,XCHAR_LESS_THAN_SIGN, _(L"comment parsing a '<'.XML Definition : AttlistDecl ::= '<!ATTLIST' S name AttDef* S? '>' ") );
03588 case 1: read_xchar(xis,XCHAR_EXCLAMATION_MARK, _(L"comment parsing a '!'.XML Definition : AttlistDecl ::= '<!ATTLIST' S name AttDef* S? '>' ") );
03589 case 2: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_A, _(L"comment parsing a 'A'.XML Definition : AttlistDecl ::= '<!ATTLIST' S name AttDef* S? '>' ") );
03590 case 3: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_T, _(L"comment parsing a 'T'.XML Definition : AttlistDecl ::= '<!ATTLIST' S name AttDef* S? '>' ") );
03591 case 4: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_T, _(L"comment parsing a 'T'.XML Definition : AttlistDecl ::= '<!ATTLIST' S name AttDef* S? '>' ") );
03592 case 5: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_L, _(L"comment parsing a 'L'.XML Definition : AttlistDecl ::= '<!ATTLIST' S name AttDef* S? '>' ") );
03593 case 6: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_I, _(L"comment parsing a 'I'.XML Definition : AttlistDecl ::= '<!ATTLIST' S name AttDef* S? '>' ") );
03594 case 7: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_S, _(L"comment parsing a 'S'.XML Definition : AttlistDecl ::= '<!ATTLIST' S name AttDef* S? '>' ") );
03595 case 8: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_T, _(L"comment parsing a 'T'.XML Definition : AttlistDecl ::= '<!ATTLIST' S name AttDef* S? '>' ") );
03596 case 9: read_space(xis);
03597 }
03598
03599
03600 xchar_t xc;
03601 while ( (xis.get(xc)) && (xc!=XCHAR_GREATER_THAN_SIGN) )
03602 ;
03603 return xis;
03604 }
03605
03606
03607
03608
03609
03610
03611
03612
03613
03614 xistream& read_entity_decl(xistream& xis, int nb_read)
03615 {
03616 if (! (xis.good()) ) return xis;
03617
03618
03619 switch (nb_read) {
03620 case 0: read_xchar(xis,XCHAR_LESS_THAN_SIGN, _(L"comment parsing a '<'.XML Definition : EntityDecl ::= GEDecl | PEDecl ") );
03621 case 1: read_xchar(xis,XCHAR_EXCLAMATION_MARK, _(L"comment parsing a '!'.XML Definition : EntityDecl ::= GEDecl | PEDecl ") );
03622 case 2: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_E, _(L"comment parsing a 'E'.XML Definition : EntityDecl ::= GEDecl | PEDecl ") );
03623 case 3: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_N, _(L"comment parsing a 'N'.XML Definition : EntityDecl ::= GEDecl | PEDecl ") );
03624 case 4: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_T, _(L"comment parsing a 'T'.XML Definition : EntityDecl ::= GEDecl | PEDecl ") );
03625 case 5: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_I, _(L"comment parsing a 'I'.XML Definition : EntityDecl ::= GEDecl | PEDecl ") );
03626 case 6: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_T, _(L"comment parsing a 'T'.XML Definition : EntityDecl ::= GEDecl | PEDecl ") );
03627 case 7: read_xchar(xis,XCHAR_LATIN_CAPITAL_LETTER_Y, _(L"comment parsing a 'Y'.XML Definition : EntityDecl ::= GEDecl | PEDecl ") );
03628 case 8: read_space(xis);
03629 }
03630 xchar_t xc(xis.front());
03631 if (xc!=XCHAR_PERCENT_SIGN) read_ge_decl(xis,9);
03632 else read_pe_decl(xis,9);
03633 return xis;
03634 }
03635
03636 XIMOL_PARSER_END_NAMESPACE
03637