3rdparty
lexy
include
lexy
input
string_input.hpp
Go to the documentation of this file.
1
// Copyright (C) 2020-2024 Jonathan Müller and lexy contributors
2
// SPDX-License-Identifier: BSL-1.0
3
4
#ifndef LEXY_INPUT_STRING_INPUT_HPP_INCLUDED
5
#define LEXY_INPUT_STRING_INPUT_HPP_INCLUDED
6
7
#include <
lexy/error.hpp
>
8
#include <
lexy/input/base.hpp
>
9
#include <
lexy/lexeme.hpp
>
10
11
namespace
lexy
12
{
13
template
<
typename
View>
14
using
_string_view_char_type
=
LEXY_DECAY_DECLTYPE
(*
LEXY_DECLVAL
(View).data());
15
17
template
<
typename
Encoding = default_encoding>
18
class
string_input
19
{
20
static_assert(lexy::is_char_encoding<Encoding>);
21
22
public
:
23
using
encoding
= Encoding;
24
using
char_type
=
typename
encoding::char_type
;
25
26
//=== constructors ===//
27
constexpr
string_input
() noexcept :
_data
(
nullptr
),
_size
(0u) {}
28
29
constexpr
string_input
(
const
char_type
*
data
, std::size_t
size
) noexcept
30
:
_data
(
data
),
_size
(
size
)
31
{}
32
constexpr
string_input
(
const
char_type
*
begin
,
const
char_type
*
end
) noexcept
33
:
string_input
(
begin
, std::size_t(
end
-
begin
))
34
{}
35
36
template
<
typename
CharT,
typename
= _detail::require_secondary_
char
_type<Encoding, CharT>>
37
string_input
(
const
CharT*
data
, std::size_t
size
) noexcept
38
:
_data
(
reinterpret_cast<
const
char_type
*
>
(
data
)),
_size
(
size
)
39
{}
40
template
<
typename
CharT,
typename
= _detail::require_secondary_
char
_type<Encoding, CharT>>
41
string_input
(
const
CharT*
begin
,
const
CharT*
end
) noexcept
42
:
string_input
(
begin
, std::size_t(
end
-
begin
))
43
{}
44
45
template
<
typename
View,
typename
CharT = _
string
_view_
char
_type<View>>
46
constexpr
explicit
string_input
(
const
View& view) noexcept :
_size
(view.size())
47
{
48
if
constexpr (std::is_same_v<CharT, char_type>)
49
{
50
_data
= view.data();
51
}
52
else
53
{
54
static_assert(Encoding::template is_secondary_char_type<CharT>());
55
_data
=
reinterpret_cast<
const
char_type
*
>
(view.data());
56
}
57
}
58
59
//=== access ===//
60
constexpr
const
char_type
*
data
() const noexcept
61
{
62
return
_data
;
63
}
64
65
constexpr std::size_t
size
() const noexcept
66
{
67
return
_size
;
68
}
69
70
//=== reader ===//
71
constexpr
auto
reader
() const& noexcept
72
{
73
return
_range_reader<encoding>(
_data
,
_data
+
_size
);
74
}
75
76
private
:
77
const
char_type
*
_data
;
78
std::size_t
_size
;
79
};
80
81
template
<
typename
CharT>
82
string_input
(
const
CharT*
begin
,
const
CharT*
end
) ->
string_input<deduce_encoding<CharT>
>;
83
template
<
typename
CharT>
84
string_input
(
const
CharT* data, std::size_t
size
) ->
string_input<deduce_encoding<CharT>
>;
85
template
<
typename
View>
86
string_input
(
const
View&) ->
string_input<deduce_encoding<_string_view_char_type<View>
>>;
87
88
template
<
typename
Encoding,
typename
CharT>
89
constexpr
string_input<Encoding>
zstring_input
(
const
CharT* str) noexcept
90
{
91
auto
end
= str;
92
while
(*
end
!= CharT())
93
++
end
;
94
95
return
string_input<Encoding>
(str,
end
);
96
}
97
template
<
typename
CharT>
98
constexpr
auto
zstring_input
(
const
CharT* str) noexcept
99
{
100
return
zstring_input<deduce_encoding<CharT>>(str);
101
}
102
103
//=== convenience typedefs ===//
104
template
<
typename
Encoding = default_encoding>
105
using
string_lexeme
=
lexeme_for<string_input<Encoding>
>;
106
107
template
<
typename
Tag,
typename
Encoding = default_encoding>
108
using
string_error
=
error_for<string_input<Encoding>
, Tag>;
109
110
template
<
typename
Encoding = default_encoding>
111
using
string_error_context
=
error_context<string_input<Encoding>
>;
112
}
// namespace lexy
113
114
#endif // LEXY_INPUT_STRING_INPUT_HPP_INCLUDED
115
cx::size
constexpr auto size(const C &c) -> decltype(c.size())
Definition:
wildcards.hpp:636
lexy::string_input::string_input
constexpr string_input() noexcept
Definition:
string_input.hpp:27
lexy::string_input::_size
std::size_t _size
Definition:
string_input.hpp:78
magic_enum::char_type
string_view::value_type char_type
Definition:
magic_enum.hpp:145
lexy::string_input::string_input
constexpr string_input(const View &view) noexcept
Definition:
string_input.hpp:46
lexy::string_input::reader
constexpr auto reader() const &noexcept
Definition:
string_input.hpp:71
lexy::string_input::string_input
constexpr string_input(const char_type *data, std::size_t size) noexcept
Definition:
string_input.hpp:29
lexy::error_context
Contains information about the context of an error, production is type-erased.
Definition:
error.hpp:233
lexy
Definition:
any_ref.hpp:12
lexy::string_input::_data
const char_type * _data
Definition:
string_input.hpp:77
cx::end
constexpr auto end(const C &c) -> decltype(c.end())
Definition:
wildcards.hpp:686
lexy::error
Generic failure.
Definition:
error.hpp:14
lexy::string_input::char_type
typename encoding::char_type char_type
Definition:
string_input.hpp:24
lexeme.hpp
lexy::string_input::string_input
constexpr string_input(const char_type *begin, const char_type *end) noexcept
Definition:
string_input.hpp:32
lexy::string_input::data
constexpr const char_type * data() const noexcept
Definition:
string_input.hpp:60
LEXY_DECAY_DECLTYPE
#define LEXY_DECAY_DECLTYPE(...)
Definition:
config.hpp:34
lexy::string_input::size
constexpr std::size_t size() const noexcept
Definition:
string_input.hpp:65
cx::begin
constexpr auto begin(const C &c) -> decltype(c.begin())
Definition:
wildcards.hpp:661
lexy::lexeme
Definition:
lexeme.hpp:16
lexy::string_input
string_input(const CharT *begin, const CharT *end) -> string_input< deduce_encoding< CharT >>
base.hpp
lexy::_string_view_char_type
LEXY_DECAY_DECLTYPE(*LEXY_DECLVAL(View).data()) _string_view_char_type
Definition:
string_input.hpp:14
LEXY_DECLVAL
#define LEXY_DECLVAL(...)
Definition:
config.hpp:32
lexy::string_input::string_input
string_input(const CharT *begin, const CharT *end) noexcept
Definition:
string_input.hpp:41
lexy::zstring_input
constexpr string_input< Encoding > zstring_input(const CharT *str) noexcept
Definition:
string_input.hpp:89
lexy::string_input
An input that refers to a string.
Definition:
string_input.hpp:18
lexy::string_input::string_input
string_input(const CharT *data, std::size_t size) noexcept
Definition:
string_input.hpp:37
error.hpp
lexy::string_input::encoding
Encoding encoding
Definition:
string_input.hpp:23
behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Dec 13 2024 03:19:17