| 159 | } |
| 160 | |
| 161 | const char* StrPair::GetStr() { |
| 162 | if (_flags & NEEDS_FLUSH) { |
| 163 | *_end = 0; |
| 164 | _flags ^= NEEDS_FLUSH; |
| 165 | |
| 166 | if (_flags) { |
| 167 | char* p = _start; // the read pointer |
| 168 | char* q = _start; // the write pointer |
| 169 | |
| 170 | while (p < _end) { |
| 171 | if ((_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == CR) { |
| 172 | // CR-LF pair becomes LF |
| 173 | // CR alone becomes LF |
| 174 | // LF-CR becomes LF |
| 175 | if (*(p + 1) == LF) { |
| 176 | p += 2; |
| 177 | } else { |
| 178 | ++p; |
| 179 | } |
| 180 | *q++ = LF; |
| 181 | } else if ((_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == LF) { |
| 182 | if (*(p + 1) == CR) { |
| 183 | p += 2; |
| 184 | } else { |
| 185 | ++p; |
| 186 | } |
| 187 | *q++ = LF; |
| 188 | } else if ((_flags & NEEDS_ENTITY_PROCESSING) && *p == '&') { |
| 189 | // Entities handled by tinyXML2: |
| 190 | // - special entities in the entity table [in/out] |
| 191 | // - numeric character reference [in] |
| 192 | // 中 or 中 |
| 193 | |
| 194 | if (*(p + 1) == '#') { |
| 195 | char buf[10] = {0}; |
| 196 | int len; |
| 197 | p = const_cast<char*>(XMLUtil::GetCharacterRef(p, buf, &len)); |
| 198 | for (int i = 0; i < len; ++i) { |
| 199 | *q++ = buf[i]; |
| 200 | } |
| 201 | TIXMLASSERT(q <= p); |
| 202 | } else { |
| 203 | int i = 0; |
| 204 | for (; i < NUM_ENTITIES; ++i) { |
| 205 | if (strncmp(p + 1, entities[i].pattern, entities[i].length) == 0 |
| 206 | && *(p + entities[i].length + 1) == ';') { |
| 207 | // Found an entity convert; |
| 208 | *q = entities[i].value; |
| 209 | ++q; |
| 210 | p += entities[i].length + 2; |
| 211 | break; |
| 212 | } |
| 213 | } |
| 214 | if (i == NUM_ENTITIES) { |
| 215 | // fixme: treat as error? |
| 216 | ++p; |
| 217 | ++q; |
| 218 | } |