Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 810339
Collapse All | Expand All

(-)a/snapper/Makefile.am (-1 lines)
Lines 25-31 libsnapper_la_SOURCES = \ Link Here
25
	Compare.cc		Compare.h		\
25
	Compare.cc		Compare.h		\
26
	SystemCmd.cc		SystemCmd.h		\
26
	SystemCmd.cc		SystemCmd.h		\
27
	AsciiFile.cc		AsciiFile.h		\
27
	AsciiFile.cc		AsciiFile.h		\
28
	Regex.cc		Regex.h			\
29
	Acls.cc			Acls.h			\
28
	Acls.cc			Acls.h			\
30
	Hooks.cc		Hooks.h			\
29
	Hooks.cc		Hooks.h			\
31
	Exception.cc		Exception.h		\
30
	Exception.cc		Exception.h		\
(-)a/snapper/Regex.cc (-103 lines)
Lines 1-103 Link Here
1
/*
2
 * Copyright (c) [2004-2011] Novell, Inc.
3
 *
4
 * All Rights Reserved.
5
 *
6
 * This program is free software; you can redistribute it and/or modify it
7
 * under the terms of version 2 of the GNU General Public License as published
8
 * by the Free Software Foundation.
9
 *
10
 * This program is distributed in the hope that it will be useful, but WITHOUT
11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13
 * more details.
14
 *
15
 * You should have received a copy of the GNU General Public License along
16
 * with this program; if not, contact Novell, Inc.
17
 *
18
 * To contact Novell about this file by physical or electronic mail, you may
19
 * find current contact information at www.novell.com.
20
 */
21
22
23
// This file is obsolete. It is only present for compatibility of libsnapper, esp. the
24
// Regex class was used in older versions of the zypp-plugin and we must avoid potentially
25
// problems during updates.
26
27
28
#include <stdexcept>
29
#include "snapper/Regex.h"
30
31
extern int _nl_msg_cat_cntr;
32
33
34
namespace snapper
35
{
36
37
Regex::Regex (const string& pattern, int cflags, unsigned int nm)
38
    : pattern (pattern),
39
      cflags (cflags),
40
      nm (cflags & REG_NOSUB ? 0 : nm)
41
{
42
    int errcode = regcomp (&rx, pattern.c_str (), cflags);
43
    if (errcode) {
44
	size_t esize = regerror(errcode, &rx, nullptr, 0);
45
	char error[esize];
46
	regerror(errcode, &rx, error, esize);
47
	throw std::runtime_error(string("Regex compilation error: ") + error);
48
    }
49
    my_nl_msg_cat_cntr = _nl_msg_cat_cntr;
50
    rm = new regmatch_t[nm];
51
}
52
53
54
Regex::~Regex ()
55
{
56
    delete [] rm;
57
    regfree (&rx);
58
}
59
60
61
bool
62
Regex::match (const string& str, int eflags) const
63
{
64
    if (my_nl_msg_cat_cntr != _nl_msg_cat_cntr) {
65
	regfree (&rx);
66
	regcomp (&rx, pattern.c_str (), cflags);
67
	my_nl_msg_cat_cntr = _nl_msg_cat_cntr;
68
    }
69
70
    last_str = str;
71
72
    return regexec (&rx, str.c_str (), nm, rm, eflags) == 0;
73
}
74
75
76
regoff_t
77
Regex::so (unsigned int i) const
78
{
79
    return i < nm ? rm[i].rm_so : -1;
80
}
81
82
83
regoff_t
84
Regex::eo (unsigned int i) const
85
{
86
    return i < nm ? rm[i].rm_eo : -1;
87
}
88
89
90
string
91
Regex::cap (unsigned int i) const
92
{
93
    if (i < nm && rm[i].rm_so > -1)
94
	return last_str.substr (rm[i].rm_so, rm[i].rm_eo - rm[i].rm_so);
95
    return "";
96
}
97
98
99
const string Regex::ws = "[ \t]*";
100
const string Regex::number = "[0123456789]+";
101
const string Regex::trailing_comment = "(#.*)?";
102
103
}
(-)a/snapper/Regex.h (-78 lines)
Lines 1-78 Link Here
1
/*
2
 * Copyright (c) [2004-2012] Novell, Inc.
3
 *
4
 * All Rights Reserved.
5
 *
6
 * This program is free software; you can redistribute it and/or modify it
7
 * under the terms of version 2 of the GNU General Public License as published
8
 * by the Free Software Foundation.
9
 *
10
 * This program is distributed in the hope that it will be useful, but WITHOUT
11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13
 * more details.
14
 *
15
 * You should have received a copy of the GNU General Public License along
16
 * with this program; if not, contact Novell, Inc.
17
 *
18
 * To contact Novell about this file by physical or electronic mail, you may
19
 * find current contact information at www.novell.com.
20
 */
21
22
23
// This file is obsolete. It is only present for compatibility of libsnapper, esp. the
24
// Regex class was used in older versions of the zypp-plugin and we must avoid potentially
25
// problems during updates.
26
27
28
#ifndef SNAPPER_REGEX_H
29
#define SNAPPER_REGEX_H
30
31
32
#include <regex.h>
33
#include <string>
34
#include <boost/noncopyable.hpp>
35
36
37
namespace snapper
38
{
39
    using std::string;
40
41
42
class Regex : private boost::noncopyable
43
{
44
public:
45
46
    Regex (const string& pattern, int cflags = REG_EXTENDED, unsigned int = 10);
47
    ~Regex ();
48
49
    string getPattern () const { return pattern; }
50
    int getCflags () const { return cflags; }
51
52
    bool match (const string&, int eflags = 0) const;
53
54
    regoff_t so (unsigned int) const;
55
    regoff_t eo (unsigned int) const;
56
57
    string cap (unsigned int) const;
58
59
    static const string ws;
60
    static const string number;
61
    static const string trailing_comment;
62
63
private:
64
65
    const string pattern;
66
    const int cflags;
67
    const unsigned int nm;
68
69
    mutable regex_t rx;
70
    mutable int my_nl_msg_cat_cntr;
71
    mutable regmatch_t* rm;
72
73
    mutable string last_str;
74
};
75
76
}
77
78
#endif

Return to bug 810339