Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions source/common/common/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,21 +240,6 @@ bool StringUtil::atoull(const char* str, uint64_t& out, int base) {
}
}

bool StringUtil::atoll(const char* str, int64_t& out, int base) {
if (strlen(str) == 0) {
return false;
}

char* end_ptr;
errno = 0;
out = std::strtoll(str, &end_ptr, base);
if (*end_ptr != '\0' || ((out == LLONG_MAX || out == LLONG_MIN) && errno == ERANGE)) {
return false;
} else {
return true;
}
}

absl::string_view StringUtil::ltrim(absl::string_view source) {
const absl::string_view::size_type pos = source.find_first_not_of(WhitespaceChars);
if (pos != absl::string_view::npos) {
Expand Down
6 changes: 0 additions & 6 deletions source/common/common/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,6 @@ class StringUtil {
*/
static bool atoull(const char* str, uint64_t& out, int base = 10);

/**
* Convert a string to a long, checking for error.
* @param return true if successful, false otherwise.
*/
static bool atoll(const char* str, int64_t& out, int base = 10);

/**
* Convert an unsigned integer to a base 10 string as fast as possible.
* @param out supplies the string to fill.
Expand Down
4 changes: 1 addition & 3 deletions source/common/http/header_utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ bool HeaderUtility::matchHeaders(const Http::HeaderMap& request_headers,
break;
case HeaderMatchType::Range: {
int64_t header_value = 0;
// TODO(dnoe): Migrate to pure string_view to eliminate std:string instance (#6580)
const std::string header_string(header_view);
match = StringUtil::atoll(header_string.c_str(), header_value, 10) &&
match = absl::SimpleAtoi(header_view, &header_value) &&
header_value >= header_data.range_.start() && header_value < header_data.range_.end();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ ParameterRouteEntryImpl::ParameterRouteEntryImpl(

ParameterRouteEntryImpl::~ParameterRouteEntryImpl() {}

bool ParameterRouteEntryImpl::matchParameter(const std::string& request_data,
bool ParameterRouteEntryImpl::matchParameter(absl::string_view request_data,
const ParameterData& config_data) const {
switch (config_data.match_type_) {
case Http::HeaderUtility::HeaderMatchType::Value:
return config_data.value_.empty() || request_data == config_data.value_;
case Http::HeaderUtility::HeaderMatchType::Range: {
int64_t value = 0;
return StringUtil::atoll(request_data.c_str(), value, 10) &&
value >= config_data.range_.start() && value < config_data.range_.end();
return absl::SimpleAtoi(request_data, &value) && value >= config_data.range_.start() &&
value < config_data.range_.end();
}
default:
NOT_REACHED_GCOVR_EXCL_LINE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class ParameterRouteEntryImpl : public RouteEntryImplBase {
uint64_t random_value) const override;

private:
bool matchParameter(const std::string& request_data, const ParameterData& config_data) const;
bool matchParameter(absl::string_view request_data, const ParameterData& config_data) const;

std::vector<ParameterData> parameter_data_list_;
};
Expand Down
27 changes: 0 additions & 27 deletions test/common/common/utility_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,33 +98,6 @@ TEST(StringUtil, atoull) {
EXPECT_EQ(18446744073709551615U, out);
}

TEST(StringUtil, atoll) {
int64_t out;
EXPECT_FALSE(StringUtil::atoll("-123b", out));
EXPECT_FALSE(StringUtil::atoll("", out));
EXPECT_FALSE(StringUtil::atoll("b123", out));

EXPECT_TRUE(StringUtil::atoll("123", out));
EXPECT_EQ(123, out);
EXPECT_TRUE(StringUtil::atoll("-123", out));
EXPECT_EQ(-123, out);
EXPECT_TRUE(StringUtil::atoll("+123", out));
EXPECT_EQ(123, out);

EXPECT_TRUE(StringUtil::atoll(" 456", out));
EXPECT_EQ(456, out);

EXPECT_TRUE(StringUtil::atoll("00789", out));
EXPECT_EQ(789, out);

// INT64_MAX + 1
EXPECT_FALSE(StringUtil::atoll("9223372036854775808", out));

// INT64_MIN
EXPECT_TRUE(StringUtil::atoll("-9223372036854775808", out));
EXPECT_EQ(INT64_MIN, out);
}

TEST(DateUtil, All) {
EXPECT_FALSE(DateUtil::timePointValid(SystemTime()));
DangerousDeprecatedTestTime test_time;
Expand Down