xref: /trunk/main/ucb/source/inc/regexp.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _UCB_REGEXP_HXX_
29 #define _UCB_REGEXP_HXX_
30 
31 #include <rtl/ustring.hxx>
32 
33 //============================================================================
34 namespace ucb_impl {
35 
36 class Regexp
37 {
38 public:
39     enum Kind
40     {
41         KIND_PREFIX,
42         KIND_AUTHORITY,
43         KIND_DOMAIN
44     };
45 
46     inline bool operator ==(Regexp const & rOther) const;
47 
48     inline bool isDefault() const
49     { return m_eKind == KIND_PREFIX && m_aPrefix.getLength() == 0; }
50 
51     inline Kind getKind() const { return m_eKind; }
52 
53     bool matches(rtl::OUString const & rString, rtl::OUString * pTranslation,
54                  bool * pTranslated) const;
55 
56     rtl::OUString getRegexp(bool bReverse) const;
57 
58     static Regexp parse(rtl::OUString const & rRegexp);
59 
60 private:
61     Kind m_eKind;
62     rtl::OUString m_aPrefix;
63     rtl::OUString m_aInfix;
64     rtl::OUString m_aReversePrefix;
65     bool m_bEmptyDomain;
66     bool m_bTranslation;
67 
68     inline Regexp(Kind eTheKind, rtl::OUString const & rThePrefix,
69                   bool bTheEmptyDomain, rtl::OUString const & rTheInfix,
70                   bool bTheTranslation,
71                   rtl::OUString const & rTheReversePrefix);
72 };
73 
74 inline bool Regexp::operator ==(Regexp const & rOther) const
75 {
76     return m_eKind == rOther.m_eKind
77            && m_aPrefix == rOther.m_aPrefix
78            && m_aInfix == rOther.m_aInfix;
79 }
80 
81 }
82 
83 #endif // _UCB_REGEXP_HXX_
84 
85