File: api.rst

package info (click to toggle)
ctre 3.9.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,084 kB
  • sloc: cpp: 80,452; makefile: 135; javascript: 69; python: 31
file content (100 lines) | stat: -rw-r--r-- 4,109 bytes parent folder | download | duplicates (2)
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
API
===

.. class:: ctll::fixed_string

  A compile-time fixed string.

  Example: ::

    static constexpr auto pattern = ctll::fixed_string{ "h.*" };
  
    constexpr auto match(std::string_view sv) noexcept {
    	return ctre::match<pattern>(sv);
    }

.. class:: template<class Iterator, class... Captures> ctre::regex_results

  .. type:: char_type = typename std::iterator_traits<Iterator>::value_type

    The character type used by the ``Iterator``.

  .. function:: template<size_t Id> constexpr captured_content<Id, void>::storage<Iterator> get()
                template<class Name> constexpr captured_content<deduced, Name>::storage<Iterator> get()
                template<ctll::fixed_string Name> constexpr captured_content<deduced, Name>::storage<Iterator> get()

    Returns the capture specified by ``Id`` or ``Name``. ID ``0`` is the full match, ID ``1`` is the first capture group, ID ``2`` is the second, etc.
    Named groups are specified using ``(?<name>)``.

    Example: ::

      if (auto m = ctre::match<"(?<chars>[a-z]+)([0-9]+)">("abc123")) {
        m.get<"chars">(); //abc
        m.get<2>(); //123
      }

  .. function:: constexpr size_t size()
    
    Returns the number of captures in this result object.

  .. function:: constexpr operator bool() const noexcept
    
    Returns whether the match was successful.

  .. function:: constexpr operator std::basic_string_view<char_type>() const noexcept
                constexpr std::basic_string_view<char_type> to_view() const noexcept
                constexpr std::basic_string_view<char_type> view() const noexcept

    Converts the match to a string view.

  .. function:: constexpr explicit operator std::basic_string<char_type>() const noexcept
                constexpr std::basic_string<char_type> to_string() const noexcept
                constexpr std::basic_string<char_type> str() const noexcept

    Converts the match to a string view. 

.. class:: template<size_t Id, typename Name = void> captured_content

   .. class:: template <typename Iterator> storage

      .. function:: constexpr auto begin() const noexcept
                    constexpr auto end() const noexcept

        Returns the begin or end iterator for the captured content.

      .. function:: constexpr operator bool() const noexcept

        Returns whether the match was successful.

      .. function:: constexpr auto size() const noexcept

        Returns the number of characters in the capture.

      .. function:: constexpr operator std::basic_string_view<char_type>() const noexcept
                    constexpr std::basic_string_view<char_type> to_view() const noexcept
                    constexpr std::basic_string_view<char_type> view() const noexcept

        Converts the capture to a string view.

      .. function:: constexpr explicit operator std::basic_string<char_type>() const noexcept
                    constexpr std::basic_string<char_type> to_string() const noexcept
                    constexpr std::basic_string<char_type> str() const noexcept

        Converts the capture to a string view. 

      .. function:: constexpr static size_t get_id() noexcept

        Returns ``Id``

.. function:: template<auto & RE, class... Args> constexpr ctre::regex_results<deduced> match(Args&&... args)
              template<ctll::fixed_string RE, class... Args> constexpr ctre::regex_results<deduced> match(Args&&... args)

  Matches ``RE`` against the whole input.
  ``Args...`` must be either a string-like object with ``begin`` and ``end`` member functions, or a pair of forward iterators. 

.. function:: template<auto & RE, class... Args> constexpr ctre::regex_results<deduced> search(Args&&... args)
              template<ctll::fixed_string RE, class... Args>  constexpr ctre::regex_results<deduced> search(Args&&... args)

  Searches for a match somewhere within the input.
  ``Args...`` must be either a string-like object with ``begin`` and ``end`` member functions, or a pair of forward iterators.