tools/assistant/lib/fulltextsearch/qtoken.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team.
       
     4 ** All rights reserved.
       
     5 **
       
     6 ** Portion Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     7 ** All rights reserved.
       
     8 **
       
     9 ** This file may be used under the terms of the GNU Lesser General Public
       
    10 ** License version 2.1 as published by the Free Software Foundation and
       
    11 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    12 ** Please review the following information to ensure the GNU Lesser General
       
    13 ** Public License version 2.1 requirements will be met:
       
    14 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    15 **
       
    16 ****************************************************************************/
       
    17 
       
    18 #include "qtoken_p.h"
       
    19 #include "qclucene_global_p.h"
       
    20 
       
    21 #include <CLucene.h>
       
    22 #include <CLucene/analysis/AnalysisHeader.h>
       
    23 
       
    24 QT_BEGIN_NAMESPACE
       
    25 
       
    26 QCLuceneTokenPrivate::QCLuceneTokenPrivate()
       
    27     : QSharedData()
       
    28 {
       
    29     token = 0;
       
    30     deleteCLuceneToken = true;
       
    31 }
       
    32 
       
    33 QCLuceneTokenPrivate::QCLuceneTokenPrivate(const QCLuceneTokenPrivate &other)
       
    34     : QSharedData()
       
    35 {
       
    36     token = _CL_POINTER(other.token);
       
    37     deleteCLuceneToken = other.deleteCLuceneToken;
       
    38 }
       
    39 
       
    40 QCLuceneTokenPrivate::~QCLuceneTokenPrivate()
       
    41 {
       
    42     if (deleteCLuceneToken)
       
    43         _CLDECDELETE(token);
       
    44 }
       
    45 
       
    46 
       
    47 QCLuceneToken::QCLuceneToken()
       
    48     : d(new QCLuceneTokenPrivate())
       
    49     , tokenText(0)
       
    50     , tokenType(0)
       
    51 {
       
    52     d->token = new lucene::analysis::Token();
       
    53 }
       
    54 
       
    55 QCLuceneToken::QCLuceneToken(const QString &text, qint32 startOffset, 
       
    56                              qint32 endOffset, const QString &defaultTyp)
       
    57     : d(new QCLuceneTokenPrivate())
       
    58     , tokenText(QStringToTChar(text))
       
    59     , tokenType(QStringToTChar(defaultTyp))
       
    60 {
       
    61     d->token = new lucene::analysis::Token(tokenText, int32_t(startOffset), 
       
    62         int32_t(endOffset), tokenType);
       
    63 }
       
    64 
       
    65 QCLuceneToken::~QCLuceneToken()
       
    66 {
       
    67     delete [] tokenText;
       
    68     delete [] tokenType;
       
    69 }
       
    70 
       
    71 quint32 QCLuceneToken::bufferLength() const
       
    72 {
       
    73     return quint32(d->token->bufferLength());
       
    74 }
       
    75 
       
    76 void QCLuceneToken::growBuffer(quint32 size)
       
    77 {
       
    78     d->token->growBuffer(size_t(size));
       
    79 }
       
    80 
       
    81 qint32 QCLuceneToken::positionIncrement() const
       
    82 {
       
    83     return qint32(d->token->getPositionIncrement());
       
    84 }
       
    85 
       
    86 void QCLuceneToken::setPositionIncrement(qint32 positionIncrement)
       
    87 {
       
    88     d->token->setPositionIncrement(int32_t(positionIncrement));
       
    89 }
       
    90 
       
    91 QString QCLuceneToken::termText() const
       
    92 {
       
    93     return TCharToQString(d->token->termText());
       
    94 }
       
    95 
       
    96 void QCLuceneToken::setTermText(const QString &text)
       
    97 {
       
    98     delete [] tokenText;
       
    99     tokenText = QStringToTChar(text);
       
   100     d->token->setText(tokenText);
       
   101 }
       
   102 
       
   103 quint32 QCLuceneToken::termTextLength() const
       
   104 {
       
   105     return quint32(d->token->termTextLength());
       
   106 }
       
   107 
       
   108 void QCLuceneToken::resetTermTextLength() const
       
   109 {
       
   110     d->token->resetTermTextLen();
       
   111 }
       
   112 
       
   113 qint32 QCLuceneToken::startOffset() const
       
   114 {
       
   115     return quint32(d->token->startOffset());
       
   116 }
       
   117 
       
   118 void QCLuceneToken::setStartOffset(qint32 value)
       
   119 {
       
   120     d->token->setStartOffset(int32_t(value));
       
   121 }
       
   122 
       
   123 qint32 QCLuceneToken::endOffset() const
       
   124 {
       
   125     return quint32(d->token->endOffset());
       
   126 }
       
   127 
       
   128 void QCLuceneToken::setEndOffset(qint32 value)
       
   129 {
       
   130     d->token->setEndOffset(int32_t(value));
       
   131 }
       
   132 
       
   133 QString QCLuceneToken::type() const
       
   134 {
       
   135     return TCharToQString(d->token->type());
       
   136 }
       
   137 
       
   138 void QCLuceneToken::setType(const QString &type)
       
   139 {
       
   140     delete [] tokenType;
       
   141     tokenType = QStringToTChar(type);
       
   142     d->token->setType(tokenType);
       
   143 }
       
   144 
       
   145 QString QCLuceneToken::toString() const
       
   146 {
       
   147     return TCharToQString(d->token->toString());
       
   148 }
       
   149 
       
   150 QT_END_NAMESPACE