From 7f9e65ef17253483e1cf0e5a68eac34335c4c68d Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Tue, 25 Apr 2017 12:04:43 +0700 Subject: [PATCH] stdlib: Remove unused C++ methods for string parsing Now toByte, toShort, toInt and toLong methods use their "...OrNull" analogs implemented in Kotlin insetad of "parse..." functions implemented in C++. This patch removes unused C++ methods. --- runtime/src/main/cpp/KString.cpp | 38 ------------------- .../kotlin/text/StringNumberConversions.kt | 14 ------- 2 files changed, 52 deletions(-) diff --git a/runtime/src/main/cpp/KString.cpp b/runtime/src/main/cpp/KString.cpp index 07d0845da19..4322937693a 100644 --- a/runtime/src/main/cpp/KString.cpp +++ b/runtime/src/main/cpp/KString.cpp @@ -47,28 +47,6 @@ OBJ_GETTER(utf8ToUtf16, const char* rawString, size_t rawStringLength) { RETURN_OBJ(result->obj()); } -// TODO: Suppose thar we can remove these parsers -KLong parseLong(KString value, KInt radix) { - const KChar* utf16 = CharArrayAddressOfElementAt(value, 0); - std::string utf8; - utf8::utf16to8(utf16, utf16 + value->count_, back_inserter(utf8)); - char* end = nullptr; - errno = 0; - KLong result = strtoll(utf8.c_str(), &end, radix); - if (utf8.size() == 0 || end != utf8.c_str() + utf8.size() || errno == ERANGE) { - ThrowNumberFormatException(); - } - return result; -} - -template T parseInt(KString value, KInt radix) { - KLong result = parseLong(value, radix); - if (result < std::numeric_limits::min() || result > std::numeric_limits::max()) { - ThrowNumberFormatException(); - } - return result; -} - void checkParsingErrors(const char* c_str, char* end, std::string::size_type c_str_size) { if (end == c_str) { ThrowNumberFormatException(); @@ -1177,22 +1155,6 @@ OBJ_GETTER0(Kotlin_io_Console_readLine) { RETURN_RESULT_OF(CreateStringFromCString, data); } -KByte Kotlin_String_parseByte(KString value, KInt radix) { - return parseInt(value, radix); -} - -KShort Kotlin_String_parseShort(KString value, KInt radix) { - return parseInt(value, radix); -} - -KInt Kotlin_String_parseInt(KString value, KInt radix) { - return parseInt(value, radix); -} - -KLong Kotlin_String_parseLong(KString value, KInt radix) { - return parseLong(value, radix); -} - KFloat Kotlin_String_parseFloat(KString value) { return parseFloat(value); } diff --git a/runtime/src/main/kotlin/kotlin/text/StringNumberConversions.kt b/runtime/src/main/kotlin/kotlin/text/StringNumberConversions.kt index 96b638fa43b..43e821ab430 100644 --- a/runtime/src/main/kotlin/kotlin/text/StringNumberConversions.kt +++ b/runtime/src/main/kotlin/kotlin/text/StringNumberConversions.kt @@ -58,10 +58,6 @@ public inline fun Long.toString(radix: Int): String = longToString(this, checkRa @kotlin.internal.InlineOnly public inline fun String.toBoolean(): Boolean = this.equals("true", ignoreCase = true) -// TODO: Remove it? -@SymbolName("Kotlin_String_parseByte") -external private fun parseByte(value: String, radix: Int): Byte - /** * Parses the string as a signed [Byte] number and returns the result. * @throws NumberFormatException if the string is not a valid representation of a number. @@ -77,9 +73,6 @@ public inline fun String.toByte(): Byte = toByteOrNull() ?: throw NumberFormatEx @kotlin.internal.InlineOnly public inline fun String.toByte(radix: Int): Byte = toByteOrNull(radix) ?: throw NumberFormatException() -@SymbolName("Kotlin_String_parseShort") -external private fun parseShort(value: String, radix: Int): Short - /** * Parses the string as a [Short] number and returns the result. * @throws NumberFormatException if the string is not a valid representation of a number. @@ -95,9 +88,6 @@ public inline fun String.toShort(): Short = toShortOrNull() ?: throw NumberForma @kotlin.internal.InlineOnly public inline fun String.toShort(radix: Int): Short = toShortOrNull(radix) ?: throw NumberFormatException() -@SymbolName("Kotlin_String_parseInt") -external private fun parseInt(value: String, radix: Int): Int - /** * Parses the string as an [Int] number and returns the result. * @throws NumberFormatException if the string is not a valid representation of a number. @@ -113,10 +103,6 @@ public inline fun String.toInt(): Int = toIntOrNull() ?: throw NumberFormatExcep @kotlin.internal.InlineOnly public inline fun String.toInt(radix: Int): Int = toIntOrNull(radix) ?: throw NumberFormatException() - -@SymbolName("Kotlin_String_parseLong") -external private fun parseLong(value: String, radix: Int): Long - /** * Parses the string as a [Long] number and returns the result. * @throws NumberFormatException if the string is not a valid representation of a number.