html encoding
-
-
Hm although that probably won't work for
é
character :/ -
Perhaps QUrl would work better here https://doc.qt.io/qt-5/qurl.html#toPercentEncoding
-
Hi, is there a function to translate a standard charset word to html? For example:
"perché" -> "perché"
@mrdebug
you can traverse the string char-wise and replace each unicode character >= 128 with&#<num>
or&#x<unicode-hex-val>
For the named entities (likeé
) you once will need to create a static replacement map. -
Perhaps QUrl would work better here https://doc.qt.io/qt-5/qurl.html#toPercentEncoding
I have been known in the past to "cheat" by using url encoding rules on HTML (e.g. in JavaScript) like @sierdzio suggests. But be aware the rules are not the same (HTML encoing != URL encoding), it's naughty and does not work in all cases.
Like @raven-worx says, if you want things like
é
you have to do this by hand every time, following voluminous lists like the reference he gives. Why languages/libraries do not seem to supply a useful function for this because it gets asked/wanted a lot, I do not know. -
Many thanks for your support. I need only a function to translate the IoT device descriptions in a correct html format to send notification emails.
So this function is enough for me.QString TextToHTML(QString Value) { Value.replace("à", "à"); Value.replace("è", "è"); Value.replace("é", "é"); Value.replace("ì", "ì"); Value.replace("ò", "ò"); Value.replace("ù", "à"); return Value; }
This function is not so cool but could be enough.
-
Many thanks for your support. I need only a function to translate the IoT device descriptions in a correct html format to send notification emails.
So this function is enough for me.QString TextToHTML(QString Value) { Value.replace("à", "à"); Value.replace("è", "è"); Value.replace("é", "é"); Value.replace("ì", "ì"); Value.replace("ò", "ò"); Value.replace("ù", "à"); return Value; }
This function is not so cool but could be enough.
@mrdebug
Yes this is what you have to do. However, while you are there, what are you doing about any characters which must be entitized for correct HTML, like<
-><
? I always do at least the 4:<
,&
,"
&'
. @sierdzio 's https://doc.qt.io/qt-5/qstring.html#toHtmlEscaped will do you for that. You might like to call that [at the start of, not the end!] in yourTextToHTML()
function. -
Many thanks for your support. I need only a function to translate the IoT device descriptions in a correct html format to send notification emails.
So this function is enough for me.QString TextToHTML(QString Value) { Value.replace("à", "à"); Value.replace("è", "è"); Value.replace("é", "é"); Value.replace("ì", "ì"); Value.replace("ò", "ò"); Value.replace("ù", "à"); return Value; }
This function is not so cool but could be enough.
@mrdebug said in html encoding:
instead ofValue.replace("à", "à");
better do
Value.replace( QChar(0x00C0)/*à*/, QStringLiteral("à"));
it's more robust.
-
@mrdebug
Yes this is what you have to do. However, while you are there, what are you doing about any characters which must be entitized for correct HTML, like<
-><
? I always do at least the 4:<
,&
,"
&'
. @sierdzio 's https://doc.qt.io/qt-5/qstring.html#toHtmlEscaped will do you for that. You might like to call that [at the start of, not the end!] in yourTextToHTML()
function.@JonB said in html encoding:
@mrdebug
Yes this is what you have to do. However, while you are there, what are you doing about any characters which must be entitized for correct HTML, like<
-><
? I always do at least the 4:<
,&
,"
&'
.That is, as @sierdzio already pointed out, https://doc.qt.io/qt-5/qstring.html#toHtmlEscaped
-
@JonB said in html encoding:
@mrdebug
Yes this is what you have to do. However, while you are there, what are you doing about any characters which must be entitized for correct HTML, like<
-><
? I always do at least the 4:<
,&
,"
&'
.That is, as @sierdzio already pointed out, https://doc.qt.io/qt-5/qstring.html#toHtmlEscaped