Advertisement
Guest User

Untitled

a guest
Nov 7th, 2014
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. UConverter *QIcuCodec::getConverter(QTextCodec::ConverterState *state) const
  2. {
  3.     UConverter *conv = 0;
  4.     if (state) {
  5.         if (!state->d) {
  6.             // first time
  7.             state->flags |= QTextCodec::FreeFunction;
  8.             QTextCodecUnalignedPointer::encode(state->state_data, qIcuCodecStateFree);
  9.             UErrorCode error = U_ZERO_ERROR;
  10.             state->d = ucnv_open(m_name, &error);
  11.             ucnv_setSubstChars(static_cast<UConverter *>(state->d),
  12.                                state->flags & QTextCodec::ConvertInvalidToNull ? "\0" : "?", 1, &error);
  13.             if (U_FAILURE(error))
  14.                 qDebug() << "getConverter(state) ucnv_open failed" << m_name << u_errorName(error);
  15.         }
  16.         conv = static_cast<UConverter *>(state->d);
  17.     }
  18.     if (!conv) {
  19.         // stateless conversion
  20.         UErrorCode error = U_ZERO_ERROR;
  21.         conv = ucnv_open(m_name, &error);
  22.         ucnv_setSubstChars(conv, "?", 1, &error);
  23.         if (U_FAILURE(error))
  24.             qDebug() << "getConverter(no state) ucnv_open failed" << m_name << u_errorName(error);
  25.     }
  26.     return conv;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement