Fix the boiler plate codes
[platform/framework/native/appfw.git] / src / base / utility / FBaseUtil_RegularExpressionImpl.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file                FBaseUtil_RegularExpressionImpl.h
19  * @brief               This is the header file for the _RegularExpressionImpl class.
20  * This header file contains the declarations of the _RegularExpressionImpl class.
21  */
22
23 #ifndef _FBASE_UTIL_INTERNAL_REGULAREXPRESSIONIMPL_H_
24 #define _FBASE_UTIL_INTERNAL_REGULAREXPRESSIONIMPL_H_
25
26 #include <FBaseUtilTypes.h>
27 #include <FBaseString.h>
28 #include <FBaseByteBuffer.h>
29 #include <FBaseUtilStringUtil.h>
30 #include <FBaseColIList.h>
31 #include <FBaseColArrayList.h>
32
33
34 namespace Tizen { namespace Base { namespace Utility
35 {
36
37 class _RegularExpressionImpl
38         : public Tizen::Base::Object
39 {
40 public:
41         _RegularExpressionImpl(void);
42         virtual ~_RegularExpressionImpl(void);
43
44         result Construct(const Tizen::Base::String& pattern, unsigned long options);
45         bool Match(const Tizen::Base::String& text, bool fullMatch, Tizen::Base::Collection::IList* pMatchedString);
46         bool Consume(String& text, Tizen::Base::Collection::IList* pMatchedString);
47         bool FindAndConsume(Tizen::Base::String& text, Tizen::Base::Collection::IList* pMatchedString);
48         bool Replace(Tizen::Base::String& text, const Tizen::Base::String& rewrite, bool globalReplace, int startPos);
49         bool Extract(const Tizen::Base::String& text, const Tizen::Base::String& rewrite, Tizen::Base::String& out);
50         Tizen::Base::String GetPattern(void) const;
51         result SetOptions(unsigned long options);
52         unsigned long GetOptions(void) const;
53         int GetLastMatchStart(void);
54         int GetLastMatchEnd(void);
55
56
57 private:
58         void Cleanup(void);
59         // Initializes _RegularExpressionImpl object
60         result Init(const Tizen::Base::String& pattern, const int options);
61
62         int Match(bool isFull, const Tizen::Base::String& text, int startPos, int matchOptions);
63
64         // Compiles _RegularExpressionImpl object with supplied pattern and options
65         void* Compile(const Tizen::Base::String& pattern, int options, bool forFullMatch);
66
67         result Rewrite(const Tizen::Base::String& rewrite, const Tizen::Base::String& text, Tizen::Base::String& out);
68
69         // Convert index pointing to Sting index [wchar_t] to char array [UTF8]
70         int StringToUtf8Index(const Tizen::Base::String text, int index);
71
72         // Convert index pointing to char array [UTF8] to Sting index [wchar_t]
73         int Utf8ToStringIndex(char* pUtf8String, int index);
74
75         int CheckRewritePattern(const Tizen::Base::String& rewrite);
76         result GetLastMatchedGroups(const Tizen::Base::String& text, Tizen::Base::Collection::IList& matchedGrpStrList);
77         String GetLastMatchedString(const Tizen::Base::String& text);
78         int GetLastGroupCount(void);
79
80         result PcreCompileErrorToSystemError(int compileErr);
81         result PcreExecErrorToSystemError(int err);
82
83         Tizen::Base::String __pattern;
84         void* __pReFull;
85         void* __pRePartial;
86
87         unsigned long __options;
88         bool __isCompilationRequired;
89         bool __isLastMatchPartial;
90
91         friend class RegularExpression;
92
93 }; // _RegularExpressionImpl
94
95 }}} // Tizen::Base::Utility
96
97 #endif // _FBASE_UTIL_INTERNAL_REGULAREXPRESSIONIMPL_H_