Commit 98b27ba9 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[cleanup] Use base::IsInRange in more places

Change-Id: Icb5047346fbc0a28755a55b5abe507cfd8913a21
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2599741Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71936}
parent a08d909b
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <cmath> #include <cmath>
#include <limits> #include <limits>
#include "src/base/bounds.h"
#include "src/base/compiler-specific.h" #include "src/base/compiler-specific.h"
#include "src/codegen/external-reference.h" #include "src/codegen/external-reference.h"
#include "src/common/globals.h" #include "src/common/globals.h"
...@@ -144,8 +145,8 @@ struct IntMatcher final : public ValueMatcher<T, kOpcode> { ...@@ -144,8 +145,8 @@ struct IntMatcher final : public ValueMatcher<T, kOpcode> {
return this->HasResolvedValue() && this->ResolvedValue() == value; return this->HasResolvedValue() && this->ResolvedValue() == value;
} }
bool IsInRange(const T& low, const T& high) const { bool IsInRange(const T& low, const T& high) const {
return this->HasResolvedValue() && low <= this->ResolvedValue() && return this->HasResolvedValue() &&
this->ResolvedValue() <= high; base::IsInRange(this->ResolvedValue(), low, high);
} }
bool IsMultipleOf(T n) const { bool IsMultipleOf(T n) const {
return this->HasResolvedValue() && (this->ResolvedValue() % n) == 0; return this->HasResolvedValue() && (this->ResolvedValue() % n) == 0;
......
...@@ -110,17 +110,9 @@ Handle<Object> UnicodeKeywordValue(Isolate* isolate, Handle<JSLocale> locale, ...@@ -110,17 +110,9 @@ Handle<Object> UnicodeKeywordValue(Isolate* isolate, Handle<JSLocale> locale,
return isolate->factory()->NewStringFromAsciiChecked(value.c_str()); return isolate->factory()->NewStringFromAsciiChecked(value.c_str());
} }
bool InRange(size_t value, size_t start, size_t end) {
return (start <= value) && (value <= end);
}
bool InRange(char value, char start, char end) {
return (start <= value) && (value <= end);
}
bool IsCheckRange(const std::string& str, size_t min, size_t max, bool IsCheckRange(const std::string& str, size_t min, size_t max,
bool(range_check_func)(char)) { bool(range_check_func)(char)) {
if (!InRange(str.length(), min, max)) return false; if (!base::IsInRange(str.length(), min, max)) return false;
for (size_t i = 0; i < str.length(); i++) { for (size_t i = 0; i < str.length(); i++) {
if (!range_check_func(str[i])) return false; if (!range_check_func(str[i])) return false;
} }
...@@ -128,18 +120,20 @@ bool IsCheckRange(const std::string& str, size_t min, size_t max, ...@@ -128,18 +120,20 @@ bool IsCheckRange(const std::string& str, size_t min, size_t max,
} }
bool IsAlpha(const std::string& str, size_t min, size_t max) { bool IsAlpha(const std::string& str, size_t min, size_t max) {
return IsCheckRange(str, min, max, [](char c) -> bool { return IsCheckRange(str, min, max, [](char c) -> bool {
return InRange(c, 'a', 'z') || InRange(c, 'A', 'Z'); return base::IsInRange(c, 'a', 'z') || base::IsInRange(c, 'A', 'Z');
}); });
} }
bool IsDigit(const std::string& str, size_t min, size_t max) { bool IsDigit(const std::string& str, size_t min, size_t max) {
return IsCheckRange(str, min, max, return IsCheckRange(str, min, max, [](char c) -> bool {
[](char c) -> bool { return InRange(c, '0', '9'); }); return base::IsInRange(c, '0', '9');
});
} }
bool IsAlphanum(const std::string& str, size_t min, size_t max) { bool IsAlphanum(const std::string& str, size_t min, size_t max) {
return IsCheckRange(str, min, max, [](char c) -> bool { return IsCheckRange(str, min, max, [](char c) -> bool {
return InRange(c, 'a', 'z') || InRange(c, 'A', 'Z') || InRange(c, '0', '9'); return base::IsInRange(c, 'a', 'z') || base::IsInRange(c, 'A', 'Z') ||
base::IsInRange(c, '0', '9');
}); });
} }
...@@ -159,7 +153,7 @@ bool IsUnicodeRegionSubtag(const std::string& value) { ...@@ -159,7 +153,7 @@ bool IsUnicodeRegionSubtag(const std::string& value) {
} }
bool IsDigitAlphanum3(const std::string& value) { bool IsDigitAlphanum3(const std::string& value) {
return value.length() == 4 && InRange(value[0], '0', '9') && return value.length() == 4 && base::IsInRange(value[0], '0', '9') &&
IsAlphanum(value.substr(1), 3, 3); IsAlphanum(value.substr(1), 3, 3);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment