Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: add curly braces in switch statements #62

Closed
wants to merge 1 commit into from
Closed
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
65 changes: 48 additions & 17 deletions src/jsrs_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,41 +103,49 @@ static bool GetType(const char* begin, const char* end, Type* type) {
bool result = true;
switch (*begin) {
case ',':
case ']':
case ']': {
*type = Type::kUndefined;
break;
case '{':
}
case '{': {
*type = Type::kObject;
break;
case '[':
}
case '[': {
*type = Type::kArray;
break;
}
case '\"':
case '\'':
case '\'': {
*type = Type::kString;
break;
}
case 't':
case 'f':
case 'f': {
*type = Type::kBool;
break;
case 'n':
}
case 'n': {
*type = Type::kNull;
if (begin + 4 <= end) {
result = (strncmp(begin, "null", 4) == 0);
}
break;
case 'u':
}
case 'u': {
*type = Type::kUndefined;
if (begin + 9 <= end) {
result = (strncmp(begin, "undefined", 9) == 0);
}
break;
default:
}
default: {
result = false;
if (isdigit(*begin) || *begin == '.' || *begin == '+' || *begin == '-') {
*type = Type::kNumber;
result = true;
}
}
}
return result;
}
Expand All @@ -164,12 +172,14 @@ const char* PrepareString(Isolate* isolate,
if (!string_mode) {
if (comment_mode == kDisabled && str[i] == '/') {
switch (str[i + 1]) {
case '/':
case '/': {
comment_mode = kOneline;
break;
case '*':
}
case '*': {
comment_mode = kMultiline;
break;
}
}
}

Expand Down Expand Up @@ -397,13 +407,34 @@ static char* GetControlChar(Isolate* isolate,
*res_len = 1;
bool ok;
switch (str[0]) {
case 'b': *result = '\b'; break;
case 'f': *result = '\f'; break;
case 'n': *result = '\n'; break;
case 'r': *result = '\r'; break;
case 't': *result = '\t'; break;
case 'v': *result = '\v'; break;
case '0': *result = '\0'; break;
case 'b': {
*result = '\b';
break;
}
case 'f': {
*result = '\f';
break;
}
case 'n': {
*result = '\n';
break;
}
case 'r': {
*result = '\r';
break;
}
case 't': {
*result = '\t';
break;
}
case 'v': {
*result = '\v';
break;
}
case '0': {
*result = '\0';
break;
}

case 'x': {
*result = ReadHexNumber(str + 1, 2, &ok);
Expand Down
3 changes: 2 additions & 1 deletion src/jsrs_serializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,14 @@ static const char* GetEscapedControlChar(char str, size_t* size) {
case '\\': return "\\\\";
case '\'': return "\\'";
case 0x7F: return "\\u007f";
default:
default: {
if (str < 0x20) {
*size = 6;
return control_chars[static_cast<size_t>(str)];
} else {
return nullptr;
}
}
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/unicode_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,33 @@ bool IsWhiteSpaceCharacter(const char* str, size_t* size) {
} else {
bool is_multibyte_space = false;
switch (str[0]) {
case '\xE1':
case '\xE1': {
if (str[1] == '\xBB' && str[2] == '\xBF') {
is_multibyte_space = true;
}
break;
case '\xE2':
}
case '\xE2': {
if ((str[1] == '\x80' &&
((static_cast<unsigned char>(str[2]) & 0x7F) <= 0xA ||
str[2] == '\xAF')) ||
(str[1] == '\x81' && str[2] == '\x9F')) {
is_multibyte_space = true;
}
break;
case '\xE3':
}
case '\xE3': {
if (str[1] == '\x80' && str[2] == '\x80') {
is_multibyte_space = true;
}
break;
case '\xEF':
}
case '\xEF': {
if (str[1] == '\xBB' && str[2] == '\xBF') {
is_multibyte_space = true;
}
break;
}
}
if (is_multibyte_space) {
*size = 3;
Expand Down