| 1234567891011121314151617181920212223242526272829303132333435363738 |
- #pragma once
- #include <algorithm>
- #include <cctype>
- #include <compare>
- #include <string>
- #include <string_view>
- #include <jvalidate/detail/compare.h>
- #include <jvalidate/detail/expect.h>
- namespace jvalidate::detail {
- class Anchor {
- private:
- std::string content_;
- public:
- Anchor() = default;
- explicit Anchor(std::string_view content) : content_(content) {
- EXPECT_M(content.empty() || content[0] == '_' || std::isalpha(content[0]),
- "First character of an Anchor must be alphabetic or '_'");
- EXPECT_M(
- std::all_of(content.begin(), content.end(),
- [](char c) { return std::isalnum(c) || c == '_' || c == '.' || c == '-'; }),
- "Illegal character(s) in anchor");
- }
- explicit operator std::string const &() const { return content_; }
- bool empty() const { return content_.empty(); }
- friend std::ostream & operator<<(std::ostream & os, Anchor const & self) {
- return os << self.content_;
- }
- auto operator<=>(Anchor const & lhs) const = default;
- };
- }
|