File: helpers.cpp

package info (click to toggle)
libgpiod 2.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,108 kB
  • sloc: ansic: 26,612; sh: 7,554; cpp: 4,944; python: 2,426; makefile: 811; xml: 49
file content (37 lines) | stat: -rw-r--r-- 875 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// SPDX-License-Identifier: LGPL-2.1-or-later
// SPDX-FileCopyrightText: 2021-2022 Bartosz Golaszewski <brgl@bgdev.pl>

#include "helpers.hpp"

system_error_matcher::system_error_matcher(int expected_errno)
	: _m_cond(::std::system_category().default_error_condition(expected_errno))
{

}

::std::string system_error_matcher::describe() const
{
	return "matches: errno " + ::std::to_string(this->_m_cond.value());
}

bool system_error_matcher::match(const ::std::system_error& error) const
{
	return error.code().value() == this->_m_cond.value();
}

regex_matcher::regex_matcher(const ::std::string& pattern)
	: _m_pattern(pattern),
	  _m_repr("matches: regex \"" + pattern + "\"")
{

}

::std::string regex_matcher::describe() const
{
	return this->_m_repr;
}

bool regex_matcher::match(const ::std::string& str) const
{
	return ::std::regex_match(str, this->_m_pattern);
}