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