Debian Codegraph @

lib/dat/string.hpp

raw symbols SCIP
1 /*
2 Copyright(C) 2011-2016 Brazil
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #pragma once
20
21 #include "dat.hpp"cxx . . $ `<file>/lib/dat/dat.hpp`/
22
23 namespace grncxx . . $ grn/ {
24 namespace datcxx . . $ grn/dat/ {
25
26 class GRN_DAT_APIcxx . . $ `lib/dat/dat.hpp:44:12`! Stringcxx . . $ grn/dat/String# {
27 public:
28 Stringcxx . . $ grn/dat/String#String(49f6e7a06ebc5aa8).()
29 : ptr_cxx . . $ grn/dat/String#ptr_.(NULLcxx . . $ `<external>/16391990256953433862/stddef.h:416:9`!),
30 length_cxx . . $ grn/dat/String#length_.(0) {}
31 Stringcxx . . $ grn/dat/String#String(d249e89a313417f2).(const void *ptr, UInt32cxx . . $ grn/dat/UInt32# length)
32 : ptr_cxx . . $ grn/dat/String#ptr_.(static_cast<const UInt8cxx . . $ grn/dat/UInt8# *>(ptr)),
33 length_cxx . . $ grn/dat/String#length_.(length) {}
34 template <UInt32cxx . . $ grn/dat/UInt32# T>
35 explicit Stringcxx . . $ grn/dat/String#String(b5278325fd32efb2).(const char (&str)[T])
36 : ptr_cxx . . $ grn/dat/String#ptr_.(reinterpret_cast<const UInt8cxx . . $ grn/dat/UInt8# *>(str)),
37 length_cxx . . $ grn/dat/String#length_.(T - 1) {}
38 Stringcxx . . $ grn/dat/String#String(134f24f25bda342e).(const Stringcxx . . $ grn/dat/String# &rhs)
39 : ptr_cxx . . $ grn/dat/String#ptr_.(rhs.ptr_cxx . . $ grn/dat/String#ptr_.),
40 length_cxx . . $ grn/dat/String#length_.(rhs.length_cxx . . $ grn/dat/String#length_.) {}
41
42 Stringcxx . . $ grn/dat/String# &operatorcxx . . $ grn/dat/String#`operator=`(d49b71f0ca34c700).=(const Stringcxx . . $ grn/dat/String# &rhs) {
43 set_ptrcxx . . $ grn/dat/String#set_ptr(e4289f82fef2c2f9).(rhs.ptrcxx . . $ grn/dat/String#ptr(3a8ef3fdc6e817ef).());
44 set_lengthcxx . . $ grn/dat/String#set_length(cb2f890c2fdad230).(rhs.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).());
45 return *this;
46 }
47
48 const UInt8cxx . . $ grn/dat/UInt8# &operatorcxx . . $ grn/dat/String#`operator[]`(ffeb5165310d7d37).[](UInt32cxx . . $ grn/dat/UInt32# i) const {
49 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(i >= length_);
50 return ptr_cxx . . $ grn/dat/String#ptr_.[i];
51 }
52
53 const void *ptrcxx . . $ grn/dat/String#ptr(3a8ef3fdc6e817ef).() const {
54 return ptr_cxx . . $ grn/dat/String#ptr_.;
55 }
56 UInt32cxx . . $ grn/dat/UInt32# lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).() const {
57 return length_cxx . . $ grn/dat/String#length_.;
58 }
59
60 void set_ptrcxx . . $ grn/dat/String#set_ptr(e4289f82fef2c2f9).(const void *x) {
61 ptr_cxx . . $ grn/dat/String#ptr_. = static_cast<const UInt8cxx . . $ grn/dat/UInt8# *>(x);
62 }
63 void set_lengthcxx . . $ grn/dat/String#set_length(cb2f890c2fdad230).(UInt32cxx . . $ grn/dat/UInt32# x) {
64 length_cxx . . $ grn/dat/String#length_. = x;
65 }
66
67 void assigncxx . . $ grn/dat/String#assign(d249e89a313417f2).(const void *ptr, UInt32cxx . . $ grn/dat/UInt32# length) {
68 set_ptrcxx . . $ grn/dat/String#set_ptr(e4289f82fef2c2f9).(ptr);
69 set_lengthcxx . . $ grn/dat/String#set_length(cb2f890c2fdad230).(length);
70 }
71
72 Stringcxx . . $ grn/dat/String# substrcxx . . $ grn/dat/String#substr(1af755882084cfb1).(UInt32cxx . . $ grn/dat/UInt32# offset = 0) const {
73 return Stringcxx . . $ grn/dat/String#String(d249e89a313417f2).(ptr_cxx . . $ grn/dat/String#ptr_. + offset, length_cxx . . $ grn/dat/String#length_. - offset);
74 }
75 Stringcxx . . $ grn/dat/String# substrcxx . . $ grn/dat/String#substr(31e796a9d948593a).(UInt32cxx . . $ grn/dat/UInt32# offset, UInt32cxx . . $ grn/dat/UInt32# length) const {
76 return Stringcxx . . $ grn/dat/String#String(d249e89a313417f2).(ptr_cxx . . $ grn/dat/String#ptr_. + offset, length);
77 }
78
79 // This function returns an integer as follows:
80 // - a negative value if *this < rhs,
81 // - zero if *this == rhs,
82 // - a positive value if *this > rhs,
83 // but if the offset is too large, the result is undefined.
84 int comparecxx . . $ grn/dat/String#compare(6575af31c4a8b936).(const Stringcxx . . $ grn/dat/String# &rhs, UInt32cxx . . $ grn/dat/UInt32# offset = 0) const {
85 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(offset > length());
86 GRN_DAT_DEBUG_THROW_IFcxx . . $ `lib/dat/dat.hpp:242:10`!(offset > rhs.length());
87
88 for (UInt32cxx . . $ grn/dat/UInt32# i = offset; i < lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).(); ++i) {
89 if (i >= rhs.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).()) {
90 return 1;
91 } else if ((*this)[cxx . . $ grn/dat/String#`operator[]`(ffeb5165310d7d37).i] != rhs[cxx . . $ grn/dat/String#`operator[]`(ffeb5165310d7d37).i]) {
92 return (*this)[cxx . . $ grn/dat/String#`operator[]`(ffeb5165310d7d37).i] - rhs[cxx . . $ grn/dat/String#`operator[]`(ffeb5165310d7d37).i];
93 }
94 }
95 return (lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).() == rhs.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).()) ? 0 : -1;
96 }
97
98 bool starts_withcxx . . $ grn/dat/String#starts_with(1685036b73fd3916).(const Stringcxx . . $ grn/dat/String# &str) const {
99 if (lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).() < str.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).()) {
100 return false;
101 }
102 for (UInt32cxx . . $ grn/dat/UInt32# i = 0; i < str.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).(); ++i) {
103 if ((*this)[cxx . . $ grn/dat/String#`operator[]`(ffeb5165310d7d37).i] != str[cxx . . $ grn/dat/String#`operator[]`(ffeb5165310d7d37).i]) {
104 return false;
105 }
106 }
107 return true;
108 }
109
110 bool ends_withcxx . . $ grn/dat/String#ends_with(1685036b73fd3916).(const Stringcxx . . $ grn/dat/String# &str) const {
111 if (lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).() < str.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).()) {
112 return false;
113 }
114 UInt32cxx . . $ grn/dat/UInt32# offset = lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).() - str.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).();
115 for (UInt32cxx . . $ grn/dat/UInt32# i = 0; i < str.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).(); ++i) {
116 if ((*this)[cxx . . $ grn/dat/String#`operator[]`(ffeb5165310d7d37).offset + i] != str[cxx . . $ grn/dat/String#`operator[]`(ffeb5165310d7d37).i]) {
117 return false;
118 }
119 }
120 return true;
121 }
122
123 void swapcxx . . $ grn/dat/String#swap(4b87ba8cc331336f).(Stringcxx . . $ grn/dat/String# *rhs) {
124 const UInt8cxx . . $ grn/dat/UInt8# * const ptr_temp = ptr_cxx . . $ grn/dat/String#ptr_.;
125 ptr_cxx . . $ grn/dat/String#ptr_. = rhs->ptr_cxx . . $ grn/dat/String#ptr_.;
126 rhs->ptr_cxx . . $ grn/dat/String#ptr_. = ptr_temp;
127
128 const UInt32cxx . . $ grn/dat/UInt32# length_temp = length_cxx . . $ grn/dat/String#length_.;
129 length_cxx . . $ grn/dat/String#length_. = rhs->length_cxx . . $ grn/dat/String#length_.;
130 rhs->length_cxx . . $ grn/dat/String#length_. = length_temp;
131 }
132
133 private:
134 const UInt8cxx . . $ grn/dat/UInt8# *ptr_cxx . . $ grn/dat/String#ptr_.;
135 UInt32cxx . . $ grn/dat/UInt32# length_cxx . . $ grn/dat/String#length_.;
136 };
137
138 inline bool operatorcxx . . $ grn/dat/`operator==`(d92c12cfb095b7ec).==(const Stringcxx . . $ grn/dat/String# &lhs, const Stringcxx . . $ grn/dat/String# &rhs) {
139 if (lhs.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).() != rhs.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).()) {
140 return false;
141 } else if (lhs.ptrcxx . . $ grn/dat/String#ptr(3a8ef3fdc6e817ef).() == rhs.ptrcxx . . $ grn/dat/String#ptr(3a8ef3fdc6e817ef).()) {
142 return true;
143 }
144 for (UInt32cxx . . $ grn/dat/UInt32# i = 0; i < lhs.lengthcxx . . $ grn/dat/String#length(ddd8539a2fcdd4ce).(); ++i) {
145 if (lhs[cxx . . $ grn/dat/String#`operator[]`(ffeb5165310d7d37).i] != rhs[cxx . . $ grn/dat/String#`operator[]`(ffeb5165310d7d37).i]) {
146 return false;
147 }
148 }
149 return true;
150 }
151
152 inline bool operatorcxx . . $ grn/dat/`operator!=`(d92c12cfb095b7ec).!=(const Stringcxx . . $ grn/dat/String# &lhs, const Stringcxx . . $ grn/dat/String# &rhs) {
153 return !(lhs ==cxx . . $ grn/dat/`operator==`(d92c12cfb095b7ec). rhs);
154 }
155
156 inline bool operatorcxx . . $ grn/dat/`operator<`(d92c12cfb095b7ec).<(const Stringcxx . . $ grn/dat/String# &lhs, const Stringcxx . . $ grn/dat/String# &rhs) {
157 return lhs.comparecxx . . $ grn/dat/String#compare(6575af31c4a8b936).(rhs) < 0;
158 }
159
160 inline bool operatorcxx . . $ grn/dat/`operator>`(d92c12cfb095b7ec).>(const Stringcxx . . $ grn/dat/String# &lhs, const Stringcxx . . $ grn/dat/String# &rhs) {
161 return rhs <cxx . . $ grn/dat/`operator<`(d92c12cfb095b7ec). lhs;
162 }
163
164 inline bool operatorcxx . . $ grn/dat/`operator<=`(d92c12cfb095b7ec).<=(const Stringcxx . . $ grn/dat/String# &lhs, const Stringcxx . . $ grn/dat/String# &rhs) {
165 return !(lhs >cxx . . $ grn/dat/`operator>`(d92c12cfb095b7ec). rhs);
166 }
167
168 inline bool operatorcxx . . $ grn/dat/`operator>=`(d92c12cfb095b7ec).>=(const Stringcxx . . $ grn/dat/String# &lhs, const Stringcxx . . $ grn/dat/String# &rhs) {
169 return !(lhs <cxx . . $ grn/dat/`operator<`(d92c12cfb095b7ec). rhs);
170 }
171
172 } // namespace dat
173 } // namespace grn