| 51 | } |
| 52 | |
| 53 | void TiXmlBase::EncodeString( const TIXML_STRING& str, TIXML_STRING* outString ) |
| 54 | { |
| 55 | int i=0; |
| 56 | |
| 57 | while( i<(int)str.length() ) |
| 58 | { |
| 59 | unsigned char c = (unsigned char) str[i]; |
| 60 | |
| 61 | if ( c == '&' |
| 62 | && i < ( (int)str.length() - 2 ) |
| 63 | && str[i+1] == '#' |
| 64 | && str[i+2] == 'x' ) |
| 65 | { |
| 66 | // Hexadecimal character reference. |
| 67 | // Pass through unchanged. |
| 68 | // © -- copyright symbol, for example. |
| 69 | // |
| 70 | // The -1 is a bug fix from Rob Laveaux. It keeps |
| 71 | // an overflow from happening if there is no ';'. |
| 72 | // There are actually 2 ways to exit this loop - |
| 73 | // while fails (error case) and break (semicolon found). |
| 74 | // However, there is no mechanism (currently) for |
| 75 | // this function to return an error. |
| 76 | while ( i<(int)str.length()-1 ) |
| 77 | { |
| 78 | outString->append( str.c_str() + i, 1 ); |
| 79 | ++i; |
| 80 | if ( str[i] == ';' ) |
| 81 | break; |
| 82 | } |
| 83 | } |
| 84 | else if ( c == '&' ) |
| 85 | { |
| 86 | outString->append( entity[0].str, entity[0].strLength ); |
| 87 | ++i; |
| 88 | } |
| 89 | else if ( c == '<' ) |
| 90 | { |
| 91 | outString->append( entity[1].str, entity[1].strLength ); |
| 92 | ++i; |
| 93 | } |
| 94 | else if ( c == '>' ) |
| 95 | { |
| 96 | outString->append( entity[2].str, entity[2].strLength ); |
| 97 | ++i; |
| 98 | } |
| 99 | else if ( c == '\"' ) |
| 100 | { |
| 101 | outString->append( entity[3].str, entity[3].strLength ); |
| 102 | ++i; |
| 103 | } |
| 104 | else if ( c == '\'' ) |
| 105 | { |
| 106 | outString->append( entity[4].str, entity[4].strLength ); |
| 107 | ++i; |
| 108 | } |
| 109 | else if ( c < 32 ) |
| 110 | { |