Reapplied code style fixes
This commit is contained in:
parent
a409ba9488
commit
a866a9d980
6 changed files with 129 additions and 40 deletions
35
.idea/codeStyleSettings.xml
Normal file
35
.idea/codeStyleSettings.xml
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectCodeStyleSettingsManager">
|
||||||
|
<option name="PER_PROJECT_SETTINGS">
|
||||||
|
<value>
|
||||||
|
<Objective-C-extensions>
|
||||||
|
<option name="GENERATE_INSTANCE_VARIABLES_FOR_PROPERTIES" value="ASK" />
|
||||||
|
<option name="RELEASE_STYLE" value="IVAR" />
|
||||||
|
<file>
|
||||||
|
<option name="com.jetbrains.objc.util.OCDeclarationKind" value="Import" />
|
||||||
|
<option name="com.jetbrains.objc.util.OCDeclarationKind" value="Macro" />
|
||||||
|
<option name="com.jetbrains.objc.util.OCDeclarationKind" value="Typedef" />
|
||||||
|
<option name="com.jetbrains.objc.util.OCDeclarationKind" value="Struct" />
|
||||||
|
<option name="com.jetbrains.objc.util.OCDeclarationKind" value="Enum" />
|
||||||
|
<option name="com.jetbrains.objc.util.OCDeclarationKind" value="ClassPredef" />
|
||||||
|
<option name="com.jetbrains.objc.util.OCDeclarationKind" value="Constant" />
|
||||||
|
<option name="com.jetbrains.objc.util.OCDeclarationKind" value="Global" />
|
||||||
|
<option name="com.jetbrains.objc.util.OCDeclarationKind" value="FunctionPredecl" />
|
||||||
|
<option name="com.jetbrains.objc.util.OCDeclarationKind" value="Function" />
|
||||||
|
<option name="com.jetbrains.objc.util.OCDeclarationKind" value="Class" />
|
||||||
|
</file>
|
||||||
|
<class>
|
||||||
|
<option name="com.jetbrains.objc.util.OCDeclarationKind" value="Property" />
|
||||||
|
<option name="com.jetbrains.objc.util.OCDeclarationKind" value="Synthesize" />
|
||||||
|
<option name="com.jetbrains.objc.util.OCDeclarationKind" value="InitMethod" />
|
||||||
|
<option name="com.jetbrains.objc.util.OCDeclarationKind" value="StaticMethod" />
|
||||||
|
<option name="com.jetbrains.objc.util.OCDeclarationKind" value="InstanceMethod" />
|
||||||
|
<option name="com.jetbrains.objc.util.OCDeclarationKind" value="DeallocMethod" />
|
||||||
|
</class>
|
||||||
|
</Objective-C-extensions>
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default (1)" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/json.iml
Normal file
8
.idea/json.iml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="CPP_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
5
.idea/misc.xml
Normal file
5
.idea/misc.xml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
|
||||||
|
<component name="ProjectRootManager" version="2" />
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/json.iml" filepath="$PROJECT_DIR$/.idea/json.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
107
src/json.cc
107
src/json.cc
|
@ -2060,10 +2060,10 @@ std::string json::parser::parseString()
|
||||||
|
|
||||||
if (!evenAmountOfBackslashes)
|
if (!evenAmountOfBackslashes)
|
||||||
{
|
{
|
||||||
// uneven amount of backslashes means the user wants to escape something
|
// uneven amount of backslashes means the user wants to escape
|
||||||
// so we know there is a case such as '\X' or '\\\X' but we don't
|
// something so we know there is a case such as '\X' or '\\\X' but
|
||||||
// know yet what X is.
|
// we don't know yet what X is.
|
||||||
// at this point in the code, the currentChar has the value of X
|
// at this point in the code, the currentChar has the value of X.
|
||||||
|
|
||||||
// slash, backslash and quote are copied as is
|
// slash, backslash and quote are copied as is
|
||||||
if ( currentChar == '/'
|
if ( currentChar == '/'
|
||||||
|
@ -2074,33 +2074,55 @@ std::string json::parser::parseString()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// All other characters are replaced by their respective special character
|
// all other characters are replaced by their respective special
|
||||||
if (currentChar == 't')
|
// character
|
||||||
result += '\t';
|
switch (currentChar)
|
||||||
else if (currentChar == 'b')
|
|
||||||
result += '\b';
|
|
||||||
else if (currentChar == 'f')
|
|
||||||
result += '\f';
|
|
||||||
else if (currentChar == 'n')
|
|
||||||
result += '\n';
|
|
||||||
else if (currentChar == 'r')
|
|
||||||
result += '\r';
|
|
||||||
else if (currentChar == 'u')
|
|
||||||
{
|
{
|
||||||
// \uXXXX[\uXXXX] is used for escaping unicode, which
|
case 't':
|
||||||
// has it's own subroutine.
|
{
|
||||||
result += parseUnicodeEscape();
|
result += '\t';
|
||||||
// the parsing process has brought us one step behind the
|
break;
|
||||||
// unicode escape sequence:
|
}
|
||||||
// \uXXXX
|
case 'b':
|
||||||
// ^
|
{
|
||||||
// so we need to go one character back or the parser
|
result += '\b';
|
||||||
// would skip the character we are currently pointing at
|
break;
|
||||||
// (as the for-loop will drecement pos_ after this iteration).
|
}
|
||||||
pos_--;
|
case 'f':
|
||||||
|
{
|
||||||
|
result += '\f';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'n':
|
||||||
|
{
|
||||||
|
result += '\n';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'r':
|
||||||
|
{
|
||||||
|
result += '\r';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'u':
|
||||||
|
{
|
||||||
|
// \uXXXX[\uXXXX] is used for escaping unicode, which
|
||||||
|
// has it's own subroutine.
|
||||||
|
result += parseUnicodeEscape();
|
||||||
|
// the parsing process has brought us one step behind
|
||||||
|
// the unicode escape sequence:
|
||||||
|
// \uXXXX
|
||||||
|
// ^
|
||||||
|
// we need to go one character back or the parser would
|
||||||
|
// skip the character we are currently pointing at as
|
||||||
|
// the for-loop will decrement pos_ after this iteration
|
||||||
|
pos_--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
error("expected one of \\, /, b, f, n, r, t, u behind backslash.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else // user did something like \z and we should report a error
|
|
||||||
error("expected one of \\,/,b,f,n,r,t,u behind backslash.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2119,8 +2141,9 @@ std::string json::parser::parseString()
|
||||||
}
|
}
|
||||||
else if (currentChar != '\\')
|
else if (currentChar != '\\')
|
||||||
{
|
{
|
||||||
// all non-backslash characters are added to the end of the result string.
|
// all non-backslash characters are added to the end of the
|
||||||
// the only backslashes we want in the result are the ones that are escaped (which happens above).
|
// result string. The only backslashes we want in the result
|
||||||
|
// are the ones that are escaped (which happens above).
|
||||||
result += currentChar;
|
result += currentChar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2262,7 +2285,8 @@ unsigned int json::parser::parse4HexCodePoint()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// the cast is safe as 4 hex characters can't present more than 16 bits
|
// the cast is safe as 4 hex characters can't present more than 16 bits
|
||||||
// the input to stoul was checked to contain only hexadecimal characters (see above)
|
// the input to stoul was checked to contain only hexadecimal characters
|
||||||
|
// (see above)
|
||||||
return static_cast<unsigned int>(std::stoul(hexCode, nullptr, 16));
|
return static_cast<unsigned int>(std::stoul(hexCode, nullptr, 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2274,7 +2298,8 @@ The escape sequence has two forms:
|
||||||
where X and Y are a hexadecimal character (a-zA-Z0-9).
|
where X and Y are a hexadecimal character (a-zA-Z0-9).
|
||||||
|
|
||||||
Form 1 just contains the unicode code point in the hexadecimal number XXXX.
|
Form 1 just contains the unicode code point in the hexadecimal number XXXX.
|
||||||
Form 2 is encoding a UTF-16 surrogate pair. The high surrogate is XXXX, the low surrogate is YYYY.
|
Form 2 is encoding a UTF-16 surrogate pair. The high surrogate is XXXX, the low
|
||||||
|
surrogate is YYYY.
|
||||||
|
|
||||||
@return the UTF-8 character this unicode escape sequence escaped.
|
@return the UTF-8 character this unicode escape sequence escaped.
|
||||||
|
|
||||||
|
@ -2292,10 +2317,10 @@ std::string json::parser::parseUnicodeEscape()
|
||||||
|
|
||||||
if (firstCodePoint >= 0xD800 && firstCodePoint <= 0xDBFF)
|
if (firstCodePoint >= 0xD800 && firstCodePoint <= 0xDBFF)
|
||||||
{
|
{
|
||||||
// we found invalid code points, which means we either have a malformed input
|
// we found invalid code points, which means we either have a malformed
|
||||||
// or we found a high surrogate.
|
// input or we found a high surrogate.
|
||||||
// we can only find out by seeing if the next character also wants to encode
|
// we can only find out by seeing if the next character also wants to
|
||||||
// a unicode character (so, we have the \uXXXX\uXXXX case here).
|
// encode a unicode character (so, we have the \uXXXX\uXXXX case here).
|
||||||
|
|
||||||
// jump behind the next \u
|
// jump behind the next \u
|
||||||
pos_ += 2;
|
pos_ += 2;
|
||||||
|
@ -2305,14 +2330,16 @@ std::string json::parser::parseUnicodeEscape()
|
||||||
// ok, we have a low surrogate, check if it is a valid one
|
// ok, we have a low surrogate, check if it is a valid one
|
||||||
if (secondCodePoint >= 0xDC00 && secondCodePoint <= 0xDFFF)
|
if (secondCodePoint >= 0xDC00 && secondCodePoint <= 0xDFFF)
|
||||||
{
|
{
|
||||||
// calculate the final code point from the pair according to the spec
|
// calculate the code point from the pair according to the spec
|
||||||
unsigned int finalCodePoint =
|
unsigned int finalCodePoint =
|
||||||
// high surrogate occupies the most significant 22 bits
|
// high surrogate occupies the most significant 22 bits
|
||||||
(firstCodePoint << 10)
|
(firstCodePoint << 10)
|
||||||
// low surrogate occupies the least significant 15 bits
|
// low surrogate occupies the least significant 15 bits
|
||||||
+ secondCodePoint
|
+ secondCodePoint
|
||||||
// there is still the 0xD800, 0xDC00 and 0x10000 noise in the result
|
// there is still the 0xD800, 0xDC00 and 0x10000 noise in
|
||||||
// so we have to substract with (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00
|
// the result
|
||||||
|
// so we have to substract with:
|
||||||
|
// (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00
|
||||||
- 0x35FDC00;
|
- 0x35FDC00;
|
||||||
|
|
||||||
// we transform the calculated point into UTF-8
|
// we transform the calculated point into UTF-8
|
||||||
|
|
Loading…
Reference in a new issue