LIEF: Library to Instrument Executable Formats
Version 1.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
lief-install
x86_64
static
include
frozen
string.h
Go to the documentation of this file.
1
/*
2
* Frozen
3
* Copyright 2016 QuarksLab
4
*
5
* Licensed to the Apache Software Foundation (ASF) under one
6
* or more contributor license agreements. See the NOTICE file
7
* distributed with this work for additional information
8
* regarding copyright ownership. The ASF licenses this file
9
* to you under the Apache License, Version 2.0 (the
10
* "License"); you may not use this file except in compliance
11
* with the License. You may obtain a copy of the License at
12
*
13
* http://www.apache.org/licenses/LICENSE-2.0
14
*
15
* Unless required by applicable law or agreed to in writing,
16
* software distributed under the License is distributed on an
17
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18
* KIND, either express or implied. See the License for the
19
* specific language governing permissions and limitations
20
* under the License.
21
*/
22
23
#ifndef FROZEN_LETITGO_STRING_H
24
#define FROZEN_LETITGO_STRING_H
25
26
#include "
frozen/bits/elsa.h
"
27
#include "
frozen/bits/hash_string.h
"
28
#include "
frozen/bits/version.h
"
29
#include "
frozen/bits/defines.h
"
30
31
#include <cstddef>
32
#include <functional>
33
34
#ifdef FROZEN_LETITGO_HAS_STRING_VIEW
35
#include <string_view>
36
#endif
37
38
namespace
frozen
{
39
40
template
<
typename
_CharT>
41
class
basic_string
{
42
using
chr_t = _CharT;
43
44
chr_t
const
*data_;
45
std::size_t size_;
46
47
public
:
48
template
<std::
size_t
N>
49
constexpr
basic_string
(chr_t
const
(&
data
)[N])
50
: data_(
data
), size_(N - 1) {}
51
constexpr
basic_string
(chr_t
const
*
data
, std::size_t
size
)
52
: data_(
data
), size_(
size
) {}
53
54
#ifdef FROZEN_LETITGO_HAS_STRING_VIEW
55
constexpr
basic_string
(std::basic_string_view<chr_t>
data
)
56
: data_(
data
.
data
()), size_(
data
.
size
()) {}
57
58
explicit
constexpr
operator
std::basic_string_view<chr_t>()
const
{
59
return
std::basic_string_view<chr_t>(data_, size_);
60
}
61
#endif
62
63
constexpr
basic_string
(
const
basic_string
&)
noexcept
=
default
;
64
constexpr
basic_string
&
operator=
(
const
basic_string
&)
noexcept
=
default
;
65
66
constexpr
std::size_t
length
()
const
{
return
size_; }
67
constexpr
std::size_t
size
()
const
{
return
size_; }
68
69
constexpr
chr_t
operator[]
(std::size_t i)
const
{
return
data_[i]; }
70
71
constexpr
bool
operator==
(
basic_string
other)
const
{
72
if
(size_ != other.size_)
73
return
false
;
74
for
(std::size_t i = 0; i < size_; ++i)
75
if
(data_[i] != other.data_[i])
76
return
false
;
77
return
true
;
78
}
79
80
constexpr
bool
operator<
(
const
basic_string
&other)
const
{
81
unsigned
i = 0;
82
while
(i <
size
() && i < other.
size
()) {
83
if
((*
this
)[i] < other[i]) {
84
return
true
;
85
}
86
if
((*
this
)[i] > other[i]) {
87
return
false
;
88
}
89
++i;
90
}
91
return
size
() < other.
size
();
92
}
93
94
friend
constexpr
bool
operator>
(
const
basic_string
& lhs,
const
basic_string
& rhs) {
95
return
rhs < lhs;
96
}
97
friend
constexpr
bool
operator>=
(
const
basic_string
& lhs,
const
basic_string
& rhs) {
98
return
!(lhs < rhs);
99
}
100
friend
constexpr
bool
operator<=
(
const
basic_string
& lhs,
const
basic_string
& rhs) {
101
return
!(lhs > rhs);
102
}
103
104
constexpr
const
chr_t *
data
()
const
{
return
data_; }
105
constexpr
const
chr_t *
begin
()
const
{
return
data
(); }
106
constexpr
const
chr_t *
end
()
const
{
return
data
() +
size
(); }
107
};
108
109
template
<
typename
_CharT>
struct
elsa
<
basic_string
<_CharT>> {
110
constexpr
std::size_t
operator()
(
basic_string<_CharT>
value)
const
{
111
return
hash_string
(value);
112
}
113
constexpr
std::size_t
operator()
(
basic_string<_CharT>
value, std::size_t seed)
const
{
114
return
hash_string
(value, seed);
115
}
116
};
117
118
using
string
=
basic_string<char>
;
119
using
wstring
=
basic_string<wchar_t>
;
120
using
u16string
=
basic_string<char16_t>
;
121
using
u32string
=
basic_string<char32_t>
;
122
123
#ifdef FROZEN_LETITGO_HAS_CHAR8T
124
using
u8string =
basic_string<char8_t>
;
125
#endif
126
127
namespace
string_literals
{
128
129
constexpr
string
operator
""
_s(
const
char
*data, std::size_t size) {
130
return
{data, size};
131
}
132
133
constexpr
wstring
operator
""
_s(
const
wchar_t
*data, std::size_t size) {
134
return
{data, size};
135
}
136
137
constexpr
u16string
operator
""
_s(
const
char16_t
*data, std::size_t size) {
138
return
{data, size};
139
}
140
141
constexpr
u32string
operator
""
_s(
const
char32_t
*data, std::size_t size) {
142
return
{data, size};
143
}
144
145
#ifdef FROZEN_LETITGO_HAS_CHAR8T
146
constexpr
u8string
operator
""
_s(
const
char8_t
*data, std::size_t size) {
147
return
{data, size};
148
}
149
#endif
150
151
}
// namespace string_literals
152
153
}
// namespace frozen
154
155
namespace
std
{
156
template
<
typename
_CharT>
struct
hash<
frozen
::basic_string<_CharT>> {
157
std::size_t
operator()
(
frozen::basic_string<_CharT>
s)
const
{
158
return
frozen::elsa<frozen::basic_string<_CharT>
>{}(s);
159
}
160
};
161
}
// namespace std
162
163
#endif
frozen::basic_string
Definition
string.h:41
frozen::basic_string::operator<=
friend constexpr bool operator<=(const basic_string &lhs, const basic_string &rhs)
Definition
string.h:100
frozen::basic_string::operator<
constexpr bool operator<(const basic_string &other) const
Definition
string.h:80
frozen::basic_string::operator>
friend constexpr bool operator>(const basic_string &lhs, const basic_string &rhs)
Definition
string.h:94
frozen::basic_string::begin
constexpr const chr_t * begin() const
Definition
string.h:105
frozen::basic_string< char >::size
constexpr std::size_t size() const
Definition
string.h:67
frozen::basic_string::end
constexpr const chr_t * end() const
Definition
string.h:106
frozen::basic_string::operator[]
constexpr chr_t operator[](std::size_t i) const
Definition
string.h:69
frozen::basic_string::operator==
constexpr bool operator==(basic_string other) const
Definition
string.h:71
frozen::basic_string< char >::data
constexpr const chr_t * data() const
Definition
string.h:104
frozen::basic_string::basic_string
constexpr basic_string(chr_t const (&data)[N])
Definition
string.h:49
frozen::basic_string::length
constexpr std::size_t length() const
Definition
string.h:66
frozen::basic_string::basic_string
constexpr basic_string(const basic_string &) noexcept=default
frozen::basic_string::operator=
constexpr basic_string & operator=(const basic_string &) noexcept=default
frozen::basic_string::operator>=
friend constexpr bool operator>=(const basic_string &lhs, const basic_string &rhs)
Definition
string.h:97
frozen::basic_string::basic_string
constexpr basic_string(chr_t const *data, std::size_t size)
Definition
string.h:51
defines.h
elsa.h
version.h
hash_string.h
frozen::string_literals
Definition
string.h:127
frozen
Definition
algorithm.h:30
frozen::string
basic_string< char > string
Definition
string.h:118
frozen::u16string
basic_string< char16_t > u16string
Definition
string.h:120
frozen::u32string
basic_string< char32_t > u32string
Definition
string.h:121
frozen::hash_string
constexpr std::size_t hash_string(const String &value)
Definition
hash_string.h:9
frozen::wstring
basic_string< wchar_t > wstring
Definition
string.h:119
std
Definition
string.h:155
frozen::elsa< basic_string< _CharT > >::operator()
constexpr std::size_t operator()(basic_string< _CharT > value, std::size_t seed) const
Definition
string.h:113
frozen::elsa< basic_string< _CharT > >::operator()
constexpr std::size_t operator()(basic_string< _CharT > value) const
Definition
string.h:110
frozen::elsa
Definition
elsa.h:30
std::hash< frozen::basic_string< _CharT > >::operator()
std::size_t operator()(frozen::basic_string< _CharT > s) const
Definition
string.h:157
Generated by
1.17.0