//---------------------------------------------------------------------------
//  getWordItems
//
//! Construct a list of word items to be inserted into a word list, based on
//! the results of a list of searches.
//
//! @param searchSpecs the list of search specifications
//! @return a list of word items
//---------------------------------------------------------------------------
QList<WordTableModel::WordItem>
WordVariationDialog::getWordItems(const QList<SearchSpec>& searchSpecs) const
{
    QList<WordTableModel::WordItem> wordItems;
    QMap<QString, QString> wordMap;
    QListIterator<SearchSpec> lit (searchSpecs);
    while (lit.hasNext()) {
        QStringList wordList = wordEngine->search(lexicon, lit.next(), false);
        QStringListIterator wit (wordList);
        while (wit.hasNext()) {
            QString str = wit.next();
            wordMap.insert(str.toUpper(), str);
        }
    }

    QMapIterator<QString, QString> mit (wordMap);
    while (mit.hasNext()) {
        mit.next();
        QString value = mit.value();
        QList<QChar> wildcardChars;
        for (int i = 0; i < value.length(); ++i) {
            QChar c = value[i];
            if (c.isLower())
                wildcardChars.append(c);
        }
        QString wildcard;
        if (!wildcardChars.isEmpty()) {
            qSort(wildcardChars.begin(), wildcardChars.end(),
                  Auxil::localeAwareLessThanQChar);
            foreach (const QChar& c, wildcardChars)
                wildcard.append(c.toUpper());
        }
        wordItems.append(WordTableModel::WordItem(
            mit.key(), WordTableModel::WordNormal, wildcard));
    }
void Scanner::consumeRegexpModifiers()
{
    QChar ch = m_src.peek();
    while (ch.isLetter() && ch.isLower()) {
        m_src.move();
        ch = m_src.peek();
    }
}
Exemple #3
0
static QString charFilterRegExp(QString const & filter)
{
	QString re;
	for (int i = 0; i < filter.length(); ++i) {
		QChar c = filter[i];
		if (c.isLower())
			re += ".*[" + QRegExp::escape(c) + QRegExp::escape(c.toUpper()) + "]";
		else
			re += ".*" + QRegExp::escape(c);
	}
	return re;
}
bool is_a_vowel(QChar single_letter)
{
    // Make sure we are dealing with lowercase letters.
    single_letter = single_letter.toLower();
    if (!single_letter.isLower()) return FALSE;

    if (single_letter == 'a') return TRUE;
    if (single_letter == 'e') return TRUE;
    if (single_letter == 'i') return TRUE;
    if (single_letter == 'o') return TRUE;
    if (single_letter == 'u') return TRUE;

    return (FALSE);
}
Exemple #5
0
static bool isAllCaps(const QString &s)
{
	for(int n = 0; n < s.length(); ++n)
	{
		QChar c = s[n];

		// non-letters are allowed, so what we really check against is
		//   lowercase
		if(c.isLower())
			return false;
	}

	return true;
}
// There is probably a better way with QChar, but I can't find it.
int letter_to_number (QChar let)
{
   // Make sure we are dealing with lowercase letters.
    let = let.toLower();
    if (!let.isLower()) return 0;

    for (int i = 0; i < 26; i++)
    {
        letters_and_numbers *ln_ptr =& lowercase_and_numbers[i];
        if (ln_ptr->let == let) return (ln_ptr->num);
    }

    /* all else - just return zero*/
    return 0;
}
Exemple #7
0
void Autocorrect::fixTwoUppercaseChars()
{
    if (! m_fixTwoUppercaseChars) return;
    if (m_word.length() <= 2) return;

    if (m_twoUpperLetterExceptions.contains(m_word.trimmed()))
        return;

    QChar firstChar = m_word.at(0);
    QChar secondChar = m_word.at(1);

    if (secondChar.isUpper()) {
        QChar thirdChar = m_word.at(2);

        if (firstChar.isUpper() && thirdChar.isLower())
            m_word.replace(1, 1, secondChar.toLower());
    }
}
void
MorseCodeDecoderNode::add(QString code, QChar character, int level)
{
  if (level == code.size()) {
    if (m_character == QChar('\0') && character.isLower())
      m_character = character;
  } else {
    QChar part = code[level];
    MorseCodeDecoderNode * branch;
    if (part == '.') {
      if (!m_dot_branch)
	m_dot_branch = new MorseCodeDecoderNode();
      branch = m_dot_branch;
    }
    else {
      if (!m_dash_branch)
	m_dash_branch = new MorseCodeDecoderNode();
      branch = m_dash_branch;
    }
    branch->add(code, character, level+1);
  }
}
QVariant Cell::parseMember(const QString &formula, SpreadSheet *widget) const
{
    int fOp = firstOperatorPosition(formula);
    if (fOp == -1)
        fOp = formula.length();
    QChar first = formula.at(0);
    
    QRegExp importedData("([\\w\\s]+:[A-Z][1-9][0-9]*)");
    QRegExp cellId("([A-Z][1-9][0-9]*)");
    
    //paranteza
    if (first=='(')
    {
        int end = 0;
        int open_p_count = 0;
        int closed_p_count = 0;
        for (int c=0; c<formula.length(); c++)
        {
            if (formula.at(c) == '(')
                open_p_count++;
            else if (formula.at(c) == ')')
                closed_p_count++;
            if (open_p_count == closed_p_count)
            {
                end = c;
                break;
            }
        }
        return computeFormula(formula.mid(1,end-1), widget);
    }
    //numar 0 sau 0.0
    else if (first.isDigit())
    {
        QString s = formula.left(fOp);
        if (s.count('.') <= 1)
        {
            bool ok;
            double x = s.toDouble(&ok);
            if (ok)
                return x;
        }
        emit invalidFormula(QString("Invalid number or number format in %1").arg(s));
        return "#####";
    }
    //tabela:identificator
    else if (formula.indexOf(importedData) == 0)
    {
        int idx = 0;
        QHash<QString,QString> matches = QHash<QString,QString>();
        while ((idx = formula.indexOf(importedData, idx)) != -1)
        {
            QString match = formula.mid(idx, importedData.matchedLength());
            int delim = match.indexOf(':');
            QString table = match.left(delim);
            QString id = match.mid(delim+1);
            matches.insertMulti(table, id);
            idx += importedData.matchedLength();
        }
        QString result = widget->getLinkData(formula, matches);
        if (isValidFormula(result))
            return display(result);
        else
            return result;
    }
    //celula A2
    else if (cellId.exactMatch(formula))
    {
        QVariant cellVal = getCellValue(formula,widget);
        if (cellVal == "#####")
            emit invalidFormula(QString("Invalid cell data in %1").arg(formula));
        return cellVal;
    }
    //functie nume_functie(A1;A2;A3)
    else if (first.isLower())
    {
        QStringList simple_function_names;
        QStringList cond_function_names;
        QStringList parameters;
        simple_function_names << "sum" << "avg" << "count";
        cond_function_names << "if" << "countif";
        QString s = formula.left(fOp);

        QString params = s.mid(s.lastIndexOf('(')+1,
                               s.indexOf(')')-s.lastIndexOf('(')-1);
        if (s.count('(') == s.count(')'))
            parameters = params.split(';');
        else
        {
            emit invalidFormula(QString("Invalid paranthesis number ").append(s));
            return "#####";
        }
        s = formula.left(formula.indexOf('('));
        if (simple_function_names.contains(s))
        {
            QVariantList values;
            QListIterator<QString> it(parameters);
            while (it.hasNext())
            {
                QString str = it.next();
                QVariant val = parseMember(str, widget);
                if (val != "#####")
                    values.append(val);
            }

            if (s == "sum")
            {
                double tmp = 0;
                bool ok = true;
                QListIterator<QVariant> valIt(values);
                while (valIt.hasNext())
                {
                    QVariant aux = valIt.next();
                    tmp += aux.toDouble(&ok);
                    if (!ok)
                    {
                        emit invalidFormula(QString("Not a number: ").append(aux.toString()));
                        return "#####";
                    }
                }
                return tmp;
            }
            else if (s == "avg")
            {
                double tmp = 0;
                bool ok = true;
                QListIterator<QVariant> valIt(values);
                while (valIt.hasNext())
                {
                    QVariant aux = valIt.next();
                    tmp += aux.toDouble(&ok);
                    if (!ok)
                    {
                        emit invalidFormula(QString("Not a number: ").append(aux.toString()));
                        return "#####";
                    }
                }
                tmp /= parameters.length();
                return tmp;
            }
            else if (s == "count")
            {
                return values.length();
            }
        }
        else if (cond_function_names.contains(s))
        {
            int param_no = parameters.length();
            if (param_no < 2)
            {
                emit invalidFormula(QString("Invalid parameter number: %1").arg(param_no));
                return "#####";
            }
            
            if (s == "if")
            {
                //if(A1<5;"Picat";n)
                //if(A1<5;4)
                QRegExp pattern("^(([\\w\\s]+:)?[A-Z][1-9][0-9]*"
                                "(<|<=|>|>=|<>|=)"
                                "((([\\w\\s]+:)?[A-Z][1-9][0-9]*)|(\\d+(\\.\\d+)?)))$");
                QString condition = parameters.at(0);
                if (pattern.exactMatch(condition) && param_no <= 3)
                {
                    int length = 1;
                    int opPos = condition.indexOf(QRegExp("(<|>|=)"));
                    if (condition.indexOf(QRegExp("(<=|>=|<>)")) > -1)
                        length = 2;
                    QString op = condition.mid(opPos,length);
                    bool ok1, ok2;
                    double firstOperand = parseMember(condition.left(opPos), widget).toDouble(&ok1);
                    double secondOperand = parseMember(condition.mid(opPos+length), widget).toDouble(&ok2);
                    if (!ok1 || !ok2)
                    {
                        emit invalidFormula(QString("Invalid condition parameters: %1").arg(condition));
                        return "#####";
                    }
                    if (param_no == 2)
                        return compareMembers(param_no, op,
                                              firstOperand, secondOperand,
                                              parameters.at(1), "#####");
                    else if (param_no == 3)
                        return compareMembers(param_no, op,
                                              firstOperand, secondOperand,
                                              parameters.at(1), parameters.at(2));
                }
                else
                {
                    emit invalidFormula(QString("Invalid formula syntax: ").append(condition));
                    return "#####";
                }
            }
            else if (s == "countif")
            {
                //countif(A1;A2...An;>5)
                if (param_no > 2)
                {
                    int count = 0;
                    int length = 1;
                    QString condition = parameters.last();
                    int opPos = condition.indexOf(QRegExp("(<|>|=)"));
                    if (condition.indexOf(QRegExp("(<=|>=|<>)")) > -1)
                        length = 2;
                    if (opPos == -1)
                    {
                        emit invalidFormula(QString("Invalid condition syntax: ").append(condition));
                        return "#####";
                    } 
                    QString op = condition.mid(opPos,length);
                    bool ok;
                    double firstOperand;
                    double secondOperand = parseMember(condition.mid(opPos+length), widget).toDouble(&ok);
                    if (!ok)
                    {
                        emit invalidFormula(QString("Invalid second operand: %1").
                                            arg(condition.mid(opPos+length)));
                        return "#####";
                    }
                    for (int i=0; i<param_no-1; i++)
                    {
                        firstOperand = parseMember(parameters.at(i), widget).toDouble(&ok);
                        if (!ok)
                        {
                            emit invalidFormula(QString("Invalid operand: %1").
                                                arg(parameters.at(i)));
                            return "#####";
                        }
                        if (compareMembers(op, firstOperand, secondOperand))
                            count++;
                    }
                    return count;
                }
            }
        }
        else
        {
            emit invalidFormula("Invalid formula");
            return "#####";
        }
    }
    return formula;
}
int Lexer::nextTokenKind()
{
    int token = Parser::Token_INVALID;
    if (m_curpos >= m_contentSize) {
        m_tokenBegin = -1;
        m_tokenEnd = -1;
        createNewline(m_curpos);
        return 0;
    }
    QChar* it = m_content.data();
    it += m_curpos;
    m_tokenBegin = m_curpos;

    if (it->isSpace())
    {
        token = Parser::Token_WHITESPACE;
        while (m_curpos < m_contentSize && it->isSpace())
        {
            if (it->unicode() == '\n')
            {
                createNewline(m_curpos);
            }
            it++;
            m_curpos++;
        }
        m_curpos--;
    }
    else if (it->isDigit())
    {
	QRegExp regex("\\d+\\.\\d+|\\d+\\.\\d+|\\d+\\.\\d+e-?\\d+|\\d+\\.\\d+e-?\\d+|[\\dABCDEF]+#\\d{1,2}|\\d+");
	
	if ( regex.indexIn(m_content, m_curpos) != -1)
	{
	  kDebug() << "Matched: " << regex.cap();
	  
	  m_curpos += regex.matchedLength() - 1;
	  token = Parser::Token_INTEGER_LITERAL;
	}
    }
    else if (it->unicode() == '-')
    {
	  if ((it + 1)->unicode() == '>')
	  {
	      m_curpos++;
	      token = Parser::Token_LEADS_TO;
	  }
	  else  if ((it + 1)->unicode() == '-')
	  {
	      m_curpos++;
	      token = Parser::Token_LIST_DIFFERENCE;
	  }
	  else
	  {
	      token = Parser::Token_MINUS;
	  }
    }    
    else if (it->unicode() == '+')
    {
	if ((it + 1)->unicode() == '+')
        {
            m_curpos++;
            token = Parser::Token_LIST_ADDITION;
        }
        else
        {
            token = Parser::Token_PLUS;
        }
    }
    else if (it->unicode() == '$' && processCharLiteral(it + 1))
    {
        token = Parser::Token_CHAR_LITERAL;
    }
    else if (it->unicode() == '}')
    {
        token = Parser::Token_RBRACE;
        if (state() == Tuple)
        {
            popState();
        }
    }
    else if (it->unicode() == '_')
    {
        token = Parser::Token_UNDERLINE;
    }
    else if (it->unicode() == '{')
    {
        token = Parser::Token_LBRACE;
        pushState(Tuple);
    }
    else if (it->unicode() == ')')
    {
        token = Parser::Token_RPAREN;
    }
    else if (it->unicode() == '(')
    {
        token = Parser::Token_LPAREN;
    }
    else if (it->unicode() == ']')
    {
        token = Parser::Token_RBRACKET;
    }
    else if (it->unicode() == '[')
    {
        token = Parser::Token_LBRACKET;
    }
    else if (it->unicode() == ',')
    {
        token = Parser::Token_COMMA;
    }
    else if (it->unicode() == '#')
    {
        token = Parser::Token_POUND_SIGN;
    }
    else if (it->unicode() == '!')
    {
        token = Parser::Token_EXCLAMATION;
    }
    else if (it->unicode() == '<')
    {
        if ( (it + 1)->unicode() == '-')
        {
            m_curpos += 1;
            token = Parser::Token_LIST_COMPREHENSION_LEADS_TO;
        }
        else if ( (it + 1)->unicode() == '<' )
        {
            m_curpos += 1;
            token = Parser::Token_BINARY_OPEN;
        }
        else
        {
            token = Parser::Token_IS_SMALLER;
        }
    }
    else if (it->unicode() == '>')
    {
        if ((it + 1)->unicode() == '=')
        {
            m_curpos++;
            token = Parser::Token_IS_GREATER_OR_EQUAL;
        }
        else if ( (it + 1)->unicode() == '>' )
        {
            m_curpos += 1;
            token = Parser::Token_BINARY_CLOSE;
        }
        else
        {
            token = Parser::Token_IS_GREATER;
        }
    }
    else if (it->unicode() == '?')
    {
        token = Parser::Token_QUESTION;
    }
    else if (it->unicode() == '%')
    {
        token = Parser::Token_COMMENT;
        while (it->unicode() != '\n')
        {
            m_curpos++;
            it++;
        }
        createNewline(m_curpos);
    }
    else if (it->unicode() == '/')
    {
        if ((it + 1)->unicode() == '=')
        {
            token = Parser::Token_IS_NOT_EQUAL;
        }
        else
        {
            token = Parser::Token_FORWARD_SLASH;
        }
    }
    else if (it->unicode() == '*')
    {
        token = Parser::Token_MUL;
    }
    else if (it->unicode() == '|')
    {
        if ((it + 1)->unicode() == '|')
        {
            m_curpos++;
            token = Parser::Token_DOUBLE_PIPE;
        }
        else
        {
            token = Parser::Token_PIPE;
        }
    }
    else if (it->unicode() == ':')
    {
        if ( (it + 1)->unicode() == ':')
        {
            m_curpos += 1;
            token = Parser::Token_DOUBLE_COLON;
        }
        else
        {
            token = Parser::Token_COLON;
        }
    }
    else if (it->unicode() == '.')
    {
        token = Parser::Token_DOT;
    }
    else if (it->unicode() == ';')
    {
        token = Parser::Token_SEMICOLON;
    }
    else if (it->unicode() == '\'')
    {
        token = Parser::Token_ATOM_LITERAL;
        it++;
        m_curpos++;
        int startPos = m_curpos;
        while (m_curpos < m_contentSize
                && (it->unicode() != '\'')) {
            if (it->unicode() == '\n') createNewline(m_curpos);
            it++;
            m_curpos++;
        }
        // if the string is never terminated, make sure we don't overflow the boundaries
        if ( m_curpos == m_contentSize ) {
            --m_curpos;
        }
    }
    else if (it->unicode() == '"')
    {
        token = Parser::Token_STRING_LITERAL;
        it++;
        m_curpos++;
        while (m_curpos < m_contentSize
                && (it->unicode() != '\"')) {
            if (it->unicode() == '\n') createNewline(m_curpos);
            it++;
            m_curpos++;
        }
        // if the string is never terminated, make sure we don't overflow the boundaries
        if ( m_curpos == m_contentSize ) {
            --m_curpos;
        }
    }
    else if (it->unicode() == '=')
    {
        if ((it + 1)->unicode() == '=')
        {
            m_curpos++;
            token = Parser::Token_IS_EQUAL;
        }
        else if ((it + 1)->unicode() == '<') {
            m_curpos++;
            token = Parser::Token_IS_SMALLER_OR_EQUAL;
        }
        else if ((it + 1)->unicode() == ':' && (it + 2)->unicode() == '=')
        {
            m_curpos += 2;
            token = Parser::Token_EXACT_EQUATIONAL;
        }
        else if ((it + 1)->unicode() == '/' && (it + 2)->unicode() == '=')
        {
            m_curpos += 2;
            token = Parser::Token_EXACT_NOT_EQUATIONAL;
        }
        else
        {
            token = Parser::Token_ASSIGN;
        }
    }
    else if (it->isLetter() && it->isUpper())
    {
        QString name;
        while (m_curpos < m_contentSize && (isValidVariableIdentifier(it))) {
            name.append(*it);
            it++;
            m_curpos++;
        }
        m_curpos--;
        token = Parser::Token_VARIABLE;
    }
    else if (it->isLetter() && it->isLower())
    {
        QString name;
        while (m_curpos < m_contentSize && (isValidVariableIdentifier(it))) {
            name.append(*it);
            it++;
            m_curpos++;
        }

        m_curpos--;

        if (name == "after") {
            token = Parser::Token_AFTER;
        } else if (name == "begin") {
            token = Parser::Token_BEGIN;
        } else if (name == "case") {
            token = Parser::Token_CASE;
        } else if (name == "if") {
            token = Parser::Token_IF;
        } else if (name == "catch") {
            token = Parser::Token_CATCH;
        } else if (name == "cond") {
            token = Parser::Token_COND;
        } else if (name == "end") {
            token = Parser::Token_END;
        } else if (name == "fun") {
            token = Parser::Token_FUN;
        } else if (name == "let") {
            token = Parser::Token_LET;
        } else if (name == "of") {
            token = Parser::Token_OF;
        } else if (name == "catch") {
            token = Parser::Token_CATCH;
        } else if (name == "receive") {
            token = Parser::Token_RECEIVE;
        } else if (name == "when") {
            token = Parser::Token_WHEN;
        } else if (name == "div") {
            token = Parser::Token_INT_DIV;
        } else if (name == "rem") {
            token = Parser::Token_INT_REM;
        } else if (name == "or") {
            token = Parser::Token_OR;
        } else if (name == "xor") {
            token = Parser::Token_XOR;
        } else if (name == "bor") {
            token = Parser::Token_BIT_OR;
        } else if (name == "bxor") {
            token = Parser::Token_BIT_XOR;
        } else if (name == "query") {
            token = Parser::Token_QUERY;
        } else if (name == "bsl") {
            token = Parser::Token_SL;
        } else if (name == "bsr") {
            token = Parser::Token_SR;
        } else if (name == "and") {
            token = Parser::Token_AND;
        } else if (name == "band") {
            token = Parser::Token_BIT_AND;
        } else if (name == "not") {
            token = Parser::Token_NOT;
        } else if (name == "bnot") {
            token = Parser::Token_BIT_NOT;
        } else if (name == "orelse") {
            token = Parser::Token_ORELSE;
        } else if (name == "andalso") {
            token = Parser::Token_ANDALSO;
        } else if (name == "module") {
            token = Parser::Token_MODULE_DIRECTIVE;
        } else if (name == "include") {
            token = Parser::Token_INCLUDE_DIRECTIVE;
        } else if (name == "export") {
            token = Parser::Token_EXPORT_DIRECTIVE;
        } else if (name == "file") {
            token = Parser::Token_FILE_DIRECTIVE;
        } else if (name == "record") {
            token = Parser::Token_RECORD_DIRECTIVE;
        } else if (name == "include") {
            token = Parser::Token_INCLUDE_DIRECTIVE;
        } else if (name == "behaviour"){
	  token = Parser::Token_BEHAVIOUR_DIRECTIVE;
	} else if (name == "define"){
	  token = Parser::Token_DEFINE_DIRECTIVE;
	}	
        else
        {
            token = Parser::Token_ATOM_LITERAL;
        }
    }

    m_tokenEnd = m_curpos;
    m_curpos++;

    return token;
}
Exemple #11
0
bool Chord::parse(QString text)
{
    if (text.isEmpty())
    {
        return false;
    }

    QRegExp beforeMatcher( "^(" + IGNORE_BEFORE_PATTERN + ")" );
    if (beforeMatcher.indexIn( text ) == 0 )
    {
        int n = beforeMatcher.matchedLength();
        m_before = text.left(n);
        text = text.mid(n);
    }

    QRegExp afterMatcher( "(" + IGNORE_AFTER_PATTERN + ")$" );
    if ( afterMatcher.indexIn( text ) >= 0 )
    {
        int n = afterMatcher.matchedLength();
        m_after = text.right( n );
        text = text.mid( 0, text.length() - n );
    }

    QChar baseChar = text[0];
    m_base = parseBase(baseChar);
    if (m_base < 0)
    {
        return false;
    }

    text = text.mid(1);

    if ( ifStartsWithTake( text, "es" )
     || (!text.startsWith("sus") && ifStartsWithTake( text, "s") )
     ||  ifStartsWithTake( text, "b" )
     ||  ifStartsWithTake( text, flat())    )
    {
        m_base--;
    }

    if ( ifStartsWithTake( text, "is" )
     ||  ifStartsWithTake( text, "#" )
     ||  ifStartsWithTake( text, sharp() ) )
    {
        m_base++;
    }

    m_base %= 12;
    m_base += 12;
    m_base %= 12;

    if ( baseChar.isLower()
         || (!text.startsWith("min") && !text.startsWith("maj") && ifStartsWithTake( text, "m" ) ) )
    {
        m_isMinor = true;
    }
    else
    {
        m_isMinor = false;
    }

    m_attachment = text;
    if (QRegExp( CHORD_EXTENSION_PATTERN ).exactMatch( m_attachment ))
    {
        return true;
    }
    else
    {
        return false;
    }
}
Exemple #12
0
QString ToolTipFiller::filterActionTipContents(const FilterAction& action)
{
    if (action.isNull())
    {
        return QString();
    }

    QString            str;
    DToolTipStyleSheet cnt(ApplicationSettings::instance()->getToolTipsFont());
    QString            tip = cnt.tipHeader;

    tip += cnt.headBeg + i18n("Filter") + cnt.headEnd;

    // Displayable name
    tip += cnt.cellBeg + i18n("Name:") + cnt.cellMid
        + DImgFilterManager::instance()->i18nDisplayableName(action) + cnt.cellEnd;

    // Category
    QString reproducible("---");

    switch (action.category())
    {
        case FilterAction::ReproducibleFilter:
            reproducible = i18nc("Image filter reproducible: Yes", "Yes");
            break;
        case FilterAction::ComplexFilter:
            reproducible = i18nc("Image filter reproducible: Partially", "Partially");
            break;
        case FilterAction::DocumentedHistory:
            reproducible = i18nc("Image filter reproducible: No", "No");
            break;
        default:
            break;
    };

    tip += cnt.cellBeg + i18n("Reproducible:") + cnt.cellMid
         + reproducible + cnt.cellEnd;

    // Description

    str = action.description();

    if (str.isEmpty())
    {
        str = QString("---");
    }

    tip += cnt.cellSpecBeg + i18nc("Image filter description", "Description:") + cnt.cellSpecMid
        + cnt.breakString(str) + cnt.cellSpecEnd;

    // Identifier + version
    tip += cnt.cellBeg + i18n("Identifier:") + cnt.cellMid
        + action.identifier() + " (v" + QString::number(action.version()) + ") " + cnt.cellEnd;

    if (action.hasParameters())
    {
        tip += cnt.headBeg + i18n("Technical Parameters") + cnt.headEnd;

        const QHash<QString, QVariant>& params = action.parameters();
        QList<QString> keys                    = params.keys();
        qSort(keys);

        foreach(const QString& key, keys)
        {
            QHash<QString, QVariant>::const_iterator it;

            for (it = params.find(key); it != params.end() && it.key() == key; ++it)
            {
                if (it.key().isEmpty() || !it.value().isValid())
                {
                    continue;
                }

                if (it.key().startsWith(QLatin1String("curveData")))
                {
                    str = i18n("<i>Binary Data</i>");
                }
                else
                {
                    str = it.value().toString();
                }

                if (str.length() > cnt.maxStringLength)
                {
                    str = cnt.elidedText(str, Qt::ElideRight);
                }

                QString key = it.key();
                QChar first = key.at(0);

                if (first.isLower())
                {
                    key.replace(0, 1, first.toUpper());
                }

                tip += cnt.cellBeg + key + cnt.cellMid
                    + str + cnt.cellEnd;
            }
        }
void Changecase::sentenceCase()
{
    QTextBlock block = m_document->findBlock(m_startPosition);
    QTextCursor backCursor(m_cursor);
    int pos = block.position() + block.length() - 1;

    // TODO
    // * Exception?
    while (true) {
        QString text = block.text();
        int prevLetterIndex = -1;
        QChar currentWord;
        pos = block.position() + block.length() - 1;

        QString::Iterator iter = text.end();

        if (text.isEmpty()) { // empty block, go to next block
            if (!(block.isValid() && block.position() + block.length() < m_endPosition))
                break;
            block = block.next();
            continue;
        }

        iter--;
        while (iter != text.begin()) {
            while (iter != text.begin() && !iter->isSpace()) {
                iter--;
                pos--;
            }

            prevLetterIndex = pos;
            currentWord = QChar(*(iter + 1));
            while (iter != text.begin() && iter->isSpace()) {
                iter--;
                pos--;
            }

            // found end of sentence, go back to last found letter (indicating start of a word)
            if (iter != text.begin() && (*iter == QChar('.') || *iter == QChar('!') || *iter == QChar('?'))) {
                if (prevLetterIndex >= m_startPosition && prevLetterIndex <= m_endPosition && currentWord.isLower()) {
                    // kDebug() <<"Found end of sentence" << *iter <<" :" << currentWord;
                    m_cursor.setPosition(prevLetterIndex);
                    m_cursor.deleteChar();
                    m_cursor.insertText(currentWord.toUpper());
                    iter--;
                    pos--;
                }
                else if (prevLetterIndex < m_startPosition)
                    break;
            }
        }

        if (iter == text.begin() && --pos >= m_startPosition) { // start of paragraph, must be start of a sentence also
            if (pos + 1 == prevLetterIndex && (*iter).isLower()) {
                m_cursor.setPosition(pos);
                m_cursor.deleteChar();
                m_cursor.insertText((*iter).toUpper());
            }
            else if (!(*iter).isLetter() && currentWord.isLower()) {
                m_cursor.setPosition(prevLetterIndex);
                m_cursor.deleteChar();
                m_cursor.insertText(currentWord.toUpper());
            }
        }

        if (!(block.isValid() && block.position() + block.length() < m_endPosition))
            break;
        block = block.next();
    }
}
Exemple #14
0
bool Classic::toASS(const QByteArray &txt, LibASS *ass, double fps)
{
    if (!ass)
        return false;

    bool ok = false, use_mDVD_FPS = Use_mDVD_FPS;

    const QRegExp TMPRegExp("\\d{1,2}:\\d{1,2}:\\d{1,2}\\D\\s?");
    const QRegExp MPL2RegExp("\\[\\d+\\]\\[\\d*\\]\\s?");
    const QRegExp MicroDVDRegExp("\\{\\d+\\}\\{\\d*\\}\\s?");
    QRegExp MicroDVDStylesRegExp("\\{(\\w):(.*)\\}");
    MicroDVDStylesRegExp.setMinimal(true);

    QList<SubWithoutEnd> subsWithoutEnd;

    for (const QString &line : QString(txt).remove('\r').split('\n', QString::SkipEmptyParts))
    {
        double start = 0.0, duration = 0.0;
        QString sub;
        int idx;

        if ((idx = line.indexOf(TMPRegExp)) > -1)
        {
            int h = -1, m = -1, s = -1;
            sscanf(line.toLatin1().constData() + idx, "%d:%d:%d", &h, &m, &s);
            if (h > -1 && m > -1 && s > -1)
            {
                start = h*3600 + m*60 + s;
                sub = convertLine(TMPRegExp, line);
            }
        }
        else if ((idx = line.indexOf(MPL2RegExp)) > -1)
        {
            int s = -1, e = -1;
            sscanf(line.toLatin1().constData() + idx, "[%d][%d]", &s, &e);
            if (s > -1)
            {
                for (const QString &l : convertLine(MPL2RegExp, line).split('\n'))
                {
                    if (!sub.isEmpty())
                        sub.append('\n');
                    if (!l.isEmpty())
                    {
                        switch (l.at(0).toLatin1()) {
                            case '/':
                                sub.append("{\\i1}" + l.mid(1) + "{\\i0}");
                                break;
                            case '\\':
                                sub.append("{\\b1}" + l.mid(1) + "{\\b0}");
                                break;
                            case '_':
                                sub.append("{\\u1}" + l.mid(1) + "{\\u0}");
                                break;
                            default:
                                sub.append(l);
                                break;
                        }
                    }
                }
                start = s / 10.0;
                duration = e / 10.0 - start;
            }
        }
        else if ((idx = line.indexOf(MicroDVDRegExp)) > -1)
        {
            int s = -1, e = -1;
            sscanf(line.toLatin1().constData() + idx, "{%d}{%d}", &s, &e);
            if (s > -1)
            {
                sub = convertLine(MicroDVDRegExp, line);

                if (use_mDVD_FPS && (s == 0 || s == 1))
                {
                    use_mDVD_FPS = false;
                    const double newFPS = sub.midRef(0, 6).toDouble();
                    if (newFPS > 0.0 && newFPS < 100.0)
                    {
                        fps = newFPS;
                        continue;
                    }
                }

                int pos = 0;
                while ((pos = MicroDVDStylesRegExp.indexIn(sub, pos)) != -1)
                {
                    const int matchedLength = MicroDVDStylesRegExp.matchedLength();
                    const QString styleText = MicroDVDStylesRegExp.cap(2);
                    const QChar s = MicroDVDStylesRegExp.cap(1).at(0);
                    const bool singleLine = s.isLower();
                    switch (s.toLower().toLatin1())
                    {
                        case 'c':
                            if (styleText.startsWith('$') && styleText.length() == 7)
                            {
                                replaceText(sub, pos, matchedLength, singleLine, "{\\1c&" + styleText.mid(1) + "&}", "{\\1c}");
                                continue;
                            }
                            break;
                        case 'f':
                            replaceText(sub, pos, matchedLength, singleLine, "{\\fn" + styleText + "}", "{\\fn}");
                            continue;
                        case 's':
                            replaceText(sub, pos, matchedLength, singleLine, "{\\fs" + styleText + "}", "{\\fs}");
                            continue;
                        case 'p':
                            if (!singleLine)
                            {
                                replaceText(sub, pos, matchedLength, false, "{\\pos(" + styleText + ")}", QString());
                                continue;
                            }
                            break;
                        case 'y':
                            replaceText(sub, pos, matchedLength, singleLine, "{\\" + styleText + "1}", "{\\" + styleText + "0}");
                            continue;
                    }
                    pos += MicroDVDStylesRegExp.matchedLength();
                }

                start = s / fps;
                duration = e / fps - start;
            }
        }

        if (start >= 0.0 && !sub.isEmpty())
        {
            if (duration > 0.0)
            {
                initOnce(ok, ass);
                ass->addASSEvent(Functions::convertToASS(sub), start, duration);
            }
            else
                subsWithoutEnd.append(SubWithoutEnd(start, Sub_max_s, sub));
        }
    }

    if (!subsWithoutEnd.isEmpty())
    {
        qSort(subsWithoutEnd);

        for (int i = 0; i < subsWithoutEnd.size()-1; ++i)
        {
            const unsigned diff = subsWithoutEnd.at(i+1) - subsWithoutEnd.at(i);
            if (!diff)
            {
                subsWithoutEnd[i+1] += subsWithoutEnd.at(i);
                subsWithoutEnd.removeAt(i);
                --i;
            }
            else
                subsWithoutEnd[i].setDuration(diff);
        }

        initOnce(ok, ass);
        for (const SubWithoutEnd &sub : asConst(subsWithoutEnd))
            ass->addASSEvent(Functions::convertToASS(sub.sub), sub.start, sub.duration);
    }

    return ok;
}