tizen beta release
[framework/web/wrt-plugins-common.git] / src / Commons / RegexUtils.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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 #ifndef WRTDEVICEAPIS_COMMONS_REGEX_UTILS_H_
17 #define WRTDEVICEAPIS_COMMONS_REGEX_UTILS_H_
18
19 #include <string>
20
21 namespace WrtDeviceApis {
22 namespace Commons {
23
24 /**
25  * Adds ^ character at the beginning in proper way
26  * @param value Regexp pattern
27  * @return Proper regular expression's pattern.
28  */
29 std::string addStartPositionMark(const std::string &value);
30
31 /**
32  * Adds $ character at the end in proper way
33  * @param value Regexp pattern
34  * @return Proper regular expression's pattern.
35  */
36 std::string addEndPositionMark(const std::string &value);
37
38 /**
39  * Adds ^ character at the beginning and $ the end in proper way
40  * @param value Regexp pattern
41  * @return Proper regular expression's pattern.
42  */
43 std::string addStartAndEndPositionMark(const std::string &value);
44
45 /**
46  * Converts typical string with wildcard '%' to proper perl-like regular
47  * expression's pattern.
48  * @param str String that came from JS.
49  * @return Proper regular expression's pattern.
50  * @remarks Calling it twice will (probably?) cause double escaping.
51  */
52 std::string preparePercent(const std::string& str);
53
54 /**
55  * Converts typical string with wildcard '*' to proper perl-like regular
56  * expression's pattern.
57  * @param str String that came from JS.
58  * @return Proper regular expression's pattern.
59  * @remarks Calling it twice will (probably?) cause double escaping.
60  */
61 std::string prepareAsterisk(const std::string& str);
62
63 /**
64  * Escapes regex special characters.
65  * @param str String to escape.
66  * @return String with regex special characters escaped.
67  */
68 std::string escape(const std::string& str);
69
70 }
71 } // WrtDeviceApisCommon
72
73 #endif // WRTDEVICEAPIS_COMMONS_REGEX_UTILS_H_