Advertisement
Guest User

Untitled

a guest
Feb 13th, 2019
86
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( removeSpace || !c.isPrint() || c.isMark() ||
  9.         c.category() == QChar::Other_Control ||
  10.         c.category() == QChar::Other_Format ||
  11.         c.category() == QChar::Other_NotAssigned || c.category() == QChar::Other_PrivateUse ||
  12.         c.category() == QChar::Symbol_Other ||
  13.  
  14.         // 'Arabic Presentation Forms-A'
  15.         (c.unicode() >= 64336 && c.unicode() <= 65023) ||
  16.  
  17.         // 'Arabic Presentation Forms-B'
  18.         (c.unicode() >= 65136 && c.unicode() <= 65279) ||
  19.  
  20.         // Replacement Chars / End of the line
  21.         //c.unicode() == 65532 || c.unicode() == 65533 || c.unicode() == 65534 || c.unicode() == 65535 ||
  22.         c.unicode() >= 65532 ||
  23.  
  24.         // Jamo Fillers
  25.         c.unicode() == 4447 || c.unicode() == 4448 || c.unicode() == 12644
  26.  
  27.         /// DO NOT UNCOMMENT - Letter_Other is in use by chinese people
  28.         /// c.category() == QChar::Letter_Other
  29.  
  30.         // This code definitely worked in 4.6 and was seen to break in 5.1, hasn't been tried since
  31. #if QT_VERSION < 0x050000
  32.         || c.category() == QChar::NoCategory
  33. #endif
  34.         )
  35.         {
  36.             r.replace(i, 1, "");
  37.         }
  38.         else
  39.             ++i;
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement