Skip to content

Commit 35717a7

Browse files
authored
GH-48592: [C++] Use starts_with/ends_with methods (#48614)
### Rationale for this change The code previously used StartsWith and EndsWith utility functions. C++ now includes built-in starts_with and ends_with functions, rendering StartsWith and EndsWith unnecessary. ### What changes are included in this PR? All calls of StartsWith and EndsWith are replaces with starts_with and ends_with, respectively. The definition and tests for StartsWith and EndsWith have been deleted. ### Are these changes tested? Yes, all unit tests pass. ### Are there any user-facing changes? No. * GitHub Issue: #48592 Authored-by: Jonah Kelman <jonahkel@umich.edu> Signed-off-by: Antoine Pitrou <antoine@python.org>
1 parent 4b1ecca commit 35717a7

File tree

20 files changed

+33
-89
lines changed

20 files changed

+33
-89
lines changed

cpp/src/arrow/acero/tpch_node_test.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838

3939
namespace arrow {
4040

41-
using arrow::internal::StartsWith;
42-
4341
namespace acero {
4442
namespace internal {
4543

@@ -100,7 +98,7 @@ void VerifyUniqueKey(std::unordered_set<int32_t>* seen, const Datum& d, int32_t
10098
void VerifyStringAndNumber_Single(std::string_view row, std::string_view prefix,
10199
const int64_t i, const int32_t* nums,
102100
bool verify_padding) {
103-
ASSERT_TRUE(StartsWith(row, prefix)) << row << ", prefix=" << prefix << ", i=" << i;
101+
ASSERT_TRUE(row.starts_with(prefix)) << row << ", prefix=" << prefix << ", i=" << i;
104102
const char* num_str = row.data() + prefix.size();
105103
const char* num_str_end = row.data() + row.size();
106104
int64_t num = 0;

cpp/src/arrow/compute/expression.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ namespace arrow {
4747

4848
using internal::checked_cast;
4949
using internal::checked_pointer_cast;
50-
using internal::EndsWith;
5150
using internal::ToChars;
5251

5352
namespace compute {
@@ -180,7 +179,7 @@ std::string Expression::ToString() const {
180179
}
181180

182181
constexpr std::string_view kleene = "_kleene";
183-
if (EndsWith(call->function_name, kleene)) {
182+
if (call->function_name.ends_with(kleene)) {
184183
auto op = call->function_name.substr(0, call->function_name.size() - kleene.size());
185184
return binary(std::move(op));
186185
}

cpp/src/arrow/compute/kernels/scalar_string_ascii.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838

3939
namespace arrow {
4040

41-
using internal::EndsWith;
42-
using internal::StartsWith;
43-
4441
namespace compute {
4542
namespace internal {
4643

@@ -1291,7 +1288,7 @@ struct PlainStartsWithMatcher {
12911288
}
12921289

12931290
bool Match(std::string_view current) const {
1294-
return StartsWith(current, options_.pattern);
1291+
return current.starts_with(options_.pattern);
12951292
}
12961293
};
12971294

@@ -1309,7 +1306,7 @@ struct PlainEndsWithMatcher {
13091306
}
13101307

13111308
bool Match(std::string_view current) const {
1312-
return EndsWith(current, options_.pattern);
1309+
return current.ends_with(options_.pattern);
13131310
}
13141311
};
13151312

cpp/src/arrow/dataset/discovery.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535

3636
namespace arrow {
3737

38-
using internal::StartsWith;
39-
4038
namespace dataset {
4139

4240
namespace {
@@ -49,7 +47,7 @@ bool StartsWithAnyOf(const std::string& path, const std::vector<std::string>& pr
4947
auto parts = fs::internal::SplitAbstractPath(path);
5048
return std::any_of(parts.cbegin(), parts.cend(), [&](std::string_view part) {
5149
return std::any_of(prefixes.cbegin(), prefixes.cend(),
52-
[&](std::string_view prefix) { return StartsWith(part, prefix); });
50+
[&](std::string_view prefix) { return part.starts_with(prefix); });
5351
});
5452
}
5553

cpp/src/arrow/dataset/subtree_test.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131

3232
namespace arrow {
3333

34-
using internal::StartsWith;
35-
3634
using compute::field_ref;
3735
using compute::literal;
3836

@@ -112,7 +110,7 @@ bool IsAncestorOf(std::string_view ancestor, std::string_view descendant) {
112110
ancestor = RemoveTrailingSlash(ancestor);
113111
if (ancestor == "") return true;
114112
descendant = RemoveTrailingSlash(descendant);
115-
if (!StartsWith(descendant, ancestor)) return false;
113+
if (!descendant.starts_with(ancestor)) return false;
116114
descendant.remove_prefix(ancestor.size());
117115
if (descendant.empty()) return true;
118116
return descendant.front() == '/';

cpp/src/arrow/engine/simple_extension_type_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class SimpleExtensionType : public ExtensionType {
111111
void Fail() { params_ = std::nullopt; }
112112

113113
void Init(std::string_view class_name, std::string_view repr, size_t num_properties) {
114-
if (!::arrow::internal::StartsWith(repr, class_name)) return Fail();
114+
if (!repr.starts_with(class_name)) return Fail();
115115

116116
repr = repr.substr(class_name.size());
117117
if (repr.empty()) return Fail();

cpp/src/arrow/engine/substrait/relation_internal.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
namespace arrow {
6666

6767
using internal::checked_cast;
68-
using internal::StartsWith;
6968
using internal::ToChars;
7069
using util::UriFromAbsolutePath;
7170

cpp/src/arrow/filesystem/azurefs.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ void AzureOptions::ExtractFromUriSchemeAndHierPart(const Uri& uri,
7070
std::string* out_path) {
7171
const auto host = uri.host();
7272
std::string path;
73-
if (arrow::internal::EndsWith(host, blob_storage_authority)) {
73+
if (host.ends_with(blob_storage_authority)) {
7474
account_name = host.substr(0, host.size() - blob_storage_authority.size());
7575
path = internal::RemoveLeadingSlash(uri.path());
76-
} else if (arrow::internal::EndsWith(host, dfs_storage_authority)) {
76+
} else if (host.ends_with(dfs_storage_authority)) {
7777
account_name = host.substr(0, host.size() - dfs_storage_authority.size());
7878
path = internal::ConcatAbstractPath(uri.username(), uri.path());
7979
} else {

cpp/src/arrow/filesystem/azurefs_test.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2856,8 +2856,7 @@ std::shared_ptr<const KeyValueMetadata> NormalizerKeyValueMetadata(
28562856
value = "2023-10-31T08:15:20Z";
28572857
}
28582858
} else if (key == "ETag") {
2859-
if (arrow::internal::StartsWith(value, "\"") &&
2860-
arrow::internal::EndsWith(value, "\"")) {
2859+
if (value.starts_with("\"") && value.ends_with("\"")) {
28612860
// Valid value
28622861
value = "\"ETagValue\"";
28632862
}

cpp/src/arrow/filesystem/path_util.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929

3030
namespace arrow {
3131

32-
using internal::StartsWith;
33-
3432
namespace fs {
3533
namespace internal {
3634

@@ -236,7 +234,7 @@ bool IsAncestorOf(std::string_view ancestor, std::string_view descendant) {
236234
}
237235

238236
descendant = RemoveTrailingSlash(descendant);
239-
if (!StartsWith(descendant, ancestor)) {
237+
if (!descendant.starts_with(ancestor)) {
240238
// an ancestor path is a prefix of descendant paths
241239
return false;
242240
}
@@ -249,7 +247,7 @@ bool IsAncestorOf(std::string_view ancestor, std::string_view descendant) {
249247
}
250248

251249
// "/hello/w" is not an ancestor of "/hello/world"
252-
return StartsWith(descendant, std::string{kSep});
250+
return descendant.starts_with(std::string{kSep});
253251
}
254252

255253
std::optional<std::string_view> RemoveAncestor(std::string_view ancestor,

0 commit comments

Comments
 (0)