Удаление акцентов из QString [дубликат]
This question already has an answer here:
How to remove accents / diacritic marks from a string in Qt? 4 answersЯ хочу удалить акценты и, в более общем случае, диакритические знаки из строки, чтобы начать поиск без учета акцента. Основываясь на чтении классов символов Unicode, я пришел к следующему:
QString unaccent(const QString s)
{
QString s2 = s.normalized(QString::NormalizationForm_D);
QString out;
for (int i=0,j=s2.length(); i<j; i++)
{
// strip diacritic marks
if (s2.at(i).category()!=QChar::Mark_NonSpacing &&
s2.at(i).category()!=QChar::Mark_SpacingCombining)
{
out.append(s2.at(i));
}
}
return out;
}
Кажется, он работает достаточно хорошо для латинских языков, но мне интересно, насколько он адекватен другим алфавитам: арабскому, кириллическому, CJK ... который я не могу проверить из-за недостаточного культурного понимания этих языков.
В частности, я хотел бы знать:
What Unicode normalization form is better suited for this problem:NormalizationForm_KD
or NormalizationForm_D
?
Is it sufficient to remove the characters belonging to Mark_NonSpacing
and Mark_SpacingCombining
categories or should it include more categories?
Are there other improvements to the above code that would make it work as best as possible for all languages?