Skip to content

Commit f1f3f46

Browse files
authored
Merge pull request #2326 from hzeller/feature-20250113-use-std-stringview
Use std::string_view instead of absl::string_view.
2 parents a05622e + b7ff052 commit f1f3f46

File tree

430 files changed

+3083
-3454
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

430 files changed

+3083
-3454
lines changed

.github/bin/check-potential-problems.sh

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,12 @@
1919

2020
EXIT_CODE=0
2121

22-
# std::string_view::iterator is a const char* in gcc, clang, and absl C++ libs.
23-
# This resulted into the assumption that it is in many places in this code base.
24-
#
25-
# On Windows the iterator is a wrapping object, so breaking that assumption.
26-
#
27-
# So, until these assumptions are fixed, we need to use absl::string_view that
28-
# comes with the same implementation everywhere.
22+
# absl has a string_view but there is also std::string_view.
23+
# Use the std::string_view throughout.
2924
find verible -name "*.h" -o -name "*.cc" | \
30-
xargs grep -n "std::string_view"
25+
xargs grep -n "absl::string_view"
3126
if [ $? -eq 0 ]; then
32-
echo "::error:: use absl::string_view instead of std::string_view"
27+
echo "::error:: use std::string_view instead of absl::string_view"
3328
echo
3429
EXIT_CODE=1
3530
fi

