-
Notifications
You must be signed in to change notification settings - Fork 93
/
basics.hpp
1868 lines (1710 loc) · 38.6 KB
/
basics.hpp
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* RESTinio
*/
/*!
* @file
* @brief Utilities for parsing values of http-fields
*
* @since v.0.6.1
*/
#pragma once
#include <restinio/impl/string_caseless_compare.hpp>
#include <restinio/helpers/easy_parser.hpp>
#include <restinio/expected.hpp>
#include <algorithm>
namespace restinio
{
namespace http_field_parsers
{
using namespace restinio::easy_parser;
namespace meta = restinio::utils::metaprogramming;
namespace qvalue_details
{
//! A type to hold a qvalue.
using underlying_uint_t = std::uint_least16_t;
//! The maximal allowed value for a qvalue.
constexpr underlying_uint_t maximum = 1000u;
//! The minimal allowed value for a qvalue.
constexpr underlying_uint_t zero = 0u;
// A part of workaround for problem with static constexpr members
// detected after release of v.0.6.1.
enum class extremum_min_t { v };
enum class extremum_max_t { v };
//! A helper wrapper to indicate that value is already checked and
//! shouldn't be checked again.
class trusted
{
const underlying_uint_t m_value;
public :
explicit constexpr
trusted( underlying_uint_t value ) noexcept : m_value{ value } {}
constexpr auto get() const noexcept { return m_value; }
};
//! A helper wrapper to indicate that value hasn't been checked yet
//! and should be checked in the constructor of qvalue.
class untrusted
{
underlying_uint_t m_value;
public :
explicit
untrusted( underlying_uint_t value ) : m_value{ value }
{
if( m_value > maximum )
throw exception_t( "invalid value for "
"http_field_parser::rfc::qvalue_t" );
}
auto get() const noexcept { return m_value; }
};
} /* namespace qvalue_details */
//
// qvalue_t
//
/*!
* @brief A class for holding the parsed value of qvalue from RFC7231.
*
* An important note: qvalue in RFC7231 is defined as a number with
* fractional point. This number can have no more that three digits
* after a point. And the non-factional part can only be 0 or 1. If
* non-frational part is 1 then fractional part can only be 0. It means
* that qvalue can be in the range [0.000, 1.000].
*
* To simplify work with qvalue RESTinio holds qvalue as a small integer
* in the range [0, 1000] where 0 corresponds to 0.000 and 1000 corresponds
* to 1.000. In means, for example, that value 0.05 will be represented and 50,
* and the value 0.001 will be represented as 1, and the value 0.901 will
* be represented as 901.
*
* The integer representation of qvalue can be obtained via as_uint()
* method.
*
* Method as_string() returns std::string with number with fractional
* part inside. It means:
* @code
* assert("1.000" == qvalue_t{qvalue_t::maximum}.as_string());
* assert("0.901" == qvalue_t{qvalue_t::untrusted{901}}.as_string());
* @endcode
* Such representation is also used in `operator<<` for std::ostream.
*
* Instances of qvalue_t can be compared, operations `==`, `!=`, `<` and `<=`
* are supported.
*
* There are two ways to construct a new qvalue object.
*
* The first and recommended way is intended for cases when the source
* value for a new qvalue object isn't known at the compile-time and
* produced somehow at the run-time. It's the usage of qvalue_t::untrusted
* wrapper:
* @code
* qvalue_t weight{qvalue_t::untrusted{config.default_weigh() * 10}};
* @endcode
* In that case the value of `untrusted` will be checked in
* qvalue_t::untrusted's constructor and an exception will be thrown if that
* value isn't in [0, 1000] range.
*
* The second way is intended to be used with compile-time constants:
* @code
* qvalue_t weight{qvalue_t::trusted{250}};
* @endcode
* In the case of `trusted` the value is not checked in qvalue_t's
* constructor. Therefore that way should be used with additional care.
*
* @since v.0.6.1
*/
class qvalue_t
{
public :
//! The type of underlying small integer.
using underlying_uint_t = qvalue_details::underlying_uint_t;
//! The type that doesn't check a value to be used for qvalue.
using trusted = qvalue_details::trusted;
//! The type that checks a value to be used for qvalue.
using untrusted = qvalue_details::untrusted;
//! The indicator that tells that new qvalue object should have
//! the maximal allowed value.
static constexpr qvalue_details::extremum_max_t maximum =
qvalue_details::extremum_max_t::v;
//! The indicator that tells that new qvalue object should have
//! the minimal allowed value.
static constexpr qvalue_details::extremum_min_t zero =
qvalue_details::extremum_min_t::v;
private :
// Note: with the terminal 0-symbol.
using underlying_char_array_t = std::array<char, 6>;
underlying_uint_t m_value{};
underlying_char_array_t
make_char_array() const noexcept
{
underlying_char_array_t result;
if( qvalue_details::maximum == m_value )
{
std::strcpy( &result[0], "1.000" );
}
else
{
result[0] = '0';
result[1] = '.';
result[2] = '0' + static_cast<char>(m_value / 100u);
const auto d2 = m_value % 100u;
result[3] = '0' + static_cast<char>(d2 / 10u);
const auto d3 = d2 % 10u;
result[4] = '0' + static_cast<char>(d3);
result[5] = 0;
}
return result;
}
public :
constexpr qvalue_t() = default;
qvalue_t( untrusted val ) noexcept
: m_value{ val.get() }
{}
constexpr qvalue_t( trusted val ) noexcept
: m_value{ val.get() }
{}
constexpr qvalue_t( qvalue_details::extremum_min_t ) noexcept
: m_value{ qvalue_details::zero }
{}
constexpr qvalue_t( qvalue_details::extremum_max_t ) noexcept
: m_value{ qvalue_details::maximum }
{}
constexpr auto as_uint() const noexcept { return m_value; }
auto as_string() const
{
return std::string{ &make_char_array().front() };
}
friend std::ostream &
operator<<( std::ostream & to, const qvalue_t & what )
{
return (to << &what.make_char_array().front());
}
};
RESTINIO_NODISCARD
inline bool
operator==( const qvalue_t & a, const qvalue_t & b ) noexcept
{
return a.as_uint() == b.as_uint();
}
RESTINIO_NODISCARD
inline bool
operator!=( const qvalue_t & a, const qvalue_t & b ) noexcept
{
return a.as_uint() != b.as_uint();
}
RESTINIO_NODISCARD
inline bool
operator<( const qvalue_t & a, const qvalue_t & b ) noexcept
{
return a.as_uint() < b.as_uint();
}
RESTINIO_NODISCARD
inline bool
operator<=( const qvalue_t & a, const qvalue_t & b ) noexcept
{
return a.as_uint() <= b.as_uint();
}
namespace impl
{
using namespace restinio::easy_parser::impl;
//
// is_alpha
//
/*!
* @brief Is a character an ALPHA?
*
* See: https://tools.ietf.org/html/rfc5234#appendix-B.1
*
* @since v.0.6.1
*/
RESTINIO_NODISCARD
inline constexpr bool
is_alpha( const char ch ) noexcept
{
return (ch >= '\x41' && ch <= '\x5A') ||
(ch >= '\x61' && ch <= '\x7A');
}
//
// is_alpha_predicate_t
//
/*!
* @brief A preducate for symbol_producer_template that checks that
* a symbol is an alpha.
*
* @since v.0.6.2
*/
struct is_alpha_predicate_t
{
RESTINIO_NODISCARD
bool
operator()( const char actual ) const noexcept
{
return is_alpha(actual);
}
};
//
// is_alphanum_predicate_t
//
/*!
* @brief A preducate for symbol_producer_template that checks that
* a symbol is an alpha or numeric.
*
* @since v.0.6.2
*/
struct is_alphanum_predicate_t
{
RESTINIO_NODISCARD
bool
operator()( const char actual ) const noexcept
{
return is_alpha(actual) || is_digit(actual);
}
};
//
// is_vchar
//
/*!
* @brief Is a character a VCHAR?
*
* See: https://tools.ietf.org/html/rfc5234#appendix-B.1
*
* @since v.0.6.1
*/
RESTINIO_NODISCARD
inline constexpr bool
is_vchar( const char ch ) noexcept
{
return (ch >= '\x21' && ch <= '\x7E');
}
//
// is_vchar_predicate_t
//
/*!
* @brief A preducate for symbol_producer_template that checks that
* a symbol is a VCHAR.
*
* @since v.0.6.2
*/
struct is_vchar_predicate_t
{
RESTINIO_NODISCARD
bool
operator()( const char actual ) const noexcept
{
return is_vchar(actual);
}
};
//
// is_obs_text
//
/*!
* @brief Is a character an obs_text?
*
* See: https://tools.ietf.org/html/rfc7230
*
* @since v.0.6.1
*/
RESTINIO_NODISCARD
inline constexpr bool
is_obs_text( const char ch ) noexcept
{
constexpr unsigned short left = 0x80u;
constexpr unsigned short right = 0xFFu;
const unsigned short t = static_cast<unsigned short>(
static_cast<unsigned char>(ch));
return (t >= left && t <= right);
}
//
// is_qdtext
//
/*!
* @brief Is a character a qdtext?
*
* See: https://tools.ietf.org/html/rfc7230
*
* @since v.0.6.1
*/
RESTINIO_NODISCARD
inline constexpr bool
is_qdtext( const char ch ) noexcept
{
return ch == SP ||
ch == HTAB ||
ch == '!' ||
(ch >= '\x23' && ch <= '\x5B') ||
(ch >= '\x5D' && ch <= '\x7E') ||
is_obs_text( ch );
}
//
// is_ctext
//
/*!
* @brief Is a character a ctext?
*
* See: https://tools.ietf.org/html/rfc7230
*
* @since v.0.6.4
*/
RESTINIO_NODISCARD
inline constexpr bool
is_ctext( const char ch ) noexcept
{
return ch == SP ||
ch == HTAB ||
(ch >= '\x21' && ch <= '\x27') ||
(ch >= '\x2A' && ch <= '\x5B') ||
(ch >= '\x5D' && ch <= '\x7E') ||
is_obs_text( ch );
}
//
// is_ctext_predicate_t
//
/*!
* @brief A preducate for symbol_producer_template that checks that
* a symbol is a ctext.
*
* @since v.0.6.4
*/
struct is_ctext_predicate_t
{
RESTINIO_NODISCARD
bool
operator()( const char actual ) const noexcept
{
return is_ctext(actual);
}
};
//
// is_token_char_predicate_t
//
/*!
* @brief A predicate for symbol_producer_template that checks that
* a symbol can be used inside a token.
*/
struct is_token_char_predicate_t
{
RESTINIO_NODISCARD
static constexpr bool
is_token_char( const char ch ) noexcept
{
return is_alpha(ch) || is_digit(ch) ||
ch == '!' ||
ch == '#' ||
ch == '$' ||
ch == '%' ||
ch == '&' ||
ch == '\'' ||
ch == '*' ||
ch == '+' ||
ch == '-' ||
ch == '.' ||
ch == '^' ||
ch == '_' ||
ch == '`' ||
ch == '|' ||
ch == '~';
}
RESTINIO_NODISCARD
bool
operator()( const char actual ) const noexcept
{
return is_token_char(actual);
}
};
//
// ows_producer_t
//
/*!
* @brief A producer for OWS.
*
* If an OWS found in the input stream it produces non-empty
* optional_t<char> with SP as the value.
*
* See: https://tools.ietf.org/html/rfc7230
*
* @since v.0.6.1
*/
class ows_producer_t : public producer_tag< restinio::optional_t<char> >
{
public :
RESTINIO_NODISCARD
expected_t< result_type, parse_error_t >
try_parse(
source_t & from ) const noexcept
{
std::size_t extracted_spaces{};
character_t ch;
for( ch = from.getch();
!ch.m_eof && is_space(ch.m_ch);
ch = from.getch() )
{
++extracted_spaces;
}
if( !ch.m_eof )
// The first non-space char should be returned back.
from.putback();
if( extracted_spaces > 0u )
return result_type{ ' ' };
return result_type{ nullopt };
}
};
//
// token_producer_t
//
/*!
* @brief A producer for token.
*
* If a token is found in the input stream it produces std::string
* with the value of that token.
*
* See: https://tools.ietf.org/html/rfc7230
*
* @since v.0.6.1
*/
class token_producer_t : public producer_tag< std::string >
{
RESTINIO_NODISCARD
static optional_t< parse_error_t >
try_parse_value( source_t & from, std::string & accumulator )
{
error_reason_t reason = error_reason_t::pattern_not_found;
do
{
const auto ch = from.getch();
if( ch.m_eof )
{
reason = error_reason_t::unexpected_eof;
break;
}
if( !is_token_char(ch.m_ch) )
{
from.putback();
reason = error_reason_t::unexpected_character;
break;
}
accumulator += ch.m_ch;
}
while( true );
if( accumulator.empty() )
{
return parse_error_t{ from.current_position(), reason };
}
return nullopt;
}
RESTINIO_NODISCARD
static constexpr bool
is_token_char( const char ch ) noexcept
{
return is_token_char_predicate_t::is_token_char( ch );
}
public :
RESTINIO_NODISCARD
expected_t< result_type, parse_error_t >
try_parse( source_t & from ) const
{
std::string value;
const auto try_result = try_parse_value( from, value );
if( !try_result )
return { std::move(value) };
else
return make_unexpected( *try_result );
}
};
//
// quoted_string_producer_t
//
/*!
* @brief A producer for quoted_string.
*
* If a quoted_string is found in the input stream it produces std::string
* with the value of that token.
*
* See: https://tools.ietf.org/html/rfc7230
*
* @since v.0.6.1
*/
class quoted_string_producer_t : public producer_tag< std::string >
{
RESTINIO_NODISCARD
static optional_t< parse_error_t >
try_parse_value( source_t & from, std::string & accumulator )
{
error_reason_t reason = error_reason_t::pattern_not_found;
bool second_quote_extracted{ false };
do
{
const auto ch = from.getch();
if( ch.m_eof )
{
reason = error_reason_t::unexpected_eof;
break;
}
if( '"' == ch.m_ch )
second_quote_extracted = true;
else if( '\\' == ch.m_ch )
{
const auto next = from.getch();
if( next.m_eof )
{
reason = error_reason_t::unexpected_eof;
break;
}
else if( SP == next.m_ch || HTAB == next.m_ch ||
is_vchar( next.m_ch ) ||
is_obs_text( next.m_ch ) )
{
accumulator += next.m_ch;
}
else
{
reason = error_reason_t::unexpected_character;
from.putback();
break;
}
}
else if( is_qdtext( ch.m_ch ) )
accumulator += ch.m_ch;
else
{
reason = error_reason_t::unexpected_character;
from.putback();
break;
}
}
while( !second_quote_extracted );
if( !second_quote_extracted )
return parse_error_t{ from.current_position(), reason };
else
return nullopt;
}
public :
RESTINIO_NODISCARD
expected_t< result_type, parse_error_t >
try_parse( source_t & from ) const
{
source_t::content_consumer_t consumer{ from };
const auto ch = from.getch();
if( !ch.m_eof )
{
if( '"' == ch.m_ch )
{
std::string value;
const auto try_result = try_parse_value( from, value );
if( !try_result )
{
consumer.commit();
return { std::move(value) };
}
else
return make_unexpected( *try_result );
}
else
{
return make_unexpected( parse_error_t{
consumer.started_at(),
error_reason_t::unexpected_character
} );
}
}
else
return make_unexpected( parse_error_t{
consumer.started_at(),
error_reason_t::unexpected_eof
} );
}
};
//
// quoted_pair_producer_t
//
/*!
* @brief A producer for quoted_pair.
*
* If a quoted_pair is found in the input stream it produces char
* with the value of that token.
*
* See: https://tools.ietf.org/html/rfc7230
*
* @since v.0.6.4
*/
class quoted_pair_producer_t : public producer_tag< char >
{
public :
RESTINIO_NODISCARD
expected_t< result_type, parse_error_t >
try_parse( source_t & from ) const
{
source_t::content_consumer_t consumer{ from };
error_reason_t reason = error_reason_t::unexpected_eof;
const auto ch = from.getch();
if( !ch.m_eof )
{
if( '\\' == ch.m_ch )
{
const auto next = from.getch();
if( !next.m_eof )
{
if( SP == next.m_ch || HTAB == next.m_ch ||
is_vchar( next.m_ch ) ||
is_obs_text( next.m_ch ) )
{
consumer.commit();
return next.m_ch;
}
reason = error_reason_t::unexpected_character;
}
}
else
reason = error_reason_t::unexpected_character;
}
return make_unexpected( parse_error_t{
from.current_position(),
reason
} );
}
};
//
// comment_producer_t
//
/*!
* @brief A producer for comment.
*
* If a comment is found in the input stream it produces std::string
* with the value of that token.
*
* Comment is defined that way:
@verbatim
comment = "(" *( ctext / quoted-pair / comment ) ")"
ctext = HTAB / SP / %x21-27 / %x2A-5B / %x5D-7E / obs-text
quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
@endverbatim
*
* See: https://tools.ietf.org/html/rfc7230
*
* @since v.0.6.4
*/
class comment_producer_t : public producer_tag< std::string >
{
public :
RESTINIO_NODISCARD
expected_t< result_type, parse_error_t >
try_parse( source_t & from ) const; // NOTE: implementation below.
};
} /* namespace impl */
//
// alpha_symbol_producer
//
/*!
* @brief A factory for producer of ALPHA symbols.
*
* Usage example:
* @code
produce<std::string>(
repeat(1, 20, alpha_symbol_p() >> to_container());
* @endcode
*
* @since v.0.6.2
*/
RESTINIO_NODISCARD
inline auto
alpha_symbol_p()
{
return restinio::easy_parser::impl::symbol_producer_template_t<
impl::is_alpha_predicate_t >{};
}
//
// alphanum_symbol_producer
//
/*!
* @brief A factory for producer of symbol that an ALPHA or DIGIT.
*
* Usage example:
* @code
produce<std::string>(
repeat(1, 20, alphanum_symbol_p() >> to_container());
* @endcode
*
* @since v.0.6.2
*/
RESTINIO_NODISCARD
inline auto
alphanum_symbol_p()
{
return restinio::easy_parser::impl::symbol_producer_template_t<
impl::is_alphanum_predicate_t >{};
}
//
// vchar_symbol_producer
//
/*!
* @brief A factory for producer of VCHAR symbols.
*
* Usage example:
* @code
produce<std::string>(
repeat(1, 20, vchar_symbol_p() >> to_container());
* @endcode
*
* @since v.0.6.2
*/
RESTINIO_NODISCARD
inline auto
vchar_symbol_p()
{
return restinio::easy_parser::impl::symbol_producer_template_t<
impl::is_vchar_predicate_t >{};
}
//
// ctext_symbol_producer
//
/*!
* @brief A factory for producer of ctext symbols.
*
* Usage example:
* @code
produce<std::string>(
repeat(1, 20, ctext_symbol_p() >> to_container());
* @endcode
*
* @since v.0.6.4
*/
RESTINIO_NODISCARD
inline auto
ctext_symbol_p()
{
return restinio::easy_parser::impl::symbol_producer_template_t<
impl::is_ctext_predicate_t >{};
}
//
// comment_producer
//
/*!
* @brief A factory for producer of comment token.
*
* Usage example:
* @code
produce<std::string>(
alternatives(
token_p() >> as_result(),
comment_p() >> as_result()
)
);
* @endcode
*
* @since v.0.6.4
*/
RESTINIO_NODISCARD
inline auto
comment_p()
{
return impl::comment_producer_t{};
}
//
// ows_producer
//
/*!
* @brief A factory function to create an ows_producer.
*
* Usage example:
* @code
* produce<std::string>(
* ows_p() >> skip(),
* symbol('v'),
* symbol('='),
* ows_p() >> skip(),
* token_p() >> as_result()
* );
* @endcode
*
* @note
* Factory function ows() can be used instead of expression `ows_p() >> skip()`.
*
* @since v.0.6.1
*/
RESTINIO_NODISCARD
inline auto
ows_p() noexcept { return impl::ows_producer_t{}; }
//
// ows
//
/*!
* @brief A factory function to create an OWS clause.
*
* This clause handles an optional sequence of spaces in the input stream and
* skips the value of that sequence.
*
* Usage example:
* @code
* produce<std::string>(
* ows(),
* symbol('v'),
* symbol('='),
* ows(),
* token_p() >> as_result()
* );
* @endcode
* This expression corresponds the following rule:
@verbatim
T := OWS 'v' '=' OWS token
@endverbatim
*
* @since v.0.6.1
*/
RESTINIO_NODISCARD
inline auto
ows() noexcept { return ows_p() >> skip(); }
//
// token_symbol_producer
//
/*!
* @brief A factory for producer of symbols than can be used in tokens.
*
* Usage example:
* @code
produce<std::string>(
repeat(1, 20, token_symbol_p() >> to_container());
* @endcode
*
* @since v.0.6.9
*/
RESTINIO_NODISCARD
inline auto
token_symbol_p() noexcept
{
return restinio::easy_parser::impl::symbol_producer_template_t<
impl::is_token_char_predicate_t >{};
}
//
// token_producer
//
/*!
* @brief A factory function to create a token_producer.
*
* Usage example:
* @code
* using parameter = std::pair<std::string, std::string>;
* produce<parameter>(
* ows(),
* token_p() >> ¶meter::first,
* symbol('='),
* ows(),
* token_p() >> ¶meter::second
* );
* @endcode
*
* @since v.0.6.1
*/
RESTINIO_NODISCARD
inline auto
token_p() noexcept { return impl::token_producer_t{}; }
//
// quoted_string_producer
//
/*!
* @brief A factory function to create a quoted_string_producer.
*
* Usage example:
* @code
* using parameter = std::pair<std::string, std::string>;
* produce<parameter>(
* ows(),
* token_p() >> ¶meter::first,
* symbol('='),
* ows(),