File: ipackagedetails.cpp

package info (click to toggle)
packagesearch 2.10.1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,704 kB
  • sloc: cpp: 9,176; perl: 248; makefile: 15; sh: 11
file content (61 lines) | stat: -rw-r--r-- 1,562 bytes parent folder | download
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
#include "ipackagedetails.h"

namespace NApt {

IPackageDetails::BorderList IPackageDetails::getPackageList(const QString& s)
{
    BorderList result;
    if (s.isEmpty())
        return result;
    pair<uint, uint> currentPair;
    // inWord and inPar (in paranthesis) can never both be true
    bool inWord=true;
    uint inPar=0;
    // a simple parser...
    currentPair.first=0;
    for (int i=0; i<s.length(); ++i)
    {
        if (inWord)
        {
            if ( !s[i].isSpace() && s[i]!=',' && s[i]!='(')	// we are still in the word
                continue;
            // we have reached the first char after a word
            currentPair.second=i;
            result.push_back(currentPair);
            inWord=false;
            if (s[i]=='(')
                ++inPar;
        }
        else
        {
            if (inPar != 0)
            {
                if (s[i]=='(')	// this should not happen cause we should not have nested parantheses
                    ++inPar;
                if (s[i]==')')
                    --inPar;
            }
            else
            {
                if (s[i]=='(')
                    ++inPar;
                if (s[i].isLetterOrNumber() || s[i]=='-' || s[i]=='_')	// we have reached a new word
                {
                    currentPair.first=i;
                    inWord=true;
                }
            }
        }
    }
    // if we finished with a word
    if (inWord)
    {
        currentPair.second=s.length();
        result.push_back(currentPair);
    }
    return result;
}



}