From f9580d337d05360a8ea83f91b865d11d944300ba Mon Sep 17 00:00:00 2001 From: Mykola Bilochub Date: Thu, 9 Feb 2017 17:25:44 +0200 Subject: [PATCH] src: add curly braces in `switch` statements PR-URL: https://github.com/metarhia/JSTP/pull/62 --- src/jsrs_parser.cc | 65 +++++++++++++++++++++++++++++++----------- src/jsrs_serializer.cc | 3 +- src/unicode_utils.cc | 12 +++++--- 3 files changed, 58 insertions(+), 22 deletions(-) diff --git a/src/jsrs_parser.cc b/src/jsrs_parser.cc index 08c1821..38d8945 100644 --- a/src/jsrs_parser.cc +++ b/src/jsrs_parser.cc @@ -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; } @@ -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; + } } } @@ -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); diff --git a/src/jsrs_serializer.cc b/src/jsrs_serializer.cc index 702a16e..90ca1a8 100644 --- a/src/jsrs_serializer.cc +++ b/src/jsrs_serializer.cc @@ -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(str)]; } else { return nullptr; } + } } } diff --git a/src/unicode_utils.cc b/src/unicode_utils.cc index 962ebdc..296b3de 100644 --- a/src/unicode_utils.cc +++ b/src/unicode_utils.cc @@ -42,12 +42,13 @@ 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(str[2]) & 0x7F) <= 0xA || str[2] == '\xAF')) || @@ -55,16 +56,19 @@ bool IsWhiteSpaceCharacter(const char* str, size_t* size) { 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;