int MOZ_XMLTranslateEntity(const char* ptr, const char* end, const char** next, XML_Char* result) { const ENCODING* enc = XmlGetUtf16InternalEncodingNS(); int tok = PREFIX(scanRef)(enc, ptr, end, next); if (tok <= XML_TOK_INVALID) { return 0; } if (tok == XML_TOK_CHAR_REF) { int n = XmlCharRefNumber(enc, ptr); /* We could get away with just < 0, but better safe than sorry. */ if (n <= 0) { return 0; } return XmlUtf16Encode(n, (unsigned short*)result); } if (tok == XML_TOK_ENTITY_REF) { XML_Char ch = (XML_Char)XmlPredefinedEntityName(enc, ptr, *next - 2); if (!ch) { return 0; } *result = ch; return 1; } return 0; }
int MOZ_XMLTranslateEntity(const char* ptr, const char* end, const char** next, XML_Char* result) { // Can we assert here somehow? // MOZ_ASSERT(*ptr == '&'); const ENCODING* enc = XmlGetUtf16InternalEncodingNS(); /* scanRef expects to be pointed to the char after the '&'. */ int tok = PREFIX(scanRef)(enc, ptr + enc->minBytesPerChar, end, next); if (tok <= XML_TOK_INVALID) { return 0; } if (tok == XML_TOK_CHAR_REF) { /* XmlCharRefNumber expects to be pointed to the '&'. */ int n = XmlCharRefNumber(enc, ptr); /* We could get away with just < 0, but better safe than sorry. */ if (n <= 0) { return 0; } return XmlUtf16Encode(n, (unsigned short*)result); } if (tok == XML_TOK_ENTITY_REF) { /* XmlPredefinedEntityName expects to be pointed to the char after '&'. *next points to after the semicolon, so the entity ends at *next - enc->minBytesPerChar. */ XML_Char ch = (XML_Char)XmlPredefinedEntityName(enc, ptr + enc->minBytesPerChar, *next - enc->minBytesPerChar); if (!ch) { return 0; } *result = ch; return 1; } return 0; }