mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
src: use enum class instead of enum in node_i18n
"enum class" has more advantages than "enum" because it's strongly typed and scoped. Refs: https://isocpp.org/wiki/faq/cpp11-language-types#enum-class PR-URL: https://github.com/nodejs/node/pull/45646 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
This commit is contained in:
1 parent
1a47a7bbed
commit
ed0a867a4e
2 files changed
+10
-10
No files matched your search
+5
-5
@@ -642,13 +642,13 @@ int32_t ToUnicode(MaybeStackBuffer<char>* buf,
|
||||
int32_t ToASCII(MaybeStackBuffer<char>* buf,
|
||||
const char* input,
|
||||
size_t length,
|
||||
enum idna_mode mode) {
|
||||
idna_mode mode) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
uint32_t options = // CheckHyphens = false; handled later
|
||||
UIDNA_CHECK_BIDI | // CheckBidi = true
|
||||
UIDNA_CHECK_CONTEXTJ | // CheckJoiners = true
|
||||
UIDNA_NONTRANSITIONAL_TO_ASCII; // Nontransitional_Processing
|
||||
if (mode == IDNA_STRICT) {
|
||||
if (mode == idna_mode::kStrict) {
|
||||
options |= UIDNA_USE_STD3_RULES; // UseSTD3ASCIIRules = beStrict
|
||||
// VerifyDnsLength = beStrict;
|
||||
// handled later
|
||||
@@ -696,14 +696,14 @@ int32_t ToASCII(MaybeStackBuffer<char>* buf,
|
||||
info.errors &= ~UIDNA_ERROR_LEADING_HYPHEN;
|
||||
info.errors &= ~UIDNA_ERROR_TRAILING_HYPHEN;
|
||||
|
||||
if (mode != IDNA_STRICT) {
|
||||
if (mode != idna_mode::kStrict) {
|
||||
// VerifyDnsLength = beStrict
|
||||
info.errors &= ~UIDNA_ERROR_EMPTY_LABEL;
|
||||
info.errors &= ~UIDNA_ERROR_LABEL_TOO_LONG;
|
||||
info.errors &= ~UIDNA_ERROR_DOMAIN_NAME_TOO_LONG;
|
||||
}
|
||||
|
||||
if (U_FAILURE(status) || (mode != IDNA_LENIENT && info.errors != 0)) {
|
||||
if (U_FAILURE(status) || (mode != idna_mode::kLenient && info.errors != 0)) {
|
||||
len = -1;
|
||||
buf->SetLength(0);
|
||||
} else {
|
||||
@@ -741,7 +741,7 @@ static void ToASCII(const FunctionCallbackInfo<Value>& args) {
|
||||
Utf8Value val(env->isolate(), args[0]);
|
||||
// optional arg
|
||||
bool lenient = args[1]->BooleanValue(env->isolate());
|
||||
enum idna_mode mode = lenient ? IDNA_LENIENT : IDNA_DEFAULT;
|
||||
idna_mode mode = lenient ? idna_mode::kLenient : idna_mode::kDefault;
|
||||
|
||||
MaybeStackBuffer<char> buf;
|
||||
int32_t len = ToASCII(&buf, *val, val.length(), mode);
|
||||
|
||||
+5
-5
@@ -42,15 +42,15 @@ bool InitializeICUDirectory(const std::string& path);
|
||||
|
||||
void SetDefaultTimeZone(const char* tzid);
|
||||
|
||||
enum idna_mode {
|
||||
enum class idna_mode {
|
||||
// Default mode for maximum compatibility.
|
||||
IDNA_DEFAULT,
|
||||
kDefault,
|
||||
// Ignore all errors in IDNA conversion, if possible.
|
||||
IDNA_LENIENT,
|
||||
kLenient,
|
||||
// Enforce STD3 rules (UseSTD3ASCIIRules) and DNS length restrictions
|
||||
// (VerifyDnsLength). Corresponds to `beStrict` flag in the "domain to ASCII"
|
||||
// algorithm.
|
||||
IDNA_STRICT
|
||||
kStrict
|
||||
};
|
||||
|
||||
// Implements the WHATWG URL Standard "domain to ASCII" algorithm.
|
||||
@@ -58,7 +58,7 @@ enum idna_mode {
|
||||
int32_t ToASCII(MaybeStackBuffer<char>* buf,
|
||||
const char* input,
|
||||
size_t length,
|
||||
enum idna_mode mode = IDNA_DEFAULT);
|
||||
idna_mode mode = idna_mode::kDefault);
|
||||
|
||||
// Implements the WHATWG URL Standard "domain to Unicode" algorithm.
|
||||
// https://url.spec.whatwg.org/#concept-domain-to-unicode
|
||||
|
||||
Reference in new issue
Block a user