/*! \fn CSwordModuleInfo::getSimpleConfigEntry(char* name) */ QString CSwordModuleInfo::getSimpleConfigEntry(const QString& name) const { QString ret = isUnicode() ? QString::fromUtf8(m_module->getConfigEntry(name.toUtf8().constData())) : QString::fromLatin1(m_module->getConfigEntry(name.toUtf8().constData())); return ret.isEmpty() ? QString::null : ret; }
/** This function makes an estimate if a module was properly unlocked. * It returns true if the first entry of the module is not empty and * contains only printable characters (for the first 100 chars or so). * If that is the case, we can safely assume that a) the module was properly * unlocked and b) no buffer overflows will occur, which can happen when * Sword filters process garbage text which was not properly decrypted. */ bool CSwordModuleInfo::unlockKeyIsValid() { (*m_module) = sword::TOP; // This needs to use ::fromLatin1 because if the text is still locked, // a lot of garbage will show up. It will also work with properly decrypted // Unicode text, because all non-ASCII Unicode chars consist of bytes >127 // and therefore contain no control (nonprintable) characters, which are all <127. QString test = isUnicode() ? QString::fromUtf8(m_module->getRawEntryBuf().c_str()) : QString::fromLatin1( m_module->getRawEntryBuf().c_str() ); if (test.isEmpty()) { qWarning() << "Unlock key of module" << name() << "is NOT valid!"; return false; } for (int i = 0; i <= test.length() && i < 100; i++) { if ( !test[i].isPrint() && !test[i].isNull() ) { qWarning() << "Unlock key of module" << name() << "is NOT valid!"; return false; } } qDebug() << "Unlock key of module" << name() << "is valid"; return true; }
/** Deletes the current entry and removes it from the module. */ bool CSwordModuleInfo::deleteEntry(CSwordKey * const key) { module()->KeyText(isUnicode() ? key->key().toUtf8().constData() : key->key().toLocal8Bit().constData()); if (module()) { module()->deleteEntry(); return true; } return false; }
QString CSwordModuleInfo::getFormattedConfigEntry(const QString& name) const { sword::SWBuf RTF_Buffer(m_module->getConfigEntry(name.toUtf8().constData())); sword::RTFHTML RTF_Filter; RTF_Filter.processText(RTF_Buffer, 0, 0); QString ret = isUnicode() ? QString::fromUtf8(RTF_Buffer.c_str()) : QString::fromLatin1(RTF_Buffer.c_str()); return ret.isEmpty() ? QString::null : ret; }
bool CSwordModuleInfo::unlockKeyIsValid() const { m_module.setPosition(sword::TOP); /* This needs to use ::fromLatin1 because if the text is still locked, a lot of garbage will show up. It will also work with properly decrypted Unicode text, because all non-ASCII Unicode chars consist of bytes >127 and therefore contain no control (nonprintable) characters, which are all <127. */ const QString test(isUnicode() ? QString::fromUtf8(m_module.getRawEntry()) : QString::fromLatin1(m_module.getRawEntry())); if (test.isEmpty()) return false; for (int i = 0; i < test.length() && i < 100; i++) if (!test[i].isPrint() && !test[i].isNull()) return false; return true; }
/** Writes the new text at the given position into the module. This does only work for writable modules. */ void CSwordModuleInfo::write(CSwordKey * key, const QString & newText) { module()->KeyText(key->key().toUtf8().constData()); //don't store a pointer to the const char* value somewhere because QCString doesn't keep the value of it module()->setEntry(isUnicode() ? newText.toUtf8().constData() : newText.toLocal8Bit().constData()); }
int CPlaneText::to_mathml__getTag_n_Text( std::vector<QString>& v_tag, std::vector<QString>& v_text, std::vector<QString>& v_attr, long /*level*/ ) { if( to_mathml_data.value.length() && to_mathml_data.type.length() ) { v_tag.push_back( to_mathml_data.type ); v_text.push_back( to_mathml_data.value ); } else { QString bodytext( GetNodeText() ); if( isUnicode() ) { if( to_mathml_data.name.length() ) v_tag.push_back( to_mathml_data.name ); else v_tag.push_back( QString(FBL_TAG_mi) ); v_text.push_back( bodytext ); } else { int ret = 0; long cb, i; LMMLChar mmlsl( getFStyle() == FSTYLE_GREEK, getFStyle() == FSTYLE_NUMBER, getFStyle() == FSTYLE_VARIABLE || getFStyle() == FSTYLE_FUNCTION, getFStyle() == FSTYLE_TEXT ); for(cb = 0;;) { ret = mmlsl.Analisys( bodytext.midRef(cb) ); if( !ret ) break; if( mmlsl.GetRead() > 0 && !mmlsl.getTag().isEmpty() && !mmlsl.getText().isEmpty() ) { v_tag.push_back( mmlsl.getTag() ); v_text.push_back( mmlsl.getText() ); } cb += mmlsl.GetRead(); mmlsl.reset(); } if( getFStyle() == FSTYLE_TEXT ) { QString s_tag = FBL_TAG_mtext, s_text = _T(""); for( i = 0; i < (long) v_text.size(); i++ ) s_text += v_text[ i ]; v_tag.erase( v_tag.begin(), v_tag.end() ); v_tag.push_back( s_tag ); v_text.erase( v_text.begin(), v_text.end() ); v_text.push_back( s_text ); } else if( getFStyle() == FSTYLE_OP ) { QString s_tag = FBL_TAG_mo, s_text = _T(""); for( i = 0; i < (long) v_text.size(); i++ ) s_text += v_text[ i ]; v_tag.erase( v_tag.begin(), v_tag.end() ); v_tag.push_back( s_tag ); v_text.erase( v_text.begin(), v_text.end() ); v_text.push_back( s_text ); } } } int isDefaultMMLChanged = 0, nTmp = 0; long j; for( long i = 0; i < (long) v_tag.size(); i++ ) { if( v_text[ i ].length() ) { QString& topr = v_text[ i ]; if( topr[ 0 ] == _T(' ') ) { topr[ 0 ] = _T('&'); topr.insert(1, _T("nbsp;") ); } if( topr.length() > 1 && topr[ topr.length() - 1 ] == ' ' ) { topr[ topr.length() - 1 ] = _T('&'); topr.append( _T("nbsp;") ); } for( j = 0; j < (long) topr.length() - 1; j++ ) { if( topr.at(j) == ' ' && topr.at(j + 1) == ' ' ) { topr[ (int) (j + 1) ] = '&'; topr.insert( j + 2, "nbsp;" ); j += 6; } } } v_attr.push_back( to_mathml__get_attribute_str( v_tag[ i ], v_text[ i ], &nTmp ) ); isDefaultMMLChanged = isDefaultMMLChanged || nTmp; } return isDefaultMMLChanged; }