summaryrefslogtreecommitdiffstats
path: root/src/regexps.cpp
blob: 32031c0c2f925d9884b12c81d267af98683a9f9d (plain)
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
/***************************************************************************
 *   Copyright (C) 2003 by Sylvain Joyeux                                  *
 *   sylvain.joyeux@m4x.org                                                *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#include "regexps.h"
#include "debug.h"

#include <kdebug.h>

bool match_dversion(TQString version)
{
  static TQRegExp rx_revision(rxs_revision);
  TQString allowed_vchars = ".+\\w";

  kdDebug(DEBUG_ZONE) << version << endl;
  if (version[1] == ':')
  {
    allowed_vchars += ":";
    if (! version[0].isDigit()) return false;
    kdDebug(DEBUG_ZONE) << "Matched epoch" << endl;
    version = version.right( version.length() - 2 );
  }

  kdDebug(DEBUG_ZONE) << version << endl;
  int rev_pos = version.findRev('-');
  if (rev_pos > -1)
  {
    allowed_vchars += "-";
    TQString revision = version.right( version.length() - rev_pos - 1);
    if (! rx_revision.exactMatch(revision))
      return false;

    kdDebug(DEBUG_ZONE) << "Matched revision" << endl;
    version.truncate( version.length() - rev_pos - 1 );
  }

  TQRegExp rx_version("\\d[" + allowed_vchars + "]*");
  return rx_version.exactMatch(version);
}