1//
2// RegExpValidator.cpp
3//
4// Library: Util
5// Package: Options
6// Module: RegExpValidator
7//
8// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
9// and Contributors.
10//
11// SPDX-License-Identifier: BSL-1.0
12//
13
14
15#include "Poco/Util/RegExpValidator.h"
16#include "Poco/Util/Option.h"
17#include "Poco/Util/OptionException.h"
18#include "Poco/RegularExpression.h"
19#include "Poco/Format.h"
20
21
22using Poco::format;
23
24
25namespace Poco {
26namespace Util {
27
28
29RegExpValidator::RegExpValidator(const std::string& regexp):
30 _regexp(regexp)
31{
32}
33
34
35RegExpValidator::~RegExpValidator()
36{
37}
38
39
40void RegExpValidator::validate(const Option& option, const std::string& value)
41{
42 if (!RegularExpression::match(value, _regexp, RegularExpression::RE_ANCHORED | RegularExpression::RE_UTF8))
43 throw InvalidArgumentException(format("argument for %s does not match regular expression %s", option.fullName(), _regexp));
44}
45
46
47} } // namespace Poco::Util
48