external_libs/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ cc_test(
2222
deps = [
2323
":editscript",
2424
"@abseil-cpp//absl/strings",
25-
"@abseil-cpp//absl/strings:string_view",
2625
"@googletest//:gtest",
2726
"@googletest//:gtest_main",
2827
],

external_libs/editscript_test.cc

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
#include <iterator>
2121
#include <sstream>
2222
#include <string>
23+
#include <string_view>
2324
#include <vector>
2425

2526
#include "absl/strings/str_join.h"
26-
#include "absl/strings/string_view.h"
2727
#include "gtest/gtest.h"
2828

2929
namespace diff {
@@ -168,8 +168,8 @@ TEST(DiffTest, CheckNonConstStringVectorDiffResults) {
168168
}
169169

170170
TEST(DiffTest, CompleteDeletion) {
171-
const std::vector<absl::string_view> tokens1{"the", "fox"};
172-
const std::vector<absl::string_view> tokens2;
171+
const std::vector<std::string_view> tokens1{"the", "fox"};
172+
const std::vector<std::string_view> tokens2;
173173

174174
const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(),
175175
tokens2.begin(), tokens2.end());
@@ -182,8 +182,8 @@ TEST(DiffTest, CompleteDeletion) {
182182
}
183183

184184
TEST(DiffTest, CompleteInsertion) {
185-
const std::vector<absl::string_view> tokens1;
186-
const std::vector<absl::string_view> tokens2{"jumped", "over", "me"};
185+
const std::vector<std::string_view> tokens1;
186+
const std::vector<std::string_view> tokens2{"jumped", "over", "me"};
187187

188188
const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(),
189189
tokens2.begin(), tokens2.end());
@@ -196,8 +196,8 @@ TEST(DiffTest, CompleteInsertion) {
196196
}
197197

198198
TEST(DiffTest, ReplaceFromOneDifferentElement) {
199-
const std::vector<absl::string_view> tokens1{"fox"};
200-
const std::vector<absl::string_view> tokens2{"jumped", "over", "me"};
199+
const std::vector<std::string_view> tokens1{"fox"};
200+
const std::vector<std::string_view> tokens2{"jumped", "over", "me"};
201201

202202
const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(),
203203
tokens2.begin(), tokens2.end());
@@ -211,8 +211,8 @@ TEST(DiffTest, ReplaceFromOneDifferentElement) {
211211
}
212212

213213
TEST(DiffTest, ReplaceToOneDifferentElement) {
214-
const std::vector<absl::string_view> tokens1{"jumped", "over", "me"};
215-
const std::vector<absl::string_view> tokens2{"fox"};
214+
const std::vector<std::string_view> tokens1{"jumped", "over", "me"};
215+
const std::vector<std::string_view> tokens2{"fox"};
216216

217217
const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(),
218218
tokens2.begin(), tokens2.end());
@@ -226,8 +226,8 @@ TEST(DiffTest, ReplaceToOneDifferentElement) {
226226
}
227227

228228
TEST(DiffTest, CompleteReplacement) {
229-
const std::vector<absl::string_view> tokens1{"the", "fox"};
230-
const std::vector<absl::string_view> tokens2{"jumped", "over", "me"};
229+
const std::vector<std::string_view> tokens1{"the", "fox"};
230+
const std::vector<std::string_view> tokens2{"jumped", "over", "me"};
231231

232232
const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(),
233233
tokens2.begin(), tokens2.end());
@@ -241,9 +241,9 @@ TEST(DiffTest, CompleteReplacement) {
241241
}
242242

243243
TEST(DiffTest, StrictSubsequence) {
244-
const std::vector<absl::string_view> tokens1{"the", "fox", "jumped", "over",
245-
"the", "dog", "."};
246-
const std::vector<absl::string_view> tokens2{"fox", "jumped", "over"};
244+
const std::vector<std::string_view> tokens1{"the", "fox", "jumped", "over",
245+
"the", "dog", "."};
246+
const std::vector<std::string_view> tokens2{"fox", "jumped", "over"};
247247

248248
const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(),
249249
tokens2.begin(), tokens2.end());
@@ -258,9 +258,9 @@ TEST(DiffTest, StrictSubsequence) {
258258
}
259259

260260
TEST(DiffTest, StrictSupersequence) {
261-
const std::vector<absl::string_view> tokens1{"fox", "jumped", "over"};
262-
const std::vector<absl::string_view> tokens2{"the", "fox", "jumped", "over",
263-
"the", "dog", "."};
261+
const std::vector<std::string_view> tokens1{"fox", "jumped", "over"};
262+
const std::vector<std::string_view> tokens2{"the", "fox", "jumped", "over",
263+
"the", "dog", "."};
264264

265265
const Edits actual = GetTokenDiffs(tokens1.begin(), tokens1.end(),
266266
tokens2.begin(), tokens2.end());

verible/common/analysis/BUILD

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ cc_library(
1919
name = "citation",
2020
srcs = ["citation.cc"],
2121
hdrs = ["citation.h"],
22-
deps = [
23-
"@abseil-cpp//absl/strings",
24-
"@abseil-cpp//absl/strings:string_view",
25-
],
22+
deps = ["@abseil-cpp//absl/strings"],
2623
)
2724

2825
cc_library(
@@ -40,7 +37,6 @@ cc_library(
4037
"//verible/common/util:logging",
4138
"//verible/common/util:spacer",
4239
"@abseil-cpp//absl/strings",
43-
"@abseil-cpp//absl/strings:string_view",
4440
],
4541
)
4642

@@ -50,7 +46,6 @@ cc_library(
5046
deps = [
5147
":lint-rule-status",
5248
"@abseil-cpp//absl/status",
53-
"@abseil-cpp//absl/strings:string_view",
5449
],
5550
)
5651

@@ -81,7 +76,6 @@ cc_library(
8176
"//verible/common/text:token-stream-view",
8277
"//verible/common/util:iterator-range",
8378
"//verible/common/util:logging",
84-
"@abseil-cpp//absl/strings:string_view",
8579
],
8680
)
8781

@@ -97,7 +91,6 @@ cc_library(
9791
"//verible/common/util:user-interaction",
9892
"@abseil-cpp//absl/status",
9993
"@abseil-cpp//absl/strings",
100-
"@abseil-cpp//absl/strings:string_view",
10194
],
10295
)
10396

@@ -111,7 +104,6 @@ cc_test(
111104
"//verible/common/text:constants",
112105
"//verible/common/text:token-info",
113106
"//verible/common/text:token-info-test-util",
114-
"@abseil-cpp//absl/strings:string_view",
115107
"@googletest//:gtest",
116108
"@googletest//:gtest_main",
117109
],
@@ -138,7 +130,6 @@ cc_library(
138130
"@abseil-cpp//absl/status",
139131
"@abseil-cpp//absl/status:statusor",
140132
"@abseil-cpp//absl/strings",
141-
"@abseil-cpp//absl/strings:string_view",
142133
"@re2",
143134
],
144135
)
@@ -160,7 +151,6 @@ cc_library(
160151
"//verible/common/util:logging",
161152
"//verible/common/util:spacer",
162153
"@abseil-cpp//absl/status",
163-
"@abseil-cpp//absl/strings:string_view",
164154
],
165155
)
166156

