Removed some redundant methods from TextController & Moved some code to other files
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / input-filter.cpp
1 /*
2  * Copyright (c) 2021 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 // CLASS HEADER
19 #include <dali-toolkit/internal/text/hidden-text.h>
20 #include <dali-toolkit/internal/text/input-filter.h>
21
22 // INTERNAL INCLUDES
23
24 using namespace Dali::Toolkit;
25
26 namespace Dali
27 {
28 namespace Toolkit
29 {
30 namespace Text
31 {
32 const char* const PROPERTY_ACCEPTED = "accepted";
33 const char* const PROPERTY_REJECTED = "rejected";
34
35 InputFilter::InputFilter()
36 : mAccepted(""),
37   mRejected("")
38 {
39 }
40
41 void InputFilter::SetProperties(const Property::Map& map)
42 {
43   const Property::Map::SizeType count = map.Count();
44
45   for(Property::Map::SizeType position = 0; position < count; ++position)
46   {
47     KeyValuePair     keyValue = map.GetKeyValue(position);
48     Property::Key&   key      = keyValue.first;
49     Property::Value& value    = keyValue.second;
50
51     if(key == Toolkit::InputFilter::Property::ACCEPTED || key == PROPERTY_ACCEPTED)
52     {
53       value.Get(mAccepted);
54     }
55     else if(key == Toolkit::InputFilter::Property::REJECTED || key == PROPERTY_REJECTED)
56     {
57       value.Get(mRejected);
58     }
59   }
60 }
61
62 void InputFilter::GetProperties(Property::Map& map)
63 {
64   map[Toolkit::InputFilter::Property::ACCEPTED] = mAccepted.c_str();
65   map[Toolkit::InputFilter::Property::REJECTED] = mRejected.c_str();
66 }
67
68 bool InputFilter::Contains(Toolkit::InputFilter::Property::Type type, std::string source)
69 {
70   bool       match = false;
71   std::regex pattern;
72
73   if(type == Toolkit::InputFilter::Property::ACCEPTED)
74   {
75     if(mAccepted.empty())
76     {
77       return true;
78     }
79     pattern = mAccepted;
80   }
81   else if(type == Toolkit::InputFilter::Property::REJECTED)
82   {
83     if(mRejected.empty())
84     {
85       return false;
86     }
87     pattern = mRejected;
88   }
89
90   match = std::regex_match(source, pattern);
91
92   return match;
93 }
94
95 } // namespace Text
96
97 } // namespace Toolkit
98
99 } // namespace Dali