add support for Ayatana indicator to Notification plugin
[claws.git] / src / plugins / litehtml_viewer / litehtml / tstring_view.h
blob384c8d7df592ac6e1bb1e0aa60c722b2607482b1
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.
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__
33 #include <cstddef>
34 #include <ostream>
36 #include "os_types.h"
38 namespace litehtml {
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).
48 class tstring_view {
49 public:
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;
68 public:
69 tstring_view() = default;
71 tstring_view(const tstring_view& other) = default;
73 tstring_view(const_pointer s, size_type size)
74 : data_(s)
75 , size_(size)
79 constexpr const_iterator begin() const
81 return data_;
84 constexpr const_iterator cbegin() const
86 return data_;
89 constexpr const_iterator end() const
91 return data_ + size_;
94 constexpr const_iterator cend() const
96 return data_ + size_;
99 constexpr const_reference operator[](size_type offset) const
101 return *(data_ + offset);
104 constexpr const_pointer data() const
106 return data_;
109 size_type size() const
111 return size_;
114 size_type length() const
116 return size_;
119 bool empty() const
121 return (size_ == 0);
124 private:
125 const_pointer data_ = nullptr;
127 size_type size_ = 0;
130 std::basic_ostream<tstring_view::value_type>& operator<<(
131 std::basic_ostream<tstring_view::value_type>&,
132 tstring_view str);
134 } // namespace litehtml
136 #endif // LITEHTML_TSTRING_VIEW_H__