Keyple Util C++ Library - 2.4.0
Component of the Keyple C++ middleware
Pattern.cpp
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2025 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * See the NOTICE file(s) distributed with this work for additional *
5 * information regarding copyright ownership. *
6 * *
7 * This program and the accompanying materials are made available under the *
8 * terms of the Eclipse Public License 2.0 which is available at *
9 * http://www.eclipse.org/legal/epl-2.0 *
10 * *
11 * SPDX-License-Identifier: EPL-2.0 *
12 ******************************************************************************/
13
14#include "keyple/core/util/cpp/Pattern.hpp"
15
16#include <memory>
17#include <string>
18
19#include "keyple/core/util/cpp/exception/PatternSyntaxException.hpp"
20
21namespace keyple {
22namespace core {
23namespace util {
24namespace cpp {
25
26using keyple::core::util::cpp::exception::PatternSyntaxException;
27
28Pattern::Pattern(const std::string& pattern, const int flags)
29: mPattern(pattern)
30, mFlags(flags)
31{
32}
33
34std::shared_ptr<Pattern>
35Pattern::compile(const std::string& regularExpression, const int flags) const
36{
37 /* Compiler hack */
38 (void)mFlags;
39
40 try {
41 return std::make_shared<Pattern>(regularExpression, flags);
42
43 } catch (const std::exception& e) {
44 throw PatternSyntaxException(e.what());
45 }
46}
47
48std::shared_ptr<Pattern>
49Pattern::compile(const std::string& pattern)
50{
51 try {
52 return std::make_shared<Pattern>(pattern, 0);
53
54 } catch (const std::exception& e) {
55 throw PatternSyntaxException(e.what());
56 }
57}
58
59std::shared_ptr<Matcher>
60Pattern::matcher(const std::string& input) const
61{
62 return std::make_shared<Matcher>(this, input);
63}
64
65} /* namespace cpp */
66} /* namespace util */
67} /* namespace core */
68} /* namespace keyple */