Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if a QString contains only "invisible" characters?

I would like to check if a QString is made up of only non-printable or non-visible characters. The QString could contain unicode...

I imagine a regular expression may work, but I have no idea how to create such a regex.

How can I check if a QString contains only "invisible" characters ? (space, \n, \r, \t...)

My "brute force" try

bool checkIfEmpty(const QString &contents) const
{
    for(QString::const_iterator itr(contents.begin()); itr != contents.end(); ++itr)
    {
        if(*itr != '\n' && *itr != '\r' && *itr != ' ' && *itr != '\t')
            return false;
    }
    return true;
}
like image 686
Thalia Avatar asked Feb 10 '23 04:02

Thalia


1 Answers

try this approach

bool checkIfEmpty(const QString contents) const
{
     if(contents.trimmed()=="") return true;
     else return false;
}

please note that this could be used only if you meant by "no printable" is space or tab characters

like image 172
Midhun Avatar answered Apr 27 '23 12:04

Midhun