2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
20 #include "NodeFilterMatcher.h"
24 namespace WrtDeviceApis {
25 namespace Filesystem {
29 bool NodeFilterMatcher::match(const INodePtr& value,
30 const NodeFilterPtr& filter)
33 if (!matchString(value->getPath()->getName(), filter->getName())) {
37 if (!matchRange(value->getCreated(),
38 filter->getMinCreated(),
39 filter->getMaxCreated())) {
43 if (!matchRange(value->getModified(),
44 filter->getMinModified(),
45 filter->getMaxModified())) {
49 if (!matchRange(value->getSize(),
51 filter->getMaxSize())) {
58 bool NodeFilterMatcher::matchString(const std::string& value,
59 const OptionalString& filter)
61 if (!filter.IsNull()) {
62 return pcrecpp::RE(*filter).PartialMatch(value);
67 template<typename Type>
68 bool NodeFilterMatcher::matchRange(const Type& value,
69 const DPL::Optional<Type>& min,
70 const DPL::Optional<Type>& max)
72 if ((!min.IsNull() && (value < *min)) ||
73 (!max.IsNull() && (value > *max))) {