@@ -177,7 +167,6 @@ cc_library(
177167
"//verible/common/util:logging",
178168
"@abseil-cpp//absl/status",
179169
"@abseil-cpp//absl/strings",
180-
"@abseil-cpp//absl/strings:string_view",
181170
"@googletest//:gtest", # for library testonly
182171
],
183172
)
@@ -195,7 +184,6 @@ cc_library(
195184
"//verible/common/text:tree-utils",
196185
"//verible/common/util:algorithm",
197186
"//verible/common/util:logging",
198-
"@abseil-cpp//absl/strings:string_view",
199187
],
200188
)
201189

@@ -207,7 +195,6 @@ cc_library(
207195
":line-lint-rule",
208196
":lint-rule-status",
209197
"//verible/common/util:logging",
210-
"@abseil-cpp//absl/strings:string_view",
211198
],
212199
)
213200

@@ -222,17 +209,13 @@ cc_library(
222209
":linter-test-utils",
223210
"//verible/common/text:text-structure",
224211
"//verible/common/util:logging",
225-
"@abseil-cpp//absl/strings:string_view",
226212
],
227213
)
228214

229215
cc_library(
230216
name = "line-lint-rule",
231217
hdrs = ["line-lint-rule.h"],
232-
deps = [
233-
":lint-rule",
234-
"@abseil-cpp//absl/strings:string_view",
235-
],
218+
deps = [":lint-rule"],
236219
)
237220

238221
cc_library(
@@ -261,7 +244,6 @@ cc_library(
261244
":syntax-tree-linter",
262245
"//verible/common/text:text-structure",
263246
"//verible/common/util:logging",
264-
"@abseil-cpp//absl/strings:string_view",
265247
],
266248
)
267249

@@ -301,7 +283,6 @@ cc_library(
301283
":text-structure-lint-rule",
302284
"//verible/common/text:text-structure",
303285
"//verible/common/util:logging",
304-
"@abseil-cpp//absl/strings:string_view",
305286
],
306287
)
307288

@@ -316,7 +297,6 @@ cc_library(
316297
":text-structure-linter",
317298
"//verible/common/text:text-structure",
318299
"//verible/common/util:logging",
319-
"@abseil-cpp//absl/strings:string_view",
320300
],
321301
)
322302

@@ -326,7 +306,6 @@ cc_library(
326306
deps = [
327307
":lint-rule",
328308
"//verible/common/text:text-structure",
329-
"@abseil-cpp//absl/strings:string_view",
330309
],
331310
)
332311

@@ -353,7 +332,6 @@ cc_library(
353332
":token-stream-linter",
354333
"//verible/common/text:text-structure",
355334
"//verible/common/util:logging",
356-
"@abseil-cpp//absl/strings:string_view",
357335
],
358336
)
359337

