| 14 | |
| 15 | |
| 16 | Xml::Xml(void *p, size_t s /*= 0*/) : Format(p, s), doc_(true) |
| 17 | { |
| 18 | uint8_t *q = static_cast<uint8_t *>(p); |
| 19 | |
| 20 | const uint8_t utf8_bom[] = { 0xEF, 0xBB, 0xBF }; |
| 21 | |
| 22 | // tinyxml2 does not support utf16 |
| 23 | /* |
| 24 | const uint8_t utf16be_bom[] = { 0xFE, 0xFF }; |
| 25 | const uint8_t utf16le_bom[] = { 0xFF, 0xFE }; |
| 26 | */ |
| 27 | // skip utf8 bom |
| 28 | if (memcmp(q, utf8_bom, sizeof(utf8_bom)) == 0) |
| 29 | { |
| 30 | q += sizeof(utf8_bom); |
| 31 | } |
| 32 | /* else if (!memcmp(q, utf16le_bom, sizeof(utf16le_bom)) || !memcmp(q, utf16be_bom, sizeof(utf16be_bom))) |
| 33 | { |
| 34 | q += sizeof(utf16le_bom); |
| 35 | } |
| 36 | */ |
| 37 | // skip spaces |
| 38 | while (isspace(*q) && q < static_cast<uint8_t *>(p) + s) |
| 39 | { |
| 40 | q++; |
| 41 | } |
| 42 | // only parse the file if it starts with '<' |
| 43 | if (*q == '<') |
| 44 | { |
| 45 | is_valid_ = (doc_.Parse(reinterpret_cast<char *>(fp_), size_) == 0); |
| 46 | } |
| 47 | else |
| 48 | { |
| 49 | is_valid_ = false; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | |
| 54 | |