View Single Post
Old 07-19-2014, 09:07 PM   #42
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,659
Karma: 5433388
Join Date: Nov 2009
Device: many
Hi user_none,
In the preferences, if I allow a two column list for users to put in numeric values in one column and a numeric entity or named entity in the other column, how can I validate what they input?

I can use QIntValidator to only except a string with digits for the unicode codepoint value. For numeric entities, I can split out the nondigit parts and validate the unicode code point digit string. But how can I validate named entities that people type in.

My fear is they enter in a non-valid or incomplete named entity string that ends up horribly messing up their code, requiring lots of search and replace to fix it.

Is there some way to easily pass potential named entity into some simple Qt class (instead of a full blown QWebView) that I can use to verify I get back a single unicode character?

I could try validating it against a long list of known math ml and other named entities, but that would be overkill.


Edit: Found my answer using this trick:

QTextDocument text;
text.setHtml("<>"");
QString plain = text.toPlainText();

So I can validate both numeric value and entity string in one easy step. Simply use text.setHtml(entity_string) similar to above and verify that using toPlainText() the resulting QString has length 1 and that QChar.unicode() has the exact same value as the numeric value.

If not, don't save it to preferences and reload the Preferences widget with only known good pairs and let the user try again.

Hope that does the trick. If you have a better idea, please just let me know ...

Thanks,

KevinH

Last edited by KevinH; 07-19-2014 at 10:06 PM.
KevinH is online now   Reply With Quote