Advertisement
rweber89

Untitled

Feb 13th, 2019
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void SanitizeUTF8(QString &r, bool allowSpaces)
  2. {
  3.     for(int i = 0; i < r.size();)
  4.     {
  5.         const QChar c = r.at(i);
  6.         const bool removeSpace = !allowSpaces && c.isSpace();
  7.        
  8.         if(
  9.             removeSpace || !c.isPrint() || c.isMark() ||
  10.             c.category() == QChar::Other_Control ||
  11.             c.category() == QChar::Other_Format ||
  12.             c.category() == QChar::Other_NotAssigned || c.category() == QChar::Other_PrivateUse ||
  13.             c.category() == QChar::Symbol_Other ||
  14.  
  15.             // 'Arabic Presentation Forms-A'
  16.             (c.unicode() >= 64336 && c.unicode() <= 65023) ||
  17.  
  18.             // 'Arabic Presentation Forms-B'
  19.             (c.unicode() >= 65136 && c.unicode() <= 65279) ||
  20.  
  21.             // Replacement Chars / End of the line
  22.             c.unicode() >= 65532 ||
  23.  
  24.             // Jamo Fillers
  25.             c.unicode() == 4447 || c.unicode() == 4448 || c.unicode() == 12644
  26.  
  27.             ///
  28.             /// NOTES - QChar::Letter_Other is in use by chinese people
  29.             ///
  30.  
  31. #if QT_VERSION < 0x050000
  32.             // This code definitely worked in 4.6 and was seen to break in 5.1, hasn't been tried since
  33.             || c.category() == QChar::NoCategory
  34. #endif
  35.         )
  36.         {
  37.             r.replace(i, 1, "");
  38.         }
  39.         else
  40.         {
  41.             ++i;
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement