docs: restructure parsing intro with correct snippets

fix #998
This commit is contained in:
Alan de Freitas
2026-05-13 16:15:48 -05:00
parent 585c7a6930
commit a34f3a4a1a
+12 -6
View File
@@ -104,6 +104,8 @@ https://datatracker.ietf.org/doc/html/rfc3986#section-3[__URI__,window=blank_]:
[source,cpp]
----
include::example$unit/snippets.cpp[tag=code_urls_parsing_1,indent=0]
include::example$unit/snippets.cpp[tag=code_urls_parsing_2,indent=0]
----
The function returns a cpp:result[] which holds a cpp:url_view[]
@@ -117,15 +119,19 @@ The caller is responsible for ensuring that the lifetime of the character buffer
These are the same semantics as that of cpp:std::string_view[].
====
For convenience, a URL view can be constructed directly from the character buffer in a cpp:string_view[].
In this case, it parses the string according to the
https://datatracker.ietf.org/doc/html/rfc3986#section-4.1[__URI-reference__,window=blank_]
grammar, throwing an exception upon failure.
The following two statements are equivalent:
We can immediately call cpp:result::value[] to obtain a cpp:url_view[]:
[source,cpp]
----
include::example$unit/snippets.cpp[tag=code_urls_parsing_2,indent=0]
include::example$unit/snippets.cpp[tag=snippet_parsing_3,indent=0]
----
Or, on a result that is known to hold a value, the shorter
cpp:result::operator*[]:
[source,cpp]
----
include::example$unit/snippets.cpp[tag=snippet_parsing_4,indent=0]
----
In this library, free functions which parse things are named with the word "parse" followed by the name of the grammar used to match the string.