OW_XMLUnescape.cpp

Go to the documentation of this file.
00001 /* Generated by re2c 0.9.10.dev on Fri Aug 26 11:59:20 2005 */
00002 #line 1 "OW_XMLUnescape.re"
00003 /*******************************************************************************
00004 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved.
00005 *
00006 * Redistribution and use in source and binary forms, with or without
00007 * modification, are permitted provided that the following conditions are met:
00008 *
00009 *  - Redistributions of source code must retain the above copyright notice,
00010 *    this list of conditions and the following disclaimer.
00011 *
00012 *  - Redistributions in binary form must reproduce the above copyright notice,
00013 *    this list of conditions and the following disclaimer in the documentation
00014 *    and/or other materials provided with the distribution.
00015 *
00016 *  - Neither the name of Vintela, Inc. nor the names of its
00017 *    contributors may be used to endorse or promote products derived from this
00018 *    software without specific prior written permission.
00019 *
00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00021 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00022 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00023 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00024 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00025 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00026 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00029 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00030 * POSSIBILITY OF SUCH DAMAGE.
00031 *******************************************************************************/
00032 
00037 /* a simple lexical scanner to escape xml */
00038 #include "OW_config.h"
00039 #include "OW_XMLUnescape.hpp"
00040 #include "OW_StringBuffer.hpp"
00041 #include "OW_XMLParseException.hpp"
00042 #include "OW_Format.hpp"
00043 #include <limits.h> // for CHAR_MAX
00044 #include <stdlib.h> // for strtol
00045 
00046 namespace OW_NAMESPACE
00047 {
00048 
00049 String XMLUnescape(const char* escapedText, unsigned len)
00050 {
00051    StringBuffer rval(len);
00052    const char* begin = escapedText;
00053    const char* q;
00054    const char* thisTokStart = escapedText;
00055    #define YYCTYPE char
00056    #define YYCURSOR        begin
00057    #define YYLIMIT         begin
00058    #define YYMARKER        q
00059    #define YYFILL(n)
00060 start:
00061    
00062 #line 63 "OW_XMLUnescape.cpp"
00063 {
00064    YYCTYPE yych;
00065    unsigned int yyaccept;
00066    goto yy0;
00067    ++YYCURSOR;
00068 yy0:
00069    if((YYLIMIT - YYCURSOR) < 6) YYFILL(6);
00070    yych = *YYCURSOR;
00071    if(yych <= 0x00)  goto yy5;
00072    if(yych != '&')   goto yy4;
00073    goto yy2;
00074 yy2:  yyaccept = 0;
00075    yych = *(YYMARKER = ++YYCURSOR);
00076    if(yych <= 'f'){
00077       if(yych <= '#'){
00078          if(yych >= '#')   goto yy7;
00079          goto yy3;
00080       } else {
00081          if(yych == 'a')   goto yy9;
00082          goto yy3;
00083       }
00084    } else {
00085       if(yych <= 'l'){
00086          if(yych <= 'g')   goto yy12;
00087          if(yych >= 'l')   goto yy11;
00088          goto yy3;
00089       } else {
00090          if(yych == 'q')   goto yy10;
00091          goto yy3;
00092       }
00093    }
00094 yy3:
00095 #line 92 "OW_XMLUnescape.re"
00096 { rval += *(YYCURSOR-1); thisTokStart = YYCURSOR; goto start; }
00097 #line 98 "OW_XMLUnescape.cpp"
00098 yy4:  yych = *++YYCURSOR;
00099    goto yy3;
00100 yy5:  ++YYCURSOR;
00101    goto yy6;
00102 yy6:
00103 #line 93 "OW_XMLUnescape.re"
00104 { return rval.releaseString(); }
00105 #line 106 "OW_XMLUnescape.cpp"
00106 yy7:  yych = *++YYCURSOR;
00107    if(yych <= '/')   goto yy8;
00108    if(yych <= '9')   goto yy34;
00109    if(yych == 'x')   goto yy33;
00110    goto yy8;
00111 yy8:  YYCURSOR = YYMARKER;
00112    switch(yyaccept){
00113    case 0:  goto yy3;
00114    }
00115 yy9:  yych = *++YYCURSOR;
00116    if(yych == 'm')   goto yy24;
00117    if(yych == 'p')   goto yy25;
00118    goto yy8;
00119 yy10: yych = *++YYCURSOR;
00120    if(yych == 'u')   goto yy19;
00121    goto yy8;
00122 yy11: yych = *++YYCURSOR;
00123    if(yych == 't')   goto yy16;
00124    goto yy8;
00125 yy12: yych = *++YYCURSOR;
00126    if(yych != 't')   goto yy8;
00127    goto yy13;
00128 yy13: yych = *++YYCURSOR;
00129    if(yych != ';')   goto yy8;
00130    goto yy14;
00131 yy14: ++YYCURSOR;
00132    goto yy15;
00133 yy15:
00134 #line 65 "OW_XMLUnescape.re"
00135 { rval += '>'; thisTokStart = YYCURSOR; goto start; }
00136 #line 137 "OW_XMLUnescape.cpp"
00137 yy16: yych = *++YYCURSOR;
00138    if(yych != ';')   goto yy8;
00139    goto yy17;
00140 yy17: ++YYCURSOR;
00141    goto yy18;
00142 yy18:
00143 #line 66 "OW_XMLUnescape.re"
00144 { rval += '<'; thisTokStart = YYCURSOR; goto start; }
00145 #line 146 "OW_XMLUnescape.cpp"
00146 yy19: yych = *++YYCURSOR;
00147    if(yych != 'o')   goto yy8;
00148    goto yy20;
00149 yy20: yych = *++YYCURSOR;
00150    if(yych != 't')   goto yy8;
00151    goto yy21;
00152 yy21: yych = *++YYCURSOR;
00153    if(yych != ';')   goto yy8;
00154    goto yy22;
00155 yy22: ++YYCURSOR;
00156    goto yy23;
00157 yy23:
00158 #line 68 "OW_XMLUnescape.re"
00159 { rval += '\"'; thisTokStart = YYCURSOR; goto start; }
00160 #line 161 "OW_XMLUnescape.cpp"
00161 yy24: yych = *++YYCURSOR;
00162    if(yych == 'p')   goto yy30;
00163    goto yy8;
00164 yy25: yych = *++YYCURSOR;
00165    if(yych != 'o')   goto yy8;
00166    goto yy26;
00167 yy26: yych = *++YYCURSOR;
00168    if(yych != 's')   goto yy8;
00169    goto yy27;
00170 yy27: yych = *++YYCURSOR;
00171    if(yych != ';')   goto yy8;
00172    goto yy28;
00173 yy28: ++YYCURSOR;
00174    goto yy29;
00175 yy29:
00176 #line 69 "OW_XMLUnescape.re"
00177 { rval += '\''; thisTokStart = YYCURSOR; goto start; }
00178 #line 179 "OW_XMLUnescape.cpp"
00179 yy30: yych = *++YYCURSOR;
00180    if(yych != ';')   goto yy8;
00181    goto yy31;
00182 yy31: ++YYCURSOR;
00183    goto yy32;
00184 yy32:
00185 #line 67 "OW_XMLUnescape.re"
00186 { rval += '&'; thisTokStart = YYCURSOR; goto start; }
00187 #line 188 "OW_XMLUnescape.cpp"
00188 yy33: yych = *++YYCURSOR;
00189    if(yych == ';')   goto yy8;
00190    goto yy39;
00191 yy34: ++YYCURSOR;
00192    if(YYLIMIT == YYCURSOR) YYFILL(1);
00193    yych = *YYCURSOR;
00194    goto yy35;
00195 yy35: if(yych <= '/')   goto yy8;
00196    if(yych <= '9')   goto yy34;
00197    if(yych != ';')   goto yy8;
00198    goto yy36;
00199 yy36: ++YYCURSOR;
00200    goto yy37;
00201 yy37:
00202 #line 82 "OW_XMLUnescape.re"
00203 {
00204       unsigned long lval = strtoul( thisTokStart + 2, NULL, 10 );
00205       if (lval > CHAR_MAX)
00206       {
00207          OW_THROWXML(XMLParseException::MALFORMED_REFERENCE, Format("XML escape code in unsupported range: %1", YYCURSOR - 1).c_str());
00208       }
00209       char val = lval;
00210       rval += val;
00211       thisTokStart = YYCURSOR; goto start;
00212    }
00213 #line 214 "OW_XMLUnescape.cpp"
00214 yy38: ++YYCURSOR;
00215    if(YYLIMIT == YYCURSOR) YYFILL(1);
00216    yych = *YYCURSOR;
00217    goto yy39;
00218 yy39: if(yych <= ';'){
00219       if(yych <= '/')   goto yy8;
00220       if(yych <= '9')   goto yy38;
00221       if(yych <= ':')   goto yy8;
00222       goto yy40;
00223    } else {
00224       if(yych <= 'F'){
00225          if(yych <= '@')   goto yy8;
00226          goto yy38;
00227       } else {
00228          if(yych <= '`')   goto yy8;
00229          if(yych <= 'f')   goto yy38;
00230          goto yy8;
00231       }
00232    }
00233 yy40: ++YYCURSOR;
00234    goto yy41;
00235 yy41:
00236 #line 71 "OW_XMLUnescape.re"
00237 {
00238       unsigned long lval = strtoul( thisTokStart + 3, NULL, 16 );
00239       if (lval > CHAR_MAX)
00240       {
00241          OW_THROWXML(XMLParseException::MALFORMED_REFERENCE, Format("XML escape code in unsupported range: %1", YYCURSOR - 1).c_str());
00242       }
00243       char val = lval;
00244       rval += val;
00245       thisTokStart = YYCURSOR; goto start;
00246    }
00247 #line 248 "OW_XMLUnescape.cpp"
00248 }
00249 #line 94 "OW_XMLUnescape.re"
00250 
00251 
00252    return rval.releaseString();
00253 }
00254 
00255 } // end namespace OpenWBEM

Generated on Thu Feb 9 08:48:20 2006 for openwbem by  doxygen 1.4.6