Photon 1.0.0
Loading...
Searching...
No Matches
tstring_view.h
Go to the documentation of this file.
1// Copyright (C) 2020-2021 Primate Labs Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
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
13// distribution.
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.
17//
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.
29
30#ifndef LITEHTML_TSTRING_VIEW_H__
31#define LITEHTML_TSTRING_VIEW_H__
32
33#include <cstddef>
34#include <ostream>
35
36#include "types.h"
37
38namespace litehtml {
39
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).
42
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).
47
49public:
50 using value_type = char;
51
52 using pointer = char*;
53
54 using const_pointer = const char*;
55
56 using reference = char&;
57
58 using const_reference = const char&;
59
61
63
64 using size_type = size_t;
65
66 using difference_type = std::ptrdiff_t;
67
68public:
69 tstring_view() = default;
70
71 tstring_view(const tstring_view& other) = default;
72
78
79 constexpr const_iterator begin() const
80 {
81 return data_;
82 }
83
84 constexpr const_iterator cbegin() const
85 {
86 return data_;
87 }
88
89 constexpr const_iterator end() const
90 {
91 return data_ + size_;
92 }
93
94 constexpr const_iterator cend() const
95 {
96 return data_ + size_;
97 }
98
100 {
101 return *(data_ + offset);
102 }
103
104 constexpr const_pointer data() const
105 {
106 return data_;
107 }
108
110 {
111 return size_;
112 }
113
115 {
116 return size_;
117 }
118
119 bool empty() const
120 {
121 return (size_ == 0);
122 }
123
124private:
126
128};
129
130std::basic_ostream<tstring_view::value_type>& operator<<(
131 std::basic_ostream<tstring_view::value_type>&,
132 tstring_view str);
133
134} // namespace litehtml
135
136#endif // LITEHTML_TSTRING_VIEW_H__
Definition tstring_view.h:48
size_type size_
Definition tstring_view.h:127
const_pointer iterator
Definition tstring_view.h:60
const char & const_reference
Definition tstring_view.h:58
tstring_view(const_pointer s, size_type size)
Definition tstring_view.h:73
char value_type
Definition tstring_view.h:50
size_type length() const
Definition tstring_view.h:114
const char * const_pointer
Definition tstring_view.h:54
char * pointer
Definition tstring_view.h:52
constexpr const_iterator end() const
Definition tstring_view.h:89
constexpr const_pointer data() const
Definition tstring_view.h:104
const_pointer const_iterator
Definition tstring_view.h:62
const_pointer data_
Definition tstring_view.h:125
tstring_view(const tstring_view &other)=default
size_t size_type
Definition tstring_view.h:64
constexpr const_iterator cend() const
Definition tstring_view.h:94
char & reference
Definition tstring_view.h:56
constexpr const_iterator begin() const
Definition tstring_view.h:79
constexpr const_iterator cbegin() const
Definition tstring_view.h:84
constexpr const_reference operator[](size_type offset) const
Definition tstring_view.h:99
bool empty() const
Definition tstring_view.h:119
std::ptrdiff_t difference_type
Definition tstring_view.h:66
size_type size() const
Definition tstring_view.h:109
#define offset(member)
Definition css_properties.cpp:5
Definition background.h:12
std::basic_ostream< tstring_view::value_type > & operator<<(std::basic_ostream< tstring_view::value_type > &, tstring_view str)
Definition tstring_view.cpp:35
Definition types.h:89
s
Definition tag_strings.h:47