QStringConverter::availableCodecs() returns codecs that are from our perspective duplicates or are specialized single purpose codecs. Additionally Qt un-helpfully adds "Locale" to the list. */
| 192 | are specialized single purpose codecs. Additionally Qt un-helpfully adds "Locale" to the list. |
| 193 | */ |
| 194 | QStringList Utils::availableCodecs(){ |
| 195 | const std::set<QString> ignored = { "Adobe-Standard-Encoding", "Extended_UNIX_Code_Packed_Format_for_Japanese","UTF-7" }; |
| 196 | const QRegularExpression regExp(","); |
| 197 | qint32 codecCount = ucnv_countAvailable(); |
| 198 | QStringList result; |
| 199 | |
| 200 | regExp.optimize(); |
| 201 | result.reserve(codecCount); |
| 202 | for(qint32 i = 0; i < codecCount; ++i) |
| 203 | { |
| 204 | UErrorCode status = U_ZERO_ERROR; |
| 205 | const char* icuName = ucnv_getAvailableName(i); |
| 206 | const char* standardName = ucnv_getStandardName(icuName, "IANA", &status); |
| 207 | |
| 208 | if(U_FAILURE(status) || !standardName) { |
| 209 | continue; |
| 210 | } |
| 211 | |
| 212 | const QString name = QString::fromLatin1(standardName); |
| 213 | if(ignored.find(name) != ignored.cend()) |
| 214 | continue; |
| 215 | |
| 216 | result.push_back(name); |
| 217 | } |
| 218 | return result; |
| 219 | } |