String StringUtil::HtmlDecode(CStrRef input, const char *charset, bool all) { if (input.empty()) return input; ASSERT(charset); if (!html_supported_charset(charset)) { throw NotImplementedException(charset); } int len = input.size(); char *ret = string_html_decode(input, len, charset, all); return String(ret, len, AttachString); }
void ScannerToken::xhpDecode() { int len = m_text.size(); // note: 5th arg is charset_hint string; here we pass nullptr to indicate // "use the default one" which is UTF-8. (Just saves a charset lookup.) char *ret = string_html_decode(m_text.c_str(), len, true, false, nullptr, true, true); // safety check: decode function returns null iff charset unrecognized; // i.e. nullptr result would mean UTF-8 is available. // Pretty sure it is universally available! // (Do assertion anyway.) assert(ret); m_text = std::string(ret, len); free(ret); }
String StringUtil::HtmlDecode(CStrRef input, const char *charset, bool nbsp) { if (input.empty()) return input; ASSERT(charset); bool utf8 = true; if (strcasecmp(charset, "ISO-8859-1") == 0) { utf8 = false; } else if (strcasecmp(charset, "UTF-8")) { throw NotImplementedException(charset); } int len = input.size(); char *ret = string_html_decode(input, len, utf8, nbsp); return String(ret, len, AttachString); }
String StringUtil::HtmlDecode(CStrRef input, QuoteStyle quoteStyle, const char *charset, bool all) { if (input.empty()) return input; assert(charset); if (!html_supported_charset(charset)) { throw NotImplementedException(charset); } int len = input.size(); char *ret = string_html_decode(input, len, quoteStyle != NoQuotes, quoteStyle == BothQuotes, charset, all); return String(ret, len, AttachString); }
String StringUtil::HtmlDecode(CStrRef input, QuoteStyle quoteStyle, const char *charset, bool all) { if (input.empty()) return input; assert(charset); int len = input.size(); char *ret = string_html_decode(input.data(), len, quoteStyle != NoQuotes, quoteStyle == BothQuotes, charset, all); if (!ret) { // null iff charset was not recognized throw NotImplementedException(charset); // (charset is not null, see assertion above) } return String(ret, len, AttachString); }
String StringUtil::HtmlDecode(const String& input, QuoteStyle quoteStyle, const char *charset, bool all) { if (input.empty()) return input; assert(charset); int len = input.size(); char *ret = string_html_decode(input.data(), len, quoteStyle != QuoteStyle::No, quoteStyle == QuoteStyle::Both, charset, all); if (!ret) { // null iff charset was not recognized throw_not_implemented(charset); // (charset is not null, see assertion above) } return String(ret, len, AttachString); }
void ScannerToken::htmlDecode() { int len = m_text.size(); char *ret = string_html_decode(m_text.data(), len, "UTF-8", true); m_text = string(ret, len); free(ret); }
String StringUtil::HtmlDecode(CStrRef input) { if (input.empty()) return input; int len = input.size(); char *ret = string_html_decode(input, len); return String(ret, len, AttachString); }