File: qaregexpmatch.cpp

package info (click to toggle)
regexplorer 0.1.3-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 332 kB
  • ctags: 222
  • sloc: cpp: 1,166; perl: 99; makefile: 45; sh: 32
file content (120 lines) | stat: -rw-r--r-- 2,226 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// 
// $Id: qaregexpmatch.cpp,v 1.3 1999/07/19 02:36:55 amos Exp $
//
// Implementation of QaRegExpMatch class
//
// Jan Borsodi <amos@ez.no>
// Created on: <15-Jul-1999 13:53:16 amos>
//

#include "qaregexpmatch.hpp"
#include <qstring.h>
#include <qstringlist.h>
#include <qvaluelist.h>

/*!
  \class QaRegExpMatch qaregexpmatch.hpp
  \brief Holds match offset and strings from a previous match.

  It keeps a list of QaRegExpRange's from a match done earlier.
  It will also calculate the match strings on demand.
*/

/*!
  An empty match.
*/

QaRegExpMatch::QaRegExpMatch()
{
}

/*!
  Just the string
*/

QaRegExpMatch::QaRegExpMatch( const QString &s )
{
    String = s;
}

/*!
  A match of the given string.
*/

QaRegExpMatch::QaRegExpMatch( const QString &s, const regmatch_t m[], int size )
{
    String = s;
    for ( int i = 0; i < size; i++ )
    {
        appendMatch( QaRegExpRange( m[i].rm_so, m[i].rm_eo ) );
    }
}

/*!
  Destroys the object
*/

QaRegExpMatch::~QaRegExpMatch()
{
}

/*!
  Appends a match range to the list.
*/

void QaRegExpMatch::appendMatch( const QaRegExpRange &r )
{
    Matches.append( r );
    List.append( "" );
    int s = Calc.size();
    Calc.resize( s + 1 );
    Calc[s] = false;
}

/*!
  Will calculate the substrings of the match if not already done.
  \return A list of strings.
*/

const QStringList &QaRegExpMatch::toString()
{
    int i = 0;
    for ( QValueList<QaRegExpRange>::Iterator it = Matches.begin(); it != Matches.end(); ++it, ++i )
    {
        if ( Calc[i] == false )
        {
            if ( (*it).start() != -1 )
            {
                List[i] = String.mid( (*it).start(), (*it).length() );
                Calc[i] = true;
            }
        }
    }
    return List;
}

/*!
  \return The given substring.
*/

const QString &QaRegExpMatch::toString( int o )
{
    if ( Calc[o] == false )
    {
        List[o] = String.mid( Matches[o].start(), Matches[o].length() );
    }
    return List[o];
}


/*!
  \return The range of a given subexpression.
*/

const QaRegExpRange &QaRegExpMatch::operator[]( int o ) const
{
    // Fix this one later
//      if ( o < 0 || o >= Matches.count() )
//          throw OutOfRangeException;
    return Matches[o];
}