| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 2 | |
Hi, I need to html-escape a string in my Qt program. That is: I want to replace & by &, < by <, " by " etc. I could of course code this manually, but I was wondering is this functionality isn't already available somewhere in Qt (4.4.0 beta)? It strikes me as something that is probably available, but I can not find it so far... Thanks, André -- [ signature omitted ]
On Wednesday 12 March 2008 15:48:07 André Somers wrote:
> Hi,
>
> I need to html-escape a string in my Qt program. That is: I want to replace
> & by &, < by <, " by " etc. I could of course code this
> manually, but I was wondering is this functionality isn't already available
> somewhere in Qt (4.4.0 beta)?
> It strikes me as something that is probably available, but I can not find
> it so far...
QString escaped=
QString(myhtml).replace("&","&").replace(">",">").replace("<","<");
there is nothing more. everything else is valid html.
to avoid encoding issues with broken browsers you can use
QUrl::toPercentEncoding but i suggest just not using IE5.
> Thanks,
>
> André
--
[ signature omitted ]
On Wednesday 12 March 2008 15:48:07 André Somers wrote: > Hi, > > I need to html-escape a string in my Qt program. That is: I want to replace > & by &, < by <, " by " etc. I could of course code this > manually, but I was wondering is this functionality isn't already available > somewhere in Qt (4.4.0 beta)? > It strikes me as something that is probably available, but I can not find > it so far... It's available, but slightly hidden. It's Qt::escape, defined in <QTextDocument> (QtGui). -- [ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.
...and decoding? á å etc... On 3/12/08, Thiago Macieira <thiago.macieira@xxxxxxxxxxxxx> wrote: > On Wednesday 12 March 2008 15:48:07 André Somers wrote: > > > Hi, > > > > I need to html-escape a string in my Qt program. That is: I want to replace > > & by &, < by <, " by " etc. I could of course code this > > manually, but I was wondering is this functionality isn't already available > > somewhere in Qt (4.4.0 beta)? > > It strikes me as something that is probably available, but I can not find > > it so far... > > > It's available, but slightly hidden. > > It's Qt::escape, defined in <QTextDocument> (QtGui). > > > -- > Thiago José Macieira - thiago.macieira AT trolltech.com > Trolltech ASA - Sandakerveien 116, NO-0402 Oslo, Norway > > -- [ signature omitted ]
Hi ! did you tried to use QTextDocument's toPlainText() or toHtml ? Heiko André Somers schrieb: > Hi, > > I need to html-escape a string in my Qt program. That is: I want to > replace & by &, < by <, " by " etc. I could of course code > this manually, but I was wondering is this functionality isn't already > available somewhere in Qt (4.4.0 beta)? > It strikes me as something that is probably available, but I can not > find it so far... > > Thanks, > > André > -- > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with > "unsubscribe" in the subject or the body. > List archive and information: http://lists.trolltech.com/qt-interest/ > > -- [ signature omitted ]
begin:vcard fn:Heiko Steindl n:Steindl;Heiko org:Computerhaus EDV-Handels Ges.m.b.H adr;quoted-printable:;;Wienerstrasse 35a;Kapfenberg;Steiermark;8605;=C3=96sterreich email;internet:heiko@xxxxxx tel;work:+43 (0)3862 27777 tel;fax:+43 (0)3862 27777 77 tel;cell:+43 (0)676 3727777 x-mozilla-html:TRUE url:http://www.kom.at version:2.1 end:vcard
Check this:
void QXmlStreamWriterPrivate::writeEscaped(const QString &s, bool
escapeWhitespace)
{
QString escaped;
escaped.reserve(s.size());
for ( int i = 0; i < s.size(); ++i ) {
QChar c = s.at(i);
if (c.unicode() == '<' )
escaped.append(QLatin1String("<"));
else if (c.unicode() == '>' )
escaped.append(QLatin1String(">"));
else if (c.unicode() == '&' )
escaped.append(QLatin1String("&"));
else if (c.unicode() == '\"' )
escaped.append(QLatin1String("""));
else if (escapeWhitespace && c.isSpace()) {
if (c.unicode() == '\n')
escaped.append(QLatin1String(" "));
else if (c.unicode() == '\r')
escaped.append(QLatin1String(" "));
else if (c.unicode() == '\t')
escaped.append(QLatin1String("	"));
else
escaped.inline_append(QLatin1Char(' '));
} else {
escaped.inline_append(c);
}
}
if (device) {
#ifdef QT_NO_TEXTCODEC
device->write(escaped.toLatin1(), escaped.size());
#else
device->write(encoder->fromUnicode(escaped));
#endif
}
else if (stringDevice)
stringDevice->append(escaped);
else
qWarning("QXmlStreamWriter: No device");
}
--
[ signature omitted ]
To everybody who replied: Thanks, these were very valuable suggestions. I have got it to work. André "André Somers" <andre@xxxxxxxxxxxxxxxx> wrote in message news:fr8qf8$ndm$1@xxxxxxxxxxxxxxxx > Hi, > > I need to html-escape a string in my Qt program. That is: I want to > replace & by &, < by <, " by " etc. I could of course code > this manually, but I was wondering is this functionality isn't already > available somewhere in Qt (4.4.0 beta)? > It strikes me as something that is probably available, but I can not find > it so far... > > Thanks, > > André -- [ signature omitted ]