@@ -375,7 +353,6 @@ cc_test(
375353
"//verible/common/text:token-info",
376354
"//verible/common/text:tree-builder-test-util",
377355
"@abseil-cpp//absl/strings",
378-
"@abseil-cpp//absl/strings:string_view",
379356
"@googletest//:gtest",
380357
"@googletest//:gtest_main",
381358
],
@@ -391,7 +368,6 @@ cc_test(
391368
"//verible/common/text:token-info",
392369
"//verible/common/text:token-stream-view",
393370
"//verible/common/util:iterator-range",
394-
"@abseil-cpp//absl/strings:string_view",
395371
"@googletest//:gtest",
396372
"@googletest//:gtest_main",
397373
],
@@ -407,7 +383,6 @@ cc_test(
407383
"//verible/common/text:token-info",
408384
"@abseil-cpp//absl/status",
409385
"@abseil-cpp//absl/strings",
410-
"@abseil-cpp//absl/strings:string_view",
411386
"@googletest//:gtest",
412387
"@googletest//:gtest_main",
413388
],
@@ -421,7 +396,6 @@ cc_test(
421396
":linter-test-utils",
422397
"//verible/common/util:range",
423398
"@abseil-cpp//absl/strings",
424-
"@abseil-cpp//absl/strings:string_view",
425399
"@googletest//:gtest",
426400
"@googletest//:gtest_main",
427401
],
@@ -435,7 +409,6 @@ cc_test(
435409
":line-linter",
436410
":lint-rule-status",
437411
"//verible/common/text:token-info",
438-
"@abseil-cpp//absl/strings:string_view",
439412
"@googletest//:gtest",
440413
"@googletest//:gtest_main",
441414
],
@@ -455,7 +428,6 @@ cc_test(
455428
"//verible/common/text:token-info",
456429
"//verible/common/text:tree-builder-test-util",
457430
"//verible/common/util:casts",
458-
"@abseil-cpp//absl/strings:string_view",
459431
"@googletest//:gtest",
460432
"@googletest//:gtest_main",
461433
],
@@ -485,7 +457,6 @@ cc_test(
485457
"//verible/common/text:tree-builder-test-util",
486458
"//verible/common/util:range",
487459
"@abseil-cpp//absl/strings",
488-
"@abseil-cpp//absl/strings:string_view",
489460
"@googletest//:gtest",
490461
"@googletest//:gtest_main",
491462
],
@@ -501,7 +472,6 @@ cc_test(
501472
"//verible/common/text:text-structure",
502473
"//verible/common/text:token-info",
503474
"@abseil-cpp//absl/strings",
504-
"@abseil-cpp//absl/strings:string_view",
505475
"@googletest//:gtest",
506476
"@googletest//:gtest_main",
507477
],
@@ -516,7 +486,6 @@ cc_test(
516486
":token-stream-linter",
517487
"//verible/common/text:token-info",
518488
"//verible/common/text:token-stream-view",
519-
"@abseil-cpp//absl/strings:string_view",
520489
"@googletest//:gtest",
521490
"@googletest//:gtest_main",
522491
],

verible/common/analysis/citation.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
#include "verible/common/analysis/citation.h"
1616

1717
#include <string>
18+
#include <string_view>
1819

1920
#include "absl/strings/str_cat.h"
20-
#include "absl/strings/string_view.h"
2121

2222
namespace verible {
23-
std::string GetStyleGuideCitation(absl::string_view topic) {
23+
std::string GetStyleGuideCitation(std::string_view topic) {
2424
return absl::StrCat("[Style: ", topic, "]");
2525
}
2626
} // namespace verible

verible/common/analysis/citation.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
#define VERIBLE_COMMON_ANALYSIS_CITATION_H_
1717

1818
#include <string>
19-
20-
#include "absl/strings/string_view.h"
19+
#include <string_view>
2120

2221
namespace verible {
2322
// Given a styleguide topic, return a reference to some styleguide
2423
// citation for the given topic (e.g. just the topic-name or an URL).
25-
std::string GetStyleGuideCitation(absl::string_view topic);
24+
std::string GetStyleGuideCitation(std::string_view topic);
2625
} // namespace verible
2726

2827
#endif // VERIBLE_COMMON_ANALYSIS_CITATION_H_

verible/common/analysis/command-file-lexer.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
#include "verible/common/analysis/command-file-lexer.h"
1616

1717
#include <algorithm>
18+
#include <string_view>
1819
#include <vector>
1920

20-
#include "absl/strings/string_view.h"
2121
#include "verible/common/lexer/token-stream-adapter.h"
2222
#include "verible/common/text/token-info.h"
2323
#include "verible/common/text/token-stream-view.h"
@@ -26,7 +26,7 @@
2626

2727
namespace verible {
2828

29-
CommandFileLexer::CommandFileLexer(absl::string_view config)
29+
CommandFileLexer::CommandFileLexer(std::string_view config)
3030
: parent_lexer_type(config) {
3131
const auto lex_status = MakeTokenSequence(
3232
this, config, &tokens_, [&](const TokenInfo &error_token) {

0 commit comments

Comments
 (0)