1 // Copyright (C) 2020-2021 Primate Labs Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
14 // * Neither the names of the copyright holders nor the names of their
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifndef LITEHTML_TSTRING_VIEW_H__
31 #define LITEHTML_TSTRING_VIEW_H__
40 // tstring_view is a string reference type that provides a view into a string
41 // that is owned elsewhere (e.g., by a std::string object).
43 // tstring_view implements the same interface as std::base_string_view in the
44 // standard library. When litehtml moves to C++17 consider replacing the
45 // tstring_view implementation with the standard library implementations
46 // (e.g., via a using statement).
50 using value_type
= char;
52 using pointer
= char*;
54 using const_pointer
= const char*;
56 using reference
= char&;
58 using const_reference
= const char&;
60 using iterator
= const_pointer
;
62 using const_iterator
= const_pointer
;
64 using size_type
= size_t;
66 using difference_type
= std::ptrdiff_t;
69 tstring_view() = default;
71 tstring_view(const tstring_view
& other
) = default;
73 tstring_view(const_pointer s
, size_type size
)
79 constexpr const_iterator
begin() const
84 constexpr const_iterator
cbegin() const
89 constexpr const_iterator
end() const
94 constexpr const_iterator
cend() const
99 constexpr const_reference
operator[](size_type offset
) const
101 return *(data_
+ offset
);
104 constexpr const_pointer
data() const
109 size_type
size() const
114 size_type
length() const
125 const_pointer data_
= nullptr;
130 std::basic_ostream
<tstring_view::value_type
>& operator<<(
131 std::basic_ostream
<tstring_view::value_type
>&,
134 } // namespace litehtml
136 #endif // LITEHTML_TSTRING_VIEW_H__