24 #include <QtCore/QtAlgorithms>
25 #include <QtCore/QRegExp>
26 #include <QtCore/QStringList>
27 #include <QtCore/QtDebug>
33 const int HTML::MaxEntities = 248;
34 const int HTML::FirstEntities = 10;
71 {
"Epsilon", 0x0395 },
92 {
"Omicron", 0x039f },
102 {
"Scaron", 0x0160 },
107 {
"Uacute", 0x00da },
109 {
"Ugrave", 0x00d9 },
110 {
"Upsilon", 0x03a5 },
113 {
"Yacute", 0x00dd },
116 {
"aacute", 0x00e1 },
119 {
"alefsym", 0x2135 },
127 {
"atilde", 0x00e3 },
131 {
"brvbar", 0x00a6 },
143 {
"cur" "ren", 0x00a4 },
145 {
"dagger", 0x2020 },
150 {
"divide", 0x00f7 },
154 {
"epsilon", 0x03b5 },
162 {
"forall", 0x2200 },
163 {
"frac12", 0x00bd },
164 {
"frac14", 0x00bc },
165 {
"frac34", 0x00be },
172 {
"hearts", 0x2665 },
173 {
"hellip", 0x2026 },
174 {
"iacute", 0x00ed },
176 {
"igrave", 0x00ec },
181 {
"iquest", 0x00bf },
186 {
"lambda", 0x03bb },
193 {
"lfloor", 0x230a },
194 {
"lowast", 0x2217 },
197 {
"lsaquo", 0x2039 },
203 {
"middot", 0x00b7 },
214 {
"ntilde", 0x00f1 },
216 {
"oacute", 0x00f3 },
218 {
"ograve", 0x00f2 },
221 {
"omicron", 0x03bf },
226 {
"oslash", 0x00f8 },
227 {
"otilde", 0x00f5 },
228 {
"otimes", 0x2297 },
232 {
"percnt", 0x0025 },
233 {
"permil", 0x2030 },
238 {
"plusmn", 0x00b1 },
254 {
"rfloor", 0x230b },
257 {
"rsaquo", 0x203a },
260 {
"scaron", 0x0161 },
265 {
"sigmaf", 0x03c2 },
267 {
"spades", 0x2660 },
278 {
"there4", 0x2234 },
280 {
"thetasym", 0x03d1 },
281 {
"thinsp", 0x2009 },
287 {
"uacute", 0x00fa },
291 {
"upsilon", 0x03c5 },
293 {
"weierp", 0x2118 },
295 {
"yacute", 0x00fd },
304 const HtmlEntity* HTML::end_ent = &entities[MaxEntities];
305 const HtmlEntity* HTML::start_ent = &entities[0];
307 const HtmlEntity* HTML::end_first = &first[FirstEntities];
308 const HtmlEntity* HTML::start_first = &first[0];
311 static bool operator < (
const QString &entityStr,
const HtmlEntity &entity){
312 return entityStr < QLatin1String(entity.
name);
316 static bool operator < (
const HtmlEntity &entity,
const QString &entityStr){
317 return QLatin1String(entity.
name) < entityStr;
321 static bool operator == (
const HtmlEntity &entity,
const quint16 entityCode){
322 return entityCode == entity.
code;
358 if (he != end_first)
return he->
code;
359 he = (
HtmlEntity*) qBinaryFind(start_ent,end_ent,entity);
360 if (he == end_ent)
return QChar();
372 if (he != end_first)
return he->
name;
373 he = (
HtmlEntity*) qFind(start_ent,end_ent,entityCode);
374 if (he == end_ent)
return QString();
393 QRegExp entityParser(
"(&([a-zA-Z]+);)",Qt::CaseInsensitive);
395 while((index = entityParser.indexIn(*str,index)) != -1)
399 if (!decodedChar.isNull())
400 str->replace(entityParser.cap(1),decodedChar);
411 QString* str =
new QString(*src);
423 QString* str =
new QString(src);
437 QString* str =
new QString(src);
451 return decode(src->c_str());
461 return decode(src.c_str());
482 for(
int pos=0; pos<str->size(); pos++)
486 if (!encodedChar.isNull())
489 str->insert(pos, QString(
"&%1;").arg(encodedChar.toLower()));
490 pos += encodedChar.size() + 2;
503 QString* str =
new QString(*src);
515 QString* str =
new QString(src);
529 QString* str =
new QString(src);
543 return encode(src->c_str());
553 return encode(src.c_str());