QComposeInputContext::QComposeInputContext() { TableGenerator reader; m_tableState = reader.tableState(); if ((m_tableState & TableGenerator::NoErrors) == TableGenerator::NoErrors) { m_composeTable = reader.composeTable(); clearComposeBuffer(); } }
bool QComposeInputContext::checkComposeTable() { if (!m_compositionTableInitialized) { TableGenerator reader; m_tableState = reader.tableState(); m_compositionTableInitialized = true; if ((m_tableState & TableGenerator::NoErrors) == TableGenerator::NoErrors) { m_composeTable = reader.composeTable(); } else { #ifdef DEBUG_COMPOSING qDebug( "### FAILED_PARSING ###" ); #endif // if we have errors, don' try to look things up anyways. reset(); return false; } } Q_ASSERT(!m_composeTable.isEmpty()); QVector<QComposeTableElement>::const_iterator it = std::lower_bound(m_composeTable.constBegin(), m_composeTable.constEnd(), m_composeBuffer, ByKeys()); // prevent dereferencing an 'end' iterator, which would result in a crash if (it == m_composeTable.constEnd()) it -= 1; QComposeTableElement elem = *it; // would be nicer if qLowerBound had API that tells if the item was actually found if (m_composeBuffer[0] != elem.keys[0]) { #ifdef DEBUG_COMPOSING qDebug( "### no match ###" ); #endif reset(); return false; } // check if compose buffer is matched for (int i=0; i < QT_KEYSEQUENCE_MAX_LEN; i++) { // check if partial match if (m_composeBuffer[i] == 0 && elem.keys[i]) { #ifdef DEBUG_COMPOSING qDebug("### partial match ###"); #endif return true; } if (m_composeBuffer[i] != elem.keys[i]) { #ifdef DEBUG_COMPOSING qDebug("### different entry ###"); #endif reset(); return i != 0; } } #ifdef DEBUG_COMPOSING qDebug("### match exactly ###"); #endif // check if the key sequence is overwriten - see the comment in // TableGenerator::orderComposeTable() int next = 1; do { // if we are at the end of the table, then we have nothing to do here if (it + next != m_composeTable.constEnd()) { QComposeTableElement nextElem = *(it + next); if (isDuplicate(elem, nextElem)) { elem = nextElem; next++; continue; } else { break; } } break; } while (true); commitText(elem.value); reset(); return true; }