[cleanup] Use base::IsInRange in more places

Change-Id: Icb5047346fbc0a28755a55b5abe507cfd8913a21
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2599741
Reviewed-by: Georg Neis <neis@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71936}
This commit is contained in:
Camillo Bruni 2020-12-21 12:42:53 +01:00 committed by Commit Bot
parent a08d909b75
commit 98b27ba9a7
2 changed files with 11 additions and 16 deletions

View File

@ -8,6 +8,7 @@
#include <cmath>
#include <limits>
#include "src/base/bounds.h"
#include "src/base/compiler-specific.h"
#include "src/codegen/external-reference.h"
#include "src/common/globals.h"
@ -144,8 +145,8 @@ struct IntMatcher final : public ValueMatcher<T, kOpcode> {
return this->HasResolvedValue() && this->ResolvedValue() == value;
}
bool IsInRange(const T& low, const T& high) const {
return this->HasResolvedValue() && low <= this->ResolvedValue() &&
this->ResolvedValue() <= high;
return this->HasResolvedValue() &&
base::IsInRange(this->ResolvedValue(), low, high);
}
bool IsMultipleOf(T n) const {
return this->HasResolvedValue() && (this->ResolvedValue() % n) == 0;

View File

@ -110,17 +110,9 @@ Handle<Object> UnicodeKeywordValue(Isolate* isolate, Handle<JSLocale> locale,
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(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++) {
if (!range_check_func(str[i])) return false;
}
@ -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) {
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) {
return IsCheckRange(str, min, max,
[](char c) -> bool { return InRange(c, '0', '9'); });
return IsCheckRange(str, min, max, [](char c) -> bool {
return base::IsInRange(c, '0', '9');
});
}
bool IsAlphanum(const std::string& str, size_t min, size_t max) {
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) {
}
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);
}