Skip to content

Commit 936a5c0

Browse files
deokjinkimdanielleadams
authored andcommitted
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: #45646 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
1 parent 6b5f767 commit 936a5c0

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/node_i18n.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -616,13 +616,13 @@ int32_t ToUnicode(MaybeStackBuffer<char>* buf,
616616
int32_t ToASCII(MaybeStackBuffer<char>* buf,
617617
const char* input,
618618
size_t length,
619-
enum idna_mode mode) {
619+
idna_mode mode) {
620620
UErrorCode status = U_ZERO_ERROR;
621621
uint32_t options = // CheckHyphens = false; handled later
622622
UIDNA_CHECK_BIDI | // CheckBidi = true
623623
UIDNA_CHECK_CONTEXTJ | // CheckJoiners = true
624624
UIDNA_NONTRANSITIONAL_TO_ASCII; // Nontransitional_Processing
625-
if (mode == IDNA_STRICT) {
625+
if (mode == idna_mode::kStrict) {
626626
options |= UIDNA_USE_STD3_RULES; // UseSTD3ASCIIRules = beStrict
627627
// VerifyDnsLength = beStrict;
628628
// handled later
@@ -670,14 +670,14 @@ int32_t ToASCII(MaybeStackBuffer<char>* buf,
670670
info.errors &= ~UIDNA_ERROR_LEADING_HYPHEN;
671671
info.errors &= ~UIDNA_ERROR_TRAILING_HYPHEN;
672672

673-
if (mode != IDNA_STRICT) {
673+
if (mode != idna_mode::kStrict) {
674674
// VerifyDnsLength = beStrict
675675
info.errors &= ~UIDNA_ERROR_EMPTY_LABEL;
676676
info.errors &= ~UIDNA_ERROR_LABEL_TOO_LONG;
677677
info.errors &= ~UIDNA_ERROR_DOMAIN_NAME_TOO_LONG;
678678
}
679679

680-
if (U_FAILURE(status) || (mode != IDNA_LENIENT && info.errors != 0)) {
680+
if (U_FAILURE(status) || (mode != idna_mode::kLenient && info.errors != 0)) {
681681
len = -1;
682682
buf->SetLength(0);
683683
} else {
@@ -715,7 +715,7 @@ static void ToASCII(const FunctionCallbackInfo<Value>& args) {
715715
Utf8Value val(env->isolate(), args[0]);
716716
// optional arg
717717
bool lenient = args[1]->BooleanValue(env->isolate());
718-
enum idna_mode mode = lenient ? IDNA_LENIENT : IDNA_DEFAULT;
718+
idna_mode mode = lenient ? idna_mode::kLenient : idna_mode::kDefault;
719719

720720
MaybeStackBuffer<char> buf;
721721
int32_t len = ToASCII(&buf, *val, val.length(), mode);

src/node_i18n.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,23 @@ bool InitializeICUDirectory(const std::string& path);
4242

4343
void SetDefaultTimeZone(const char* tzid);
4444

45-
enum idna_mode {
45+
enum class idna_mode {
4646
// Default mode for maximum compatibility.
47-
IDNA_DEFAULT,
47+
kDefault,
4848
// Ignore all errors in IDNA conversion, if possible.
49-
IDNA_LENIENT,
49+
kLenient,
5050
// Enforce STD3 rules (UseSTD3ASCIIRules) and DNS length restrictions
5151
// (VerifyDnsLength). Corresponds to `beStrict` flag in the "domain to ASCII"
5252
// algorithm.
53-
IDNA_STRICT
53+
kStrict
5454
};
5555

5656
// Implements the WHATWG URL Standard "domain to ASCII" algorithm.
5757
// https://url.spec.whatwg.org/#concept-domain-to-ascii
5858
int32_t ToASCII(MaybeStackBuffer<char>* buf,
5959
const char* input,
6060
size_t length,
61-
enum idna_mode mode = IDNA_DEFAULT);
61+
idna_mode mode = idna_mode::kDefault);
6262

6363
// Implements the WHATWG URL Standard "domain to Unicode" algorithm.
6464
// https://url.spec.whatwg.org/#concept-domain-to-unicode

0 commit comments

Comments
 (0)