diff --git a/utils/json/build.gradle b/utils/json/build.gradle index 891d697..e69de29 100644 --- a/utils/json/build.gradle +++ b/utils/json/build.gradle @@ -1,3 +0,0 @@ -dependencies { - compile project(":") -} diff --git a/utils/json/src/main/kotlin/cn/tursom/utils/json/Json.kt b/utils/json/src/main/kotlin/cn/tursom/utils/json/Json.kt index c6e7461..bde038c 100644 --- a/utils/json/src/main/kotlin/cn/tursom/utils/json/Json.kt +++ b/utils/json/src/main/kotlin/cn/tursom/utils/json/Json.kt @@ -12,11 +12,11 @@ object Json { val content = JsonParseContent(json) val parse = parse(content) jumpWhitespace(content) - if (content.index != json.length) throw JsonFormatException(json) + if (content.index != json.length) throw JsonFormatException("$json[${json[content.index]}] remain characters") return parse } - internal data class JsonParseContent(inline val json: String, inline var index: Int = 0) + internal data class JsonParseContent(val json: String, var index: Int = 0) private fun parse(content: JsonParseContent): Any? { jumpWhitespace(content) @@ -31,14 +31,13 @@ object Json { } } - @Suppress("NOTHING_TO_INLINE") - private inline fun parseNull(content: JsonParseContent) = if (content.json.startsWith("null", content.index)) { + private fun parseNull(content: JsonParseContent) = if (content.json.startsWith("null", content.index)) { content.index += 4 null } else throw JsonFormatException(content) - @Suppress("ControlFlowWithEmptyBody", "NOTHING_TO_INLINE") - private inline fun parseBoolean(content: JsonParseContent) = when { + @Suppress("ControlFlowWithEmptyBody") + private fun parseBoolean(content: JsonParseContent) = when { content.json.startsWith("true", content.index) -> { content.index += 4 true @@ -50,24 +49,20 @@ object Json { else -> throw JsonFormatException(content) } - @Suppress("NOTHING_TO_INLINE") - private inline fun jumpWhitespaceLoopCondition(json: String, index: Int) = index < json.length && json[index] in " \t\r\n" + private fun jumpWhitespaceLoopCondition(json: String, index: Int) = index < json.length && json[index] in " \t\r\n" - @Suppress("NOTHING_TO_INLINE") - private inline fun jumpWhitespace(content: JsonParseContent) { + private fun jumpWhitespace(content: JsonParseContent) { @Suppress("ControlFlowWithEmptyBody") if (jumpWhitespaceLoopCondition(content.json, content.index)) while (jumpWhitespaceLoopCondition(content.json, ++content.index)); } - @Suppress("NOTHING_TO_INLINE") - private inline fun charToInt(char: Char): Int { + private fun charToInt(char: Char): Int { val indexOf = char - '0' if (indexOf < 0 || indexOf > 9) throw JsonFormatException("$char is not an number") return indexOf } - @Suppress("NOTHING_TO_INLINE") - private inline fun parseInt(content: JsonParseContent): Number { + private fun parseInt(content: JsonParseContent): Number { var number = charToInt(content.json[content.index]).toLong() while (++content.index < content.json.length && content.json[content.index] in '0'..'9') { number = number * 10 + charToInt(content.json[content.index]) @@ -75,8 +70,7 @@ object Json { return if (number <= Int.MAX_VALUE) number.toInt() else number } - @Suppress("NOTHING_TO_INLINE") - private inline fun parseNumber(content: JsonParseContent): Number { + private fun parseNumber(content: JsonParseContent): Number { val negative = content.json[content.index] == '-' if (negative || content.json[content.index] == '+') content.index++ var number: Number = when (content.json[content.index]) { @@ -112,8 +106,7 @@ object Json { } else number } - @Suppress("NOTHING_TO_INLINE") - private inline fun parseString(content: JsonParseContent): String { + private fun parseString(content: JsonParseContent): String { if (content.json[content.index++] != '"') throw JsonFormatException("string not begin with '\"'") val builder = StringBuilder() while (content.index < content.json.length) when (content.json[content.index]) { @@ -146,8 +139,7 @@ object Json { throw JsonFormatException(content) } - @Suppress("NOTHING_TO_INLINE") - private inline fun parseObj(content: JsonParseContent): Map { + private fun parseObj(content: JsonParseContent): Map { if (content.json[content.index++] != '{') throw JsonFormatException(content) jumpWhitespace(content) if (content.json[content.index] == '}') { @@ -171,8 +163,7 @@ object Json { return map } - @Suppress("NOTHING_TO_INLINE") - private inline fun parseArray(content: JsonParseContent): List { + private fun parseArray(content: JsonParseContent): List { if (content.json[content.index++] != '[') throw JsonFormatException(content) jumpWhitespace(content) if (content.json[content.index] == ']') {