650d5f81d1de028c2ac92816e58d1d0660b43930
[platform/upstream/libzypp.git] / zypp / base / Regex.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/base/Regex.h
10  *
11 */
12 #ifndef ZYPP_BASE_REGEX_H
13 #define ZYPP_BASE_REGEX_H
14
15 #include <iosfwd>
16 #include <string>
17
18 #include <regex.h>
19
20 ///////////////////////////////////////////////////////////////////
21 namespace zypp
22 { /////////////////////////////////////////////////////////////////
23   ///////////////////////////////////////////////////////////////////
24   /** String related utilities and \ref ZYPP_STR_REGEX.
25    \see \ref ZYPP_STR_REGEX
26   */
27   namespace str
28   { /////////////////////////////////////////////////////////////////
29
30     class regex {
31     public:
32
33         enum RegFlags {
34             optimize = 0,
35             match_extra = 0,
36             icase = REG_ICASE,
37             nosubs = REG_NOSUB,
38             match_extended = REG_EXTENDED
39         };
40
41         regex(const std::string& s,int flags = match_extended);
42         ~regex() throw();
43
44
45     public:
46         regex_t m_preg;
47         bool m_valid;
48     };
49
50
51     class smatch {
52     public:
53         smatch();
54
55         std::string operator[](unsigned i) const;
56
57         unsigned size() const;
58
59         std::string match_str;
60         regmatch_t pmatch[12];
61     };
62
63     bool regex_match(const std::string& s, str::smatch& matches, const regex& regex);
64     bool regex_match(const std::string& s,  const regex& regex);
65     bool regex_search(const std::string& s, str::smatch& matches, const regex& regex);
66
67     /////////////////////////////////////////////////////////////////
68   } // namespace str
69   ///////////////////////////////////////////////////////////////////
70   /////////////////////////////////////////////////////////////////
71 } // namespace zypp
72 ///////////////////////////////////////////////////////////////////
73 #endif // ZYPP_BASE_STRING_H