Кресты / Говнокод #10949 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
// For the probably_koi8_locales we have to look. the standard says
// these are 8859-5, but almost all Russian users use KOI8-R and
// incorrectly set $LANG to ru_RU. We'll check tolower() to see what
// it thinks ru_RU means.
// If you read the history, it seems that many Russians blame ISO and
// Perestroika for the confusion.
...
static QTextCodec * ru_RU_hack(const char * i) {
    QTextCodec * ru_RU_codec = 0;

#if !defined(QT_NO_SETLOCALE)
    QByteArray origlocale(setlocale(LC_CTYPE, i));
#else
    QByteArray origlocale(i);
#endif
    // unicode   koi8r   latin5   name
    // 0x044E    0xC0    0xEE     CYRILLIC SMALL LETTER YU
    // 0x042E    0xE0    0xCE     CYRILLIC CAPITAL LETTER YU
    int latin5 = tolower(0xCE);
    int koi8r = tolower(0xE0);
    if (koi8r == 0xC0 && latin5 != 0xEE) {
        ru_RU_codec = QTextCodec::codecForName("KOI8-R");
    } else if (koi8r != 0xC0 && latin5 == 0xEE) {
        ru_RU_codec = QTextCodec::codecForName("ISO 8859-5");
    } else {
        // something else again... let's assume... *throws dice*
        ru_RU_codec = QTextCodec::codecForName("KOI8-R");
        qWarning("QTextCodec: Using KOI8-R, probe failed (%02x %02x %s)",
                  koi8r, latin5, i);
    }
#if !defined(QT_NO_SETLOCALE)
    setlocale(LC_CTYPE, origlocale);
#endif

    return ru_RU_codec;
}

Снова Qt. На этот раз src/corelib/codecs/qtextcodec.cpp и борьба бобра с ослом русских с буржуинскими стандартами ISO.

Запостил: bormand bormand, (Updated )

Комментарии (7) RSS

    • В каком году написано - х.з. Надо порыться в репозитории, если старые коммиты у них еще живы. Но этот код есть и в 4.8.х...
      Ответить
  • Мне кажется, что это из четвертого эпизода, где "планету потерял учитель Обиван, должны мы потеряную планету найти", но чет не могу найти цитату.
    Ответить

Добавить комментарий

Семь раз отмерь — один отрежь, guest!

    А не использовать ли нам bbcode?


    8