示例#1
0
static
bool parseUrl(const TQString& _url, TQString &title, TQString &section)
{
    section = TQString::null;

    TQString url = _url;
    if (url.at(0) == '/') {
        if (TDEStandardDirs::exists(url)) {
            title = url;
            return true;
        } else
        {
            // If the directory does not exist, then it is perhaps a normal man page
            kdDebug(7107) << url << " does not exist" << endl;
        }
    }

    while (url.at(0) == '/')
        url.remove(0,1);

    title = url;

    int pos = url.find('(');
    if (pos < 0)
        return true;

    title = title.left(pos);

    section = url.mid(pos+1);
    section = section.left(section.length()-1);

    return true;
}
示例#2
0
void KDecimalByteCodec::encode( TQString &Digits, unsigned int Pos, unsigned char Char ) const
{
  unsigned char C = Char / 100;
  Digits.at(Pos++) = '0'+C;
  Char -= C * 100;
  C = Char / 10;
  Digits.at(Pos++) = '0'+C;
  Char -= C * 10;
  Digits.at(Pos) = '0'+Char;
}
示例#3
0
void KDecimalByteCodec::encodeShort( TQString &Digits, unsigned int Pos, unsigned char Char ) const
{
  unsigned char C;
  if( (C = Char / 100) )
  {
    Digits.at(Pos++) = '0'+C;
    Char -= C * 100;
  }
  if( (C = Char / 10) )
  {
    Digits.at(Pos++) = '0'+C;
    Char -= C * 10;
  }
  Digits.at(Pos) = '0'+Char;
}
示例#4
0
// Iteratively removes a string from the tree. The nicer recursive
// version apparently was a little memory hungry (see #56757)
void TDECompTreeNode::remove( const TQString& str )
{
    TQString string = str;
    string += TQChar(0x0);

    TQPtrVector<TDECompTreeNode> deletables( string.length() + 1 );

    TDECompTreeNode *child = 0L;
    TDECompTreeNode *parent = this;
    deletables.insert( 0, parent );
    
    uint i = 0;
    for ( ; i < string.length(); i++ )
    {
        child = parent->find( string.at( i ) );
        if ( child )
            deletables.insert( i + 1, child );
        else
            break;

        parent = child;
    }

    for ( ; i >= 1; i-- )
    {
        parent = deletables.at( i - 1 );
        child = deletables.at( i );
        if ( child->myChildren.count() == 0 )
            delete parent->myChildren.remove( child );
    }
}
示例#5
0
void TDECompletion::extractStringsFromNodeCI( const TDECompTreeNode *node,
                                            const TQString& beginning,
                                            const TQString& restString,
                                            TDECompletionMatchesWrapper *matches ) const
{
    if ( restString.isEmpty() ) {
        extractStringsFromNode( node, beginning, matches, false /*noweight*/ );
        return;
    }

    TQChar ch1 = restString.at(0);
    TQString newRest = restString.mid(1);
    TDECompTreeNode *child1, *child2;

    child1 = node->find( ch1 ); // the correct match
    if ( child1 )
        extractStringsFromNodeCI( child1, beginning + *child1, newRest,
                                  matches );

    // append the case insensitive matches, if available
    if ( ch1.isLetter() ) {
        // find out if we have to lower or upper it. Is there a better way?
        TQChar ch2 = ch1.lower();
        if ( ch1 == ch2 )
            ch2 = ch1.upper();
        if ( ch1 != ch2 ) {
            child2 = node->find( ch2 );
            if ( child2 )
                extractStringsFromNodeCI( child2, beginning + *child2, newRest,
                                          matches );
        }
    }
}
示例#6
0
void TDECompletion::addItem( const TQString& item, uint weight )
{
    if ( item.isEmpty() )
        return;

    TDECompTreeNode *node = myTreeRoot;
    uint len = item.length();

    bool sorted = (myOrder == Sorted);
    bool weighted = ((myOrder == Weighted) && weight > 1);

    // knowing the weight of an item, we simply add this weight to all of its
    // nodes.

    for ( uint i = 0; i < len; i++ ) {
        node = node->insert( item.at(i), sorted );
        if ( weighted )
            node->confirm( weight -1 ); // node->insert() sets weighting to 1
    }

    // add 0x0-item as delimiter with evtl. weight
    node = node->insert( 0x0, true );
    if ( weighted )
        node->confirm( weight -1 );
//     tqDebug("*** added: %s (%i)", item.latin1(), node->weight());
}
示例#7
0
void TDECompletion::findAllCompletions(const TQString& string,
                                     TDECompletionMatchesWrapper *matches,
                                     bool& hasMultipleMatches) const
{
    //kdDebug(0) << "*** finding all completions for " << string << endl;

    if ( string.isEmpty() )
        return;

    if ( myIgnoreCase ) { // case insensitive completion
        extractStringsFromNodeCI( myTreeRoot, TQString::null, string, matches );
        hasMultipleMatches = (matches->count() > 1);
        return;
    }

    TQChar ch;
    TQString completion;
    const TDECompTreeNode *node = myTreeRoot;

    // start at the tree-root and try to find the search-string
    for( uint i = 0; i < string.length(); i++ ) {
        ch = string.at( i );
        node = node->find( ch );

        if ( node )
            completion += ch;
        else
            return; // no completion -> return empty list
    }
    
    // Now we have the last node of the to be completed string.
    // Follow it as long as it has exactly one child (= longest possible
    // completion)

    while ( node->childrenCount() == 1 ) {
        node = node->firstChild();
        if ( !node->isNull() )
            completion += *node;
        // kdDebug() << completion << node->latin1();
    }


    // there is just one single match)
    if ( node->childrenCount() == 0 )
        matches->append( node->weight(), completion );

    else {
        // node has more than one child
        // -> recursively find all remaining completions
        hasMultipleMatches = true;
        extractStringsFromNode( node, completion, matches );
    }
}
示例#8
0
// tries to complete "string" from the tree-root
TQString TDECompletion::findCompletion( const TQString& string )
{
    TQChar ch;
    TQString completion;
    const TDECompTreeNode *node = myTreeRoot;

    // start at the tree-root and try to find the search-string
    for( uint i = 0; i < string.length(); i++ ) {
        ch = string.at( i );
        node = node->find( ch );

        if ( node )
            completion += ch;
        else
            return TQString::null; // no completion
    }

    // Now we have the last node of the to be completed string.
    // Follow it as long as it has exactly one child (= longest possible
    // completion)

    while ( node->childrenCount() == 1 ) {
        node = node->firstChild();
        if ( !node->isNull() )
            completion += *node;
    }
    // if multiple matches and auto-completion mode
    // -> find the first complete match
    if ( node && node->childrenCount() > 1 ) {
        myHasMultipleMatches = true;
    
        if ( myCompletionMode == TDEGlobalSettings::CompletionAuto ) {
            myRotationIndex = 1;
            if (myOrder != Weighted) {
                while ( (node = node->firstChild()) ) {
                    if ( !node->isNull() )
                        completion += *node;
                    else
                        break;
                }
            }
            else {
                // don't just find the "first" match, but the one with the
                // highest priority
        
                const TDECompTreeNode* temp_node = 0L;
                while(1) {
                    int count = node->childrenCount();
                    temp_node = node->firstChild();
                    uint weight = temp_node->weight();
                    const TDECompTreeNode* hit = temp_node;
                    for( int i = 1; i < count; i++ ) {
                        temp_node = node->childAt(i);
                        if( temp_node->weight() > weight ) {
                            hit = temp_node;
                            weight = hit->weight();
                        }
                    }
                    // 0x0 has the highest priority -> we have the best match
                    if ( hit->isNull() )
                        break;

                    node = hit;
                    completion += *node;
                }
            }
        }

        else
            doBeep( PartialMatch ); // partial match -> beep
    }

    return completion;
}