diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 3a744bbc7ad..1a81434b3a8 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -5046,7 +5046,7 @@ private void configureStdlibTest(KonanGTest task, boolean inWorker) { '../../../libraries/kotlin.test/common/src/test/kotlin', 'stdlib_external/utils.kt', 'stdlib_external/jsCollectionFactoriesActuals.kt', - 'stdlib_external/text/StringEncodingTestNative.kt'], + 'stdlib_external/text'], [ /*'build/stdlib_external/stdlib/test/internalAnnotations.kt'*/ ]) konanArtifacts { diff --git a/kotlin-native/backend.native/tests/stdlib_external/text/_IsCaseIgnorableTest.kt b/kotlin-native/backend.native/tests/stdlib_external/text/_IsCaseIgnorableTest.kt new file mode 100644 index 00000000000..588810179f0 --- /dev/null +++ b/kotlin-native/backend.native/tests/stdlib_external/text/_IsCaseIgnorableTest.kt @@ -0,0 +1,496 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package test.text + +// +// NOTE: THIS FILE IS AUTO-GENERATED by the GenerateUnicodeData.kt +// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib +// + +import kotlin.test.* + +@SharedImmutable +private val caseIgnorableRanges = arrayOf( + 0x0027..0x0027, + 0x002e..0x002e, + 0x003a..0x003a, + 0x005e..0x005e, + 0x0060..0x0060, + 0x00a8..0x00a8, + 0x00ad..0x00ad, + 0x00af..0x00af, + 0x00b4..0x00b4, + 0x00b7..0x00b7, + 0x00b8..0x00b8, + 0x02b0..0x02c1, + 0x02c2..0x02c5, + 0x02c6..0x02d1, + 0x02d2..0x02df, + 0x02e0..0x02e4, + 0x02e5..0x02eb, + 0x02ec..0x02ec, + 0x02ed..0x02ed, + 0x02ee..0x02ee, + 0x02ef..0x02ff, + 0x0300..0x036f, + 0x0374..0x0374, + 0x0375..0x0375, + 0x037a..0x037a, + 0x0384..0x0385, + 0x0387..0x0387, + 0x0483..0x0487, + 0x0488..0x0489, + 0x0559..0x0559, + 0x055f..0x055f, + 0x0591..0x05bd, + 0x05bf..0x05bf, + 0x05c1..0x05c2, + 0x05c4..0x05c5, + 0x05c7..0x05c7, + 0x05f4..0x05f4, + 0x0600..0x0605, + 0x0610..0x061a, + 0x061c..0x061c, + 0x0640..0x0640, + 0x064b..0x065f, + 0x0670..0x0670, + 0x06d6..0x06dc, + 0x06dd..0x06dd, + 0x06df..0x06e4, + 0x06e5..0x06e6, + 0x06e7..0x06e8, + 0x06ea..0x06ed, + 0x070f..0x070f, + 0x0711..0x0711, + 0x0730..0x074a, + 0x07a6..0x07b0, + 0x07eb..0x07f3, + 0x07f4..0x07f5, + 0x07fa..0x07fa, + 0x07fd..0x07fd, + 0x0816..0x0819, + 0x081a..0x081a, + 0x081b..0x0823, + 0x0824..0x0824, + 0x0825..0x0827, + 0x0828..0x0828, + 0x0829..0x082d, + 0x0859..0x085b, + 0x08d3..0x08e1, + 0x08e2..0x08e2, + 0x08e3..0x0902, + 0x093a..0x093a, + 0x093c..0x093c, + 0x0941..0x0948, + 0x094d..0x094d, + 0x0951..0x0957, + 0x0962..0x0963, + 0x0971..0x0971, + 0x0981..0x0981, + 0x09bc..0x09bc, + 0x09c1..0x09c4, + 0x09cd..0x09cd, + 0x09e2..0x09e3, + 0x09fe..0x09fe, + 0x0a01..0x0a02, + 0x0a3c..0x0a3c, + 0x0a41..0x0a42, + 0x0a47..0x0a48, + 0x0a4b..0x0a4d, + 0x0a51..0x0a51, + 0x0a70..0x0a71, + 0x0a75..0x0a75, + 0x0a81..0x0a82, + 0x0abc..0x0abc, + 0x0ac1..0x0ac5, + 0x0ac7..0x0ac8, + 0x0acd..0x0acd, + 0x0ae2..0x0ae3, + 0x0afa..0x0aff, + 0x0b01..0x0b01, + 0x0b3c..0x0b3c, + 0x0b3f..0x0b3f, + 0x0b41..0x0b44, + 0x0b4d..0x0b4d, + 0x0b55..0x0b56, + 0x0b62..0x0b63, + 0x0b82..0x0b82, + 0x0bc0..0x0bc0, + 0x0bcd..0x0bcd, + 0x0c00..0x0c00, + 0x0c04..0x0c04, + 0x0c3e..0x0c40, + 0x0c46..0x0c48, + 0x0c4a..0x0c4d, + 0x0c55..0x0c56, + 0x0c62..0x0c63, + 0x0c81..0x0c81, + 0x0cbc..0x0cbc, + 0x0cbf..0x0cbf, + 0x0cc6..0x0cc6, + 0x0ccc..0x0ccd, + 0x0ce2..0x0ce3, + 0x0d00..0x0d01, + 0x0d3b..0x0d3c, + 0x0d41..0x0d44, + 0x0d4d..0x0d4d, + 0x0d62..0x0d63, + 0x0d81..0x0d81, + 0x0dca..0x0dca, + 0x0dd2..0x0dd4, + 0x0dd6..0x0dd6, + 0x0e31..0x0e31, + 0x0e34..0x0e3a, + 0x0e46..0x0e46, + 0x0e47..0x0e4e, + 0x0eb1..0x0eb1, + 0x0eb4..0x0ebc, + 0x0ec6..0x0ec6, + 0x0ec8..0x0ecd, + 0x0f18..0x0f19, + 0x0f35..0x0f35, + 0x0f37..0x0f37, + 0x0f39..0x0f39, + 0x0f71..0x0f7e, + 0x0f80..0x0f84, + 0x0f86..0x0f87, + 0x0f8d..0x0f97, + 0x0f99..0x0fbc, + 0x0fc6..0x0fc6, + 0x102d..0x1030, + 0x1032..0x1037, + 0x1039..0x103a, + 0x103d..0x103e, + 0x1058..0x1059, + 0x105e..0x1060, + 0x1071..0x1074, + 0x1082..0x1082, + 0x1085..0x1086, + 0x108d..0x108d, + 0x109d..0x109d, + 0x10fc..0x10fc, + 0x135d..0x135f, + 0x1712..0x1714, + 0x1732..0x1734, + 0x1752..0x1753, + 0x1772..0x1773, + 0x17b4..0x17b5, + 0x17b7..0x17bd, + 0x17c6..0x17c6, + 0x17c9..0x17d3, + 0x17d7..0x17d7, + 0x17dd..0x17dd, + 0x180b..0x180d, + 0x180e..0x180e, + 0x1843..0x1843, + 0x1885..0x1886, + 0x18a9..0x18a9, + 0x1920..0x1922, + 0x1927..0x1928, + 0x1932..0x1932, + 0x1939..0x193b, + 0x1a17..0x1a18, + 0x1a1b..0x1a1b, + 0x1a56..0x1a56, + 0x1a58..0x1a5e, + 0x1a60..0x1a60, + 0x1a62..0x1a62, + 0x1a65..0x1a6c, + 0x1a73..0x1a7c, + 0x1a7f..0x1a7f, + 0x1aa7..0x1aa7, + 0x1ab0..0x1abd, + 0x1abe..0x1abe, + 0x1abf..0x1ac0, + 0x1b00..0x1b03, + 0x1b34..0x1b34, + 0x1b36..0x1b3a, + 0x1b3c..0x1b3c, + 0x1b42..0x1b42, + 0x1b6b..0x1b73, + 0x1b80..0x1b81, + 0x1ba2..0x1ba5, + 0x1ba8..0x1ba9, + 0x1bab..0x1bad, + 0x1be6..0x1be6, + 0x1be8..0x1be9, + 0x1bed..0x1bed, + 0x1bef..0x1bf1, + 0x1c2c..0x1c33, + 0x1c36..0x1c37, + 0x1c78..0x1c7d, + 0x1cd0..0x1cd2, + 0x1cd4..0x1ce0, + 0x1ce2..0x1ce8, + 0x1ced..0x1ced, + 0x1cf4..0x1cf4, + 0x1cf8..0x1cf9, + 0x1d2c..0x1d6a, + 0x1d78..0x1d78, + 0x1d9b..0x1dbf, + 0x1dc0..0x1df9, + 0x1dfb..0x1dff, + 0x1fbd..0x1fbd, + 0x1fbf..0x1fc1, + 0x1fcd..0x1fcf, + 0x1fdd..0x1fdf, + 0x1fed..0x1fef, + 0x1ffd..0x1ffe, + 0x200b..0x200f, + 0x2018..0x2018, + 0x2019..0x2019, + 0x2024..0x2024, + 0x2027..0x2027, + 0x202a..0x202e, + 0x2060..0x2064, + 0x2066..0x206f, + 0x2071..0x2071, + 0x207f..0x207f, + 0x2090..0x209c, + 0x20d0..0x20dc, + 0x20dd..0x20e0, + 0x20e1..0x20e1, + 0x20e2..0x20e4, + 0x20e5..0x20f0, + 0x2c7c..0x2c7d, + 0x2cef..0x2cf1, + 0x2d6f..0x2d6f, + 0x2d7f..0x2d7f, + 0x2de0..0x2dff, + 0x2e2f..0x2e2f, + 0x3005..0x3005, + 0x302a..0x302d, + 0x3031..0x3035, + 0x303b..0x303b, + 0x3099..0x309a, + 0x309b..0x309c, + 0x309d..0x309e, + 0x30fc..0x30fe, + 0xa015..0xa015, + 0xa4f8..0xa4fd, + 0xa60c..0xa60c, + 0xa66f..0xa66f, + 0xa670..0xa672, + 0xa674..0xa67d, + 0xa67f..0xa67f, + 0xa69c..0xa69d, + 0xa69e..0xa69f, + 0xa6f0..0xa6f1, + 0xa700..0xa716, + 0xa717..0xa71f, + 0xa720..0xa721, + 0xa770..0xa770, + 0xa788..0xa788, + 0xa789..0xa78a, + 0xa7f8..0xa7f9, + 0xa802..0xa802, + 0xa806..0xa806, + 0xa80b..0xa80b, + 0xa825..0xa826, + 0xa82c..0xa82c, + 0xa8c4..0xa8c5, + 0xa8e0..0xa8f1, + 0xa8ff..0xa8ff, + 0xa926..0xa92d, + 0xa947..0xa951, + 0xa980..0xa982, + 0xa9b3..0xa9b3, + 0xa9b6..0xa9b9, + 0xa9bc..0xa9bd, + 0xa9cf..0xa9cf, + 0xa9e5..0xa9e5, + 0xa9e6..0xa9e6, + 0xaa29..0xaa2e, + 0xaa31..0xaa32, + 0xaa35..0xaa36, + 0xaa43..0xaa43, + 0xaa4c..0xaa4c, + 0xaa70..0xaa70, + 0xaa7c..0xaa7c, + 0xaab0..0xaab0, + 0xaab2..0xaab4, + 0xaab7..0xaab8, + 0xaabe..0xaabf, + 0xaac1..0xaac1, + 0xaadd..0xaadd, + 0xaaec..0xaaed, + 0xaaf3..0xaaf4, + 0xaaf6..0xaaf6, + 0xab5b..0xab5b, + 0xab5c..0xab5f, + 0xab69..0xab69, + 0xab6a..0xab6b, + 0xabe5..0xabe5, + 0xabe8..0xabe8, + 0xabed..0xabed, + 0xfb1e..0xfb1e, + 0xfbb2..0xfbc1, + 0xfe00..0xfe0f, + 0xfe13..0xfe13, + 0xfe20..0xfe2f, + 0xfe52..0xfe52, + 0xfe55..0xfe55, + 0xfeff..0xfeff, + 0xff07..0xff07, + 0xff0e..0xff0e, + 0xff1a..0xff1a, + 0xff3e..0xff3e, + 0xff40..0xff40, + 0xff70..0xff70, + 0xff9e..0xff9f, + 0xffe3..0xffe3, + 0xfff9..0xfffb, + 0x101fd..0x101fd, + 0x102e0..0x102e0, + 0x10376..0x1037a, + 0x10a01..0x10a03, + 0x10a05..0x10a06, + 0x10a0c..0x10a0f, + 0x10a38..0x10a3a, + 0x10a3f..0x10a3f, + 0x10ae5..0x10ae6, + 0x10d24..0x10d27, + 0x10eab..0x10eac, + 0x10f46..0x10f50, + 0x11001..0x11001, + 0x11038..0x11046, + 0x1107f..0x11081, + 0x110b3..0x110b6, + 0x110b9..0x110ba, + 0x110bd..0x110bd, + 0x110cd..0x110cd, + 0x11100..0x11102, + 0x11127..0x1112b, + 0x1112d..0x11134, + 0x11173..0x11173, + 0x11180..0x11181, + 0x111b6..0x111be, + 0x111c9..0x111cc, + 0x111cf..0x111cf, + 0x1122f..0x11231, + 0x11234..0x11234, + 0x11236..0x11237, + 0x1123e..0x1123e, + 0x112df..0x112df, + 0x112e3..0x112ea, + 0x11300..0x11301, + 0x1133b..0x1133c, + 0x11340..0x11340, + 0x11366..0x1136c, + 0x11370..0x11374, + 0x11438..0x1143f, + 0x11442..0x11444, + 0x11446..0x11446, + 0x1145e..0x1145e, + 0x114b3..0x114b8, + 0x114ba..0x114ba, + 0x114bf..0x114c0, + 0x114c2..0x114c3, + 0x115b2..0x115b5, + 0x115bc..0x115bd, + 0x115bf..0x115c0, + 0x115dc..0x115dd, + 0x11633..0x1163a, + 0x1163d..0x1163d, + 0x1163f..0x11640, + 0x116ab..0x116ab, + 0x116ad..0x116ad, + 0x116b0..0x116b5, + 0x116b7..0x116b7, + 0x1171d..0x1171f, + 0x11722..0x11725, + 0x11727..0x1172b, + 0x1182f..0x11837, + 0x11839..0x1183a, + 0x1193b..0x1193c, + 0x1193e..0x1193e, + 0x11943..0x11943, + 0x119d4..0x119d7, + 0x119da..0x119db, + 0x119e0..0x119e0, + 0x11a01..0x11a0a, + 0x11a33..0x11a38, + 0x11a3b..0x11a3e, + 0x11a47..0x11a47, + 0x11a51..0x11a56, + 0x11a59..0x11a5b, + 0x11a8a..0x11a96, + 0x11a98..0x11a99, + 0x11c30..0x11c36, + 0x11c38..0x11c3d, + 0x11c3f..0x11c3f, + 0x11c92..0x11ca7, + 0x11caa..0x11cb0, + 0x11cb2..0x11cb3, + 0x11cb5..0x11cb6, + 0x11d31..0x11d36, + 0x11d3a..0x11d3a, + 0x11d3c..0x11d3d, + 0x11d3f..0x11d45, + 0x11d47..0x11d47, + 0x11d90..0x11d91, + 0x11d95..0x11d95, + 0x11d97..0x11d97, + 0x11ef3..0x11ef4, + 0x13430..0x13438, + 0x16af0..0x16af4, + 0x16b30..0x16b36, + 0x16b40..0x16b43, + 0x16f4f..0x16f4f, + 0x16f8f..0x16f92, + 0x16f93..0x16f9f, + 0x16fe0..0x16fe1, + 0x16fe3..0x16fe3, + 0x16fe4..0x16fe4, + 0x1bc9d..0x1bc9e, + 0x1bca0..0x1bca3, + 0x1d167..0x1d169, + 0x1d173..0x1d17a, + 0x1d17b..0x1d182, + 0x1d185..0x1d18b, + 0x1d1aa..0x1d1ad, + 0x1d242..0x1d244, + 0x1da00..0x1da36, + 0x1da3b..0x1da6c, + 0x1da75..0x1da75, + 0x1da84..0x1da84, + 0x1da9b..0x1da9f, + 0x1daa1..0x1daaf, + 0x1e000..0x1e006, + 0x1e008..0x1e018, + 0x1e01b..0x1e021, + 0x1e023..0x1e024, + 0x1e026..0x1e02a, + 0x1e130..0x1e136, + 0x1e137..0x1e13d, + 0x1e2ec..0x1e2ef, + 0x1e8d0..0x1e8d6, + 0x1e944..0x1e94a, + 0x1e94b..0x1e94b, + 0x1f3fb..0x1f3ff, + 0xe0001..0xe0001, + 0xe0020..0xe007f, + 0xe0100..0xe01ef, +) + +class IsCaseIgnorableTest { + @Test + fun isCaseIgnorable() { + var lastChecked = -1 + for (range in caseIgnorableRanges) { + for (codePoint in lastChecked + 1 until range.first) { + assertFalse(codePoint.isCaseIgnorable()) + } + for (codePoint in range.first..range.last) { + assertTrue(codePoint.isCaseIgnorable()) + } + lastChecked = range.last + } + for (codePoint in lastChecked + 1..0x10FFFF) { + assertFalse(codePoint.isCaseIgnorable()) + } + } +} diff --git a/kotlin-native/backend.native/tests/stdlib_external/text/_IsCasedTest.kt b/kotlin-native/backend.native/tests/stdlib_external/text/_IsCasedTest.kt new file mode 100644 index 00000000000..f1a9f3a4db6 --- /dev/null +++ b/kotlin-native/backend.native/tests/stdlib_external/text/_IsCasedTest.kt @@ -0,0 +1,191 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package test.text + +// +// NOTE: THIS FILE IS AUTO-GENERATED by the GenerateUnicodeData.kt +// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib +// + +import kotlin.test.* + +@SharedImmutable +private val casedRanges = arrayOf( + 0x0041..0x005a, + 0x0061..0x007a, + 0x00aa..0x00aa, + 0x00b5..0x00b5, + 0x00ba..0x00ba, + 0x00c0..0x00d6, + 0x00d8..0x00f6, + 0x00f8..0x01ba, + 0x01bc..0x01bf, + 0x01c4..0x0293, + 0x0295..0x02af, + 0x02b0..0x02b8, + 0x02c0..0x02c1, + 0x02e0..0x02e4, + 0x0345..0x0345, + 0x0370..0x0373, + 0x0376..0x0377, + 0x037a..0x037a, + 0x037b..0x037d, + 0x037f..0x037f, + 0x0386..0x0386, + 0x0388..0x038a, + 0x038c..0x038c, + 0x038e..0x03a1, + 0x03a3..0x03f5, + 0x03f7..0x0481, + 0x048a..0x052f, + 0x0531..0x0556, + 0x0560..0x0588, + 0x10a0..0x10c5, + 0x10c7..0x10c7, + 0x10cd..0x10cd, + 0x10d0..0x10fa, + 0x10fd..0x10ff, + 0x13a0..0x13f5, + 0x13f8..0x13fd, + 0x1c80..0x1c88, + 0x1c90..0x1cba, + 0x1cbd..0x1cbf, + 0x1d00..0x1d2b, + 0x1d2c..0x1d6a, + 0x1d6b..0x1d77, + 0x1d78..0x1d78, + 0x1d79..0x1d9a, + 0x1d9b..0x1dbf, + 0x1e00..0x1f15, + 0x1f18..0x1f1d, + 0x1f20..0x1f45, + 0x1f48..0x1f4d, + 0x1f50..0x1f57, + 0x1f59..0x1f59, + 0x1f5b..0x1f5b, + 0x1f5d..0x1f5d, + 0x1f5f..0x1f7d, + 0x1f80..0x1fb4, + 0x1fb6..0x1fbc, + 0x1fbe..0x1fbe, + 0x1fc2..0x1fc4, + 0x1fc6..0x1fcc, + 0x1fd0..0x1fd3, + 0x1fd6..0x1fdb, + 0x1fe0..0x1fec, + 0x1ff2..0x1ff4, + 0x1ff6..0x1ffc, + 0x2071..0x2071, + 0x207f..0x207f, + 0x2090..0x209c, + 0x2102..0x2102, + 0x2107..0x2107, + 0x210a..0x2113, + 0x2115..0x2115, + 0x2119..0x211d, + 0x2124..0x2124, + 0x2126..0x2126, + 0x2128..0x2128, + 0x212a..0x212d, + 0x212f..0x2134, + 0x2139..0x2139, + 0x213c..0x213f, + 0x2145..0x2149, + 0x214e..0x214e, + 0x2160..0x217f, + 0x2183..0x2184, + 0x24b6..0x24e9, + 0x2c00..0x2c2e, + 0x2c30..0x2c5e, + 0x2c60..0x2c7b, + 0x2c7c..0x2c7d, + 0x2c7e..0x2ce4, + 0x2ceb..0x2cee, + 0x2cf2..0x2cf3, + 0x2d00..0x2d25, + 0x2d27..0x2d27, + 0x2d2d..0x2d2d, + 0xa640..0xa66d, + 0xa680..0xa69b, + 0xa69c..0xa69d, + 0xa722..0xa76f, + 0xa770..0xa770, + 0xa771..0xa787, + 0xa78b..0xa78e, + 0xa790..0xa7bf, + 0xa7c2..0xa7ca, + 0xa7f5..0xa7f6, + 0xa7f8..0xa7f9, + 0xa7fa..0xa7fa, + 0xab30..0xab5a, + 0xab5c..0xab5f, + 0xab60..0xab68, + 0xab70..0xabbf, + 0xfb00..0xfb06, + 0xfb13..0xfb17, + 0xff21..0xff3a, + 0xff41..0xff5a, + 0x10400..0x1044f, + 0x104b0..0x104d3, + 0x104d8..0x104fb, + 0x10c80..0x10cb2, + 0x10cc0..0x10cf2, + 0x118a0..0x118df, + 0x16e40..0x16e7f, + 0x1d400..0x1d454, + 0x1d456..0x1d49c, + 0x1d49e..0x1d49f, + 0x1d4a2..0x1d4a2, + 0x1d4a5..0x1d4a6, + 0x1d4a9..0x1d4ac, + 0x1d4ae..0x1d4b9, + 0x1d4bb..0x1d4bb, + 0x1d4bd..0x1d4c3, + 0x1d4c5..0x1d505, + 0x1d507..0x1d50a, + 0x1d50d..0x1d514, + 0x1d516..0x1d51c, + 0x1d51e..0x1d539, + 0x1d53b..0x1d53e, + 0x1d540..0x1d544, + 0x1d546..0x1d546, + 0x1d54a..0x1d550, + 0x1d552..0x1d6a5, + 0x1d6a8..0x1d6c0, + 0x1d6c2..0x1d6da, + 0x1d6dc..0x1d6fa, + 0x1d6fc..0x1d714, + 0x1d716..0x1d734, + 0x1d736..0x1d74e, + 0x1d750..0x1d76e, + 0x1d770..0x1d788, + 0x1d78a..0x1d7a8, + 0x1d7aa..0x1d7c2, + 0x1d7c4..0x1d7cb, + 0x1e900..0x1e943, + 0x1f130..0x1f149, + 0x1f150..0x1f169, + 0x1f170..0x1f189, +) + +class IsCasedTest { + @Test + fun isCased() { + var lastChecked = -1 + for (range in casedRanges) { + for (codePoint in lastChecked + 1 until range.first) { + assertFalse(codePoint.isCased()) + } + for (codePoint in range.first..range.last) { + assertTrue(codePoint.isCased()) + } + lastChecked = range.last + } + for (codePoint in lastChecked + 1..0x10FFFF) { + assertFalse(codePoint.isCased()) + } + } +} diff --git a/kotlin-native/runtime/generator/build.gradle b/kotlin-native/runtime/generator/build.gradle index 33a21a1af2b..877dfbde25f 100644 --- a/kotlin-native/runtime/generator/build.gradle +++ b/kotlin-native/runtime/generator/build.gradle @@ -23,5 +23,5 @@ task generateUnicodeData(type: JavaExec) { group 'application' main 'generators.unicode.GenerateUnicodeDataKt' classpath configurations.generatorRuntime - args = ["native", "${project(":runtime").projectDir}/src/main/kotlin/generated"] + args = ["native", "${project(":runtime").projectDir}/src/main/kotlin/generated", "${project(":backend.native").projectDir}/tests/stdlib_external/text"] } \ No newline at end of file diff --git a/kotlin-native/runtime/src/main/cpp/KString.cpp b/kotlin-native/runtime/src/main/cpp/KString.cpp index f9579a50720..a1a781b19ec 100644 --- a/kotlin-native/runtime/src/main/cpp/KString.cpp +++ b/kotlin-native/runtime/src/main/cpp/KString.cpp @@ -79,160 +79,6 @@ OBJ_GETTER(utf8ToUtf16, const char* rawString, size_t rawStringLength) { RETURN_RESULT_OF(utf8ToUtf16Impl, rawString, end, charCount); } -constexpr KShort uppercaseValuesCache[] = { - 924, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, - 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, - 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 192, 193, 194, 195, 196, - 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, - 213, 214, 247, 216, 217, 218, 219, 220, 221, 222, 376, 256, 256, 258, 258, 260, - 260, 262, 262, 264, 264, 266, 266, 268, 268, 270, 270, 272, 272, 274, 274, 276, - 276, 278, 278, 280, 280, 282, 282, 284, 284, 286, 286, 288, 288, 290, 290, 292, - 292, 294, 294, 296, 296, 298, 298, 300, 300, 302, 302, 304, 73, 306, 306, 308, - 308, 310, 310, 312, 313, 313, 315, 315, 317, 317, 319, 319, 321, 321, 323, 323, - 325, 325, 327, 327, 329, 330, 330, 332, 332, 334, 334, 336, 336, 338, 338, 340, - 340, 342, 342, 344, 344, 346, 346, 348, 348, 350, 350, 352, 352, 354, 354, 356, - 356, 358, 358, 360, 360, 362, 362, 364, 364, 366, 366, 368, 368, 370, 370, 372, - 372, 374, 374, 376, 377, 377, 379, 379, 381, 381, 83, 384, 385, 386, 386, 388, - 388, 390, 391, 391, 393, 394, 395, 395, 397, 398, 399, 400, 401, 401, 403, 404, - 502, 406, 407, 408, 408, 410, 411, 412, 413, 544, 415, 416, 416, 418, 418, 420, - 420, 422, 423, 423, 425, 426, 427, 428, 428, 430, 431, 431, 433, 434, 435, 435, - 437, 437, 439, 440, 440, 442, 443, 444, 444, 446, 503, 448, 449, 450, 451, 452, - 452, 452, 455, 455, 455, 458, 458, 458, 461, 461, 463, 463, 465, 465, 467, 467, - 469, 469, 471, 471, 473, 473, 475, 475, 398, 478, 478, 480, 480, 482, 482, 484, - 484, 486, 486, 488, 488, 490, 490, 492, 492, 494, 494, 496, 497, 497, 497, 500, - 500, 502, 503, 504, 504, 506, 506, 508, 508, 510, 510, 512, 512, 514, 514, 516, - 516, 518, 518, 520, 520, 522, 522, 524, 524, 526, 526, 528, 528, 530, 530, 532, - 532, 534, 534, 536, 536, 538, 538, 540, 540, 542, 542, 544, 545, 546, 546, 548, - 548, 550, 550, 552, 552, 554, 554, 556, 556, 558, 558, 560, 560, 562, 562, 564, - 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, - 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 385, 390, - 597, 393, 394, 600, 399, 602, 400, 604, 605, 606, 607, 403, 609, 610, 404, 612, - 613, 614, 615, 407, 406, 618, 619, 620, 621, 622, 412, 624, 625, 413, 627, 628, - 415, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 422, 641, 642, 425, 644, - 645, 646, 647, 430, 649, 433, 434, 652, 653, 654, 655, 656, 657, 439, 659, 660, - 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, - 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, - 693, 694, 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708, - 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, - 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, - 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, - 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 771, 772, - 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, - 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 800, 801, 802, 803, 804, - 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820, - 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, - 921, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848, 849, 850, 851, 852, - 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, 865, 866, 867, 868, - 869, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, - 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899, 900, - 901, 902, 903, 904, 905, 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, - 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, - 933, 934, 935, 936, 937, 938, 939, 902, 904, 905, 906, 944, 913, 914, 915, 916, - 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 931, 931, 932, - 933, 934, 935, 936, 937, 938, 939, 908, 910, 911, 975, 914, 920, 978, 979, 980, - 934, 928, 983, 984, 984, 986, 986, 988, 988, 990, 990, 992, 992, 994, 994, 996, - 996, 998, 998 -}; - -constexpr KShort lowercaseValuesCache[] = { - 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, - 240, 241, 242, 243, 244, 245, 246, 215, 248, 249, 250, 251, 252, 253, 254, 223, - 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, - 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, - 257, 257, 259, 259, 261, 261, 263, 263, 265, 265, 267, 267, 269, 269, 271, 271, - 273, 273, 275, 275, 277, 277, 279, 279, 281, 281, 283, 283, 285, 285, 287, 287, - 289, 289, 291, 291, 293, 293, 295, 295, 297, 297, 299, 299, 301, 301, 303, 303, - 105, 305, 307, 307, 309, 309, 311, 311, 312, 314, 314, 316, 316, 318, 318, 320, - 320, 322, 322, 324, 324, 326, 326, 328, 328, 329, 331, 331, 333, 333, 335, 335, - 337, 337, 339, 339, 341, 341, 343, 343, 345, 345, 347, 347, 349, 349, 351, 351, - 353, 353, 355, 355, 357, 357, 359, 359, 361, 361, 363, 363, 365, 365, 367, 367, - 369, 369, 371, 371, 373, 373, 375, 375, 255, 378, 378, 380, 380, 382, 382, 383, - 384, 595, 387, 387, 389, 389, 596, 392, 392, 598, 599, 396, 396, 397, 477, 601, - 603, 402, 402, 608, 611, 405, 617, 616, 409, 409, 410, 411, 623, 626, 414, 629, - 417, 417, 419, 419, 421, 421, 640, 424, 424, 643, 426, 427, 429, 429, 648, 432, - 432, 650, 651, 436, 436, 438, 438, 658, 441, 441, 442, 443, 445, 445, 446, 447, - 448, 449, 450, 451, 454, 454, 454, 457, 457, 457, 460, 460, 460, 462, 462, 464, - 464, 466, 466, 468, 468, 470, 470, 472, 472, 474, 474, 476, 476, 477, 479, 479, - 481, 481, 483, 483, 485, 485, 487, 487, 489, 489, 491, 491, 493, 493, 495, 495, - 496, 499, 499, 499, 501, 501, 405, 447, 505, 505, 507, 507, 509, 509, 511, 511, - 513, 513, 515, 515, 517, 517, 519, 519, 521, 521, 523, 523, 525, 525, 527, 527, - 529, 529, 531, 531, 533, 533, 535, 535, 537, 537, 539, 539, 541, 541, 543, 543, - 414, 545, 547, 547, 549, 549, 551, 551, 553, 553, 555, 555, 557, 557, 559, 559, - 561, 561, 563, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, - 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, - 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, - 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, - 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, - 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, - 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, 671, - 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687, - 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701, 702, 703, - 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, - 720, 721, 722, 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, - 736, 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, - 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, - 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, - 784, 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, - 800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, - 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, - 832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, - 848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 863, - 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, - 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, - 896, 897, 898, 899, 900, 901, 940, 903, 941, 942, 943, 907, 972, 909, 973, 974, - 912, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, - 960, 961, 930, 963, 964, 965, 966, 967, 968, 969, 970, 971, 940, 941, 942, 943, - 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, - 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, - 976, 977, 978, 979, 980, 981, 982, 983, 985, 985, 987, 987, 989, 989, 991, 991, - 993, 993, 995, 995, 997, 997, 999, 999 -}; - -constexpr KChar uppercaseKeys[] = { - 0x61, 0xb5, 0xe0, 0xf8, 0xff, 0x101, 0x131, 0x133, 0x13a, 0x14b, 0x17a, 0x17f, 0x183, 0x188, 0x18c, 0x192, 0x195, 0x199, 0x1a1, 0x1a8, - 0x1ad, 0x1b0, 0x1b4, 0x1b9, 0x1bd, 0x1bf, 0x1c5, 0x1c6, 0x1c8, 0x1c9, 0x1cb, 0x1cc, 0x1ce, 0x1dd, 0x1df, 0x1f2, 0x1f3, 0x1f5, 0x1f9, 0x223, - 0x253, 0x254, 0x256, 0x259, 0x25b, 0x260, 0x263, 0x268, 0x269, 0x26f, 0x272, 0x275, 0x280, 0x283, 0x288, 0x28a, 0x292, 0x345, 0x3ac, 0x3ad, - 0x3b1, 0x3c2, 0x3c3, 0x3cc, 0x3cd, 0x3d0, 0x3d1, 0x3d5, 0x3d6, 0x3db, 0x3f0, 0x3f1, 0x3f2, 0x430, 0x450, 0x461, 0x48d, 0x4c2, 0x4c8, 0x4cc, - 0x4d1, 0x4f9, 0x561, 0x1e01, 0x1e9b, 0x1ea1, 0x1f00, 0x1f10, 0x1f20, 0x1f30, 0x1f40, 0x1f51, 0x1f60, 0x1f70, 0x1f72, 0x1f76, 0x1f78, 0x1f7a, 0x1f7c, 0x1f80, - 0x1f90, 0x1fa0, 0x1fb0, 0x1fb3, 0x1fbe, 0x1fc3, 0x1fd0, 0x1fe0, 0x1fe5, 0x1ff3, 0x2170, 0x24d0, 0xff41 -}; - -constexpr KChar uppercaseValues[] = { - 0x7a, 0xffe0, 0xb5, 0x2e7, 0xf6, 0xffe0, 0xfe, 0xffe0, 0xff, 0x79, 0x812f, 0xffff, 0x131, 0xff18, 0x8137, 0xffff, 0x8148, 0xffff, 0x8177, 0xffff, - 0x817e, 0xffff, 0x17f, 0xfed4, 0x8185, 0xffff, 0x188, 0xffff, 0x18c, 0xffff, 0x192, 0xffff, 0x195, 0x61, 0x199, 0xffff, 0x81a5, 0xffff, 0x1a8, 0xffff, - 0x1ad, 0xffff, 0x1b0, 0xffff, 0x81b6, 0xffff, 0x1b9, 0xffff, 0x1bd, 0xffff, 0x1bf, 0x38, 0x1c5, 0xffff, 0x1c6, 0xfffe, 0x1c8, 0xffff, 0x1c9, 0xfffe, - 0x1cb, 0xffff, 0x1cc, 0xfffe, 0x81dc, 0xffff, 0x1dd, 0xffb1, 0x81ef, 0xffff, 0x1f2, 0xffff, 0x1f3, 0xfffe, 0x1f5, 0xffff, 0x821f, 0xffff, 0x8233, 0xffff, - 0x253, 0xff2e, 0x254, 0xff32, 0x257, 0xff33, 0x259, 0xff36, 0x25b, 0xff35, 0x260, 0xff33, 0x263, 0xff31, 0x268, 0xff2f, 0x269, 0xff2d, 0x26f, 0xff2d, - 0x272, 0xff2b, 0x275, 0xff2a, 0x280, 0xff26, 0x283, 0xff26, 0x288, 0xff26, 0x28b, 0xff27, 0x292, 0xff25, 0x345, 0x54, 0x3ac, 0xffda, 0x3af, 0xffdb, - 0x3c1, 0xffe0, 0x3c2, 0xffe1, 0x3cb, 0xffe0, 0x3cc, 0xffc0, 0x3ce, 0xffc1, 0x3d0, 0xffc2, 0x3d1, 0xffc7, 0x3d5, 0xffd1, 0x3d6, 0xffca, 0x83ef, 0xffff, - 0x3f0, 0xffaa, 0x3f1, 0xffb0, 0x3f2, 0xffb1, 0x44f, 0xffe0, 0x45f, 0xffb0, 0x8481, 0xffff, 0x84bf, 0xffff, 0x84c4, 0xffff, 0x4c8, 0xffff, 0x4cc, 0xffff, - 0x84f5, 0xffff, 0x4f9, 0xffff, 0x586, 0xffd0, 0x9e95, 0xffff, 0x1e9b, 0xffc5, 0x9ef9, 0xffff, 0x1f07, 0x8, 0x1f15, 0x8, 0x1f27, 0x8, 0x1f37, 0x8, - 0x1f45, 0x8, 0x9f57, 0x8, 0x1f67, 0x8, 0x1f71, 0x4a, 0x1f75, 0x56, 0x1f77, 0x64, 0x1f79, 0x80, 0x1f7b, 0x70, 0x1f7d, 0x7e, 0x1f87, 0x8, - 0x1f97, 0x8, 0x1fa7, 0x8, 0x1fb1, 0x8, 0x1fb3, 0x9, 0x1fbe, 0xe3db, 0x1fc3, 0x9, 0x1fd1, 0x8, 0x1fe1, 0x8, 0x1fe5, 0x7, 0x1ff3, 0x9, - 0x217f, 0xfff0, 0x24e9, 0xffe6, 0xff5a, 0xffe0 -}; - -constexpr KChar lowercaseKeys[] = { - 0x41, 0xc0, 0xd8, 0x100, 0x130, 0x132, 0x139, 0x14a, 0x178, 0x179, 0x181, 0x182, 0x186, 0x187, 0x189, 0x18b, 0x18e, 0x18f, 0x190, 0x191, - 0x193, 0x194, 0x196, 0x197, 0x198, 0x19c, 0x19d, 0x19f, 0x1a0, 0x1a6, 0x1a7, 0x1a9, 0x1ac, 0x1ae, 0x1af, 0x1b1, 0x1b3, 0x1b7, 0x1b8, 0x1bc, - 0x1c4, 0x1c5, 0x1c7, 0x1c8, 0x1ca, 0x1cb, 0x1de, 0x1f1, 0x1f2, 0x1f6, 0x1f7, 0x1f8, 0x222, 0x386, 0x388, 0x38c, 0x38e, 0x391, 0x3a3, 0x3da, - 0x400, 0x410, 0x460, 0x48c, 0x4c1, 0x4c7, 0x4cb, 0x4d0, 0x4f8, 0x531, 0x1e00, 0x1ea0, 0x1f08, 0x1f18, 0x1f28, 0x1f38, 0x1f48, 0x1f59, 0x1f68, 0x1f88, - 0x1f98, 0x1fa8, 0x1fb8, 0x1fba, 0x1fbc, 0x1fc8, 0x1fcc, 0x1fd8, 0x1fda, 0x1fe8, 0x1fea, 0x1fec, 0x1ff8, 0x1ffa, 0x1ffc, 0x2126, 0x212a, 0x212b, 0x2160, 0x24b6 -}; - -constexpr KChar lowercaseValues[] = { - 0x5a, 0x20, 0xd6, 0x20, 0xde, 0x20, 0x812e, 0x1, 0x130, 0xff39, 0x8136, 0x1, 0x8147, 0x1, 0x8176, 0x1, 0x178, 0xff87, 0x817d, 0x1, - 0x181, 0xd2, 0x8184, 0x1, 0x186, 0xce, 0x187, 0x1, 0x18a, 0xcd, 0x18b, 0x1, 0x18e, 0x4f, 0x18f, 0xca, 0x190, 0xcb, 0x191, 0x1, - 0x193, 0xcd, 0x194, 0xcf, 0x196, 0xd3, 0x197, 0xd1, 0x198, 0x1, 0x19c, 0xd3, 0x19d, 0xd5, 0x19f, 0xd6, 0x81a4, 0x1, 0x1a6, 0xda, - 0x1a7, 0x1, 0x1a9, 0xda, 0x1ac, 0x1, 0x1ae, 0xda, 0x1af, 0x1, 0x1b2, 0xd9, 0x81b5, 0x1, 0x1b7, 0xdb, 0x1b8, 0x1, 0x1bc, 0x1, - 0x1c4, 0x2, 0x1c5, 0x1, 0x1c7, 0x2, 0x1c8, 0x1, 0x1ca, 0x2, 0x81db, 0x1, 0x81ee, 0x1, 0x1f1, 0x2, 0x81f4, 0x1, 0x1f6, 0xff9f, - 0x1f7, 0xffc8, 0x821e, 0x1, 0x8232, 0x1, 0x386, 0x26, 0x38a, 0x25, 0x38c, 0x40, 0x38f, 0x3f, 0x3a1, 0x20, 0x3ab, 0x20, 0x83ee, 0x1, - 0x40f, 0x50, 0x42f, 0x20, 0x8480, 0x1, 0x84be, 0x1, 0x84c3, 0x1, 0x4c7, 0x1, 0x4cb, 0x1, 0x84f4, 0x1, 0x4f8, 0x1, 0x556, 0x30, - 0x9e94, 0x1, 0x9ef8, 0x1, 0x1f0f, 0xfff8, 0x1f1d, 0xfff8, 0x1f2f, 0xfff8, 0x1f3f, 0xfff8, 0x1f4d, 0xfff8, 0x9f5f, 0xfff8, 0x1f6f, 0xfff8, 0x1f8f, 0xfff8, - 0x1f9f, 0xfff8, 0x1faf, 0xfff8, 0x1fb9, 0xfff8, 0x1fbb, 0xffb6, 0x1fbc, 0xfff7, 0x1fcb, 0xffaa, 0x1fcc, 0xfff7, 0x1fd9, 0xfff8, 0x1fdb, 0xff9c, 0x1fe9, 0xfff8, - 0x1feb, 0xff90, 0x1fec, 0xfff9, 0x1ff9, 0xff80, 0x1ffb, 0xff82, 0x1ffc, 0xfff7, 0x2126, 0xe2a3, 0x212a, 0xdf41, 0x212b, 0xdfba, 0x216f, 0x10, 0x24cf, 0x1a -}; - constexpr KChar digitKeys[] = { 0x30, 0x41, 0x61, 0x660, 0x6f0, 0x966, 0x9e6, 0xa66, 0xae6, 0xb66, 0xbe7, 0xc66, 0xce6, 0xd66, 0xe50, 0xed0, 0xf20, 0x1040, 0x1369, 0x17e0, 0x1810, 0xff10, 0xff21, 0xff41 @@ -244,69 +90,6 @@ constexpr KChar digitValues[] = { 0x1819, 0x1810, 0xff19, 0xff10, 0xff3a, 0xff17, 0xff5a, 0xff37 }; -KChar towupper_Konan(KChar ch) { - // Optimized case for ASCII. - if ('a' <= ch && ch <= 'z') { - return ch - ('a' - 'A'); - } - if (ch < 181) { - return ch; - } - if (ch < 1000) { - return uppercaseValuesCache[ch - 181]; - } - int result = binarySearchRange(uppercaseKeys, ARRAY_SIZE(uppercaseKeys), ch); - if (result >= 0) { - bool by2 = false; - KChar start = uppercaseKeys[result]; - KChar end = uppercaseValues[result * 2]; - if ((start & 0x8000) != (end & 0x8000)) { - end ^= 0x8000; - by2 = true; - } - if (ch <= end) { - if (by2 && (ch & 1) != (start & 1)) { - return ch; - } - KChar mapping = uppercaseValues[result * 2 + 1]; - return ch + mapping; - } - } - return ch; -} - -KChar towlower_Konan(KChar ch) { - // Optimized case for ASCII. - if ('A' <= ch && ch <= 'Z') { - return ch + ('a' - 'A'); - } - if (ch < 192) { - return ch; - } - if (ch < 1000) { - return lowercaseValuesCache[ch - 192]; - } - - int result = binarySearchRange(lowercaseKeys, ARRAY_SIZE(lowercaseKeys), ch); - if (result >= 0) { - bool by2 = false; - KChar start = lowercaseKeys[result]; - KChar end = lowercaseValues[result * 2]; - if ((start & 0x8000) != (end & 0x8000)) { - end ^= 0x8000; - by2 = true; - } - if (ch <= end) { - if (by2 && (ch & 1) != (start & 1)) { - return ch; - } - KChar mapping = lowercaseValues[result * 2 + 1]; - return ch + mapping; - } - } - return ch; -} - } // namespace extern "C" { @@ -336,22 +119,14 @@ void DisposeCString(char* cstring) { } // String.kt -OBJ_GETTER(Kotlin_String_replace, KString thiz, KChar oldChar, KChar newChar, KBoolean ignoreCase) { +OBJ_GETTER(Kotlin_String_replace, KString thiz, KChar oldChar, KChar newChar) { auto count = thiz->count_; ArrayHeader* result = AllocArrayInstance(theStringTypeInfo, count, OBJ_RESULT)->array(); const KChar* thizRaw = CharArrayAddressOfElementAt(thiz, 0); KChar* resultRaw = CharArrayAddressOfElementAt(result, 0); - if (ignoreCase) { - KChar oldCharLower = towlower_Konan(oldChar); - for (uint32_t index = 0; index < count; ++index) { - KChar thizChar = *thizRaw++; - *resultRaw++ = towlower_Konan(thizChar) == oldCharLower ? newChar : thizChar; - } - } else { - for (uint32_t index = 0; index < count; ++index) { - KChar thizChar = *thizRaw++; - *resultRaw++ = thizChar == oldChar ? newChar : thizChar; - } + for (uint32_t index = 0; index < count; ++index) { + KChar thizChar = *thizRaw++; + *resultRaw++ = thizChar == oldChar ? newChar : thizChar; } RETURN_OBJ(result->obj()); } @@ -380,28 +155,6 @@ OBJ_GETTER(Kotlin_String_plusImpl, KString thiz, KString other) { RETURN_OBJ(result->obj()); } -OBJ_GETTER(Kotlin_String_toUpperCase, KString thiz) { - auto count = thiz->count_; - ArrayHeader* result = AllocArrayInstance(theStringTypeInfo, count, OBJ_RESULT)->array(); - const KChar* thizRaw = CharArrayAddressOfElementAt(thiz, 0); - KChar* resultRaw = CharArrayAddressOfElementAt(result, 0); - for (uint32_t index = 0; index < count; ++index) { - *resultRaw++ = towupper_Konan(*thizRaw++); - } - RETURN_OBJ(result->obj()); -} - -OBJ_GETTER(Kotlin_String_toLowerCase, KString thiz) { - auto count = thiz->count_; - ArrayHeader* result = AllocArrayInstance(theStringTypeInfo, count, OBJ_RESULT)->array(); - const KChar* thizRaw = CharArrayAddressOfElementAt(thiz, 0); - KChar* resultRaw = CharArrayAddressOfElementAt(result, 0); - for (uint32_t index = 0; index < count; ++index) { - *resultRaw++ = towlower_Konan(*thizRaw++); - } - RETURN_OBJ(result->obj()); -} - OBJ_GETTER(Kotlin_String_unsafeStringFromCharArray, KConstRef thiz, KInt start, KInt size) { const ArrayHeader* array = thiz->array(); RuntimeAssert(array->type_info() == theCharArrayTypeInfo, "Must use a char array"); @@ -452,28 +205,6 @@ KInt Kotlin_String_compareTo(KString thiz, KString other) { return diff < 0 ? -1 : 1; } -KInt Kotlin_String_compareToIgnoreCase(KString thiz, KConstRef other) { - RuntimeAssert(thiz->type_info() == theStringTypeInfo && - other->type_info() == theStringTypeInfo, "Must be strings"); - // Important, due to literal internalization. - KString otherString = other->array(); - if (thiz == otherString) return 0; - auto count = thiz->count_ < otherString->count_ ? thiz->count_ : otherString->count_; - const KChar* thizRaw = CharArrayAddressOfElementAt(thiz, 0); - const KChar* otherRaw = CharArrayAddressOfElementAt(otherString, 0); - for (uint32_t index = 0; index < count; ++index) { - int diff = towlower_Konan(*thizRaw++) - towlower_Konan(*otherRaw++); - if (diff != 0) - return diff < 0 ? -1 : 1; - } - if (otherString->count_ == thiz->count_) - return 0; - else if (otherString->count_ > thiz->count_) - return -1; - else - return 1; -} - KChar Kotlin_String_get(KString thiz, KInt index) { // We couldn't have created a string bigger than max KInt value. @@ -563,42 +294,13 @@ KBoolean Kotlin_String_equals(KString thiz, KConstRef other) { thiz->count_ * sizeof(KChar)) == 0; } -KBoolean Kotlin_String_equalsIgnoreCase(KString thiz, KConstRef other) { - RuntimeAssert(thiz->type_info() == theStringTypeInfo && - other->type_info() == theStringTypeInfo, "Must be strings"); - // Important, due to literal internalization. - KString otherString = other->array(); - if (thiz == otherString) return true; - if (thiz->count_ != otherString->count_) return false; - auto count = thiz->count_; - const KChar* thizRaw = CharArrayAddressOfElementAt(thiz, 0); - const KChar* otherRaw = CharArrayAddressOfElementAt(otherString, 0); - for (uint32_t index = 0; index < count; ++index) { - if (towlower_Konan(*thizRaw++) != towlower_Konan(*otherRaw++)) return false; - } - return true; -} - -KBoolean Kotlin_String_regionMatches(KString thiz, KInt thizOffset, - KString other, KInt otherOffset, - KInt length, KBoolean ignoreCase) { - if (length < 0 || - thizOffset < 0 || length > static_cast(thiz->count_) - thizOffset || - otherOffset < 0 || length > static_cast(other->count_) - otherOffset) { - return false; - } - const KChar* thizRaw = CharArrayAddressOfElementAt(thiz, thizOffset); - const KChar* otherRaw = CharArrayAddressOfElementAt(other, otherOffset); - if (ignoreCase) { - for (KInt index = 0; index < length; ++index) { - if (towlower_Konan(*thizRaw++) != towlower_Konan(*otherRaw++)) return false; - } - } else { - for (KInt index = 0; index < length; ++index) { - if (*thizRaw++ != *otherRaw++) return false; - } - } - return true; +// Bounds checks is are performed on Kotlin side +KBoolean Kotlin_String_unsafeRangeEquals(KString thiz, KInt thizOffset, KString other, KInt otherOffset, KInt length) { + return memcmp( + CharArrayAddressOfElementAt(thiz, thizOffset), + CharArrayAddressOfElementAt(other, otherOffset), + length * sizeof(KChar) + ) == 0; } KBoolean Kotlin_Char_isIdentifierIgnorable(KChar ch) { @@ -618,14 +320,6 @@ KBoolean Kotlin_Char_isLowSurrogate(KChar ch) { return ((ch & 0xfc00) == 0xdc00); } -KChar Kotlin_Char_toLowerCase(KChar ch) { - return towlower_Konan(ch); -} - -KChar Kotlin_Char_toUpperCase(KChar ch) { - return towupper_Konan(ch); -} - constexpr KInt digits[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, diff --git a/kotlin-native/runtime/src/main/kotlin/generated/_LowercaseMappings.kt b/kotlin-native/runtime/src/main/kotlin/generated/_LowercaseMappings.kt new file mode 100644 index 00000000000..542cac8fe7c --- /dev/null +++ b/kotlin-native/runtime/src/main/kotlin/generated/_LowercaseMappings.kt @@ -0,0 +1,53 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package kotlin.text + +// +// NOTE: THIS FILE IS AUTO-GENERATED by the GenerateUnicodeData.kt +// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib +// + +// 174 ranges totally +@SharedImmutable +private val rangeStart = intArrayOf( + 0x0041, 0x00c0, 0x00d8, 0x0100, 0x0130, 0x0132, 0x0139, 0x014a, 0x0178, 0x0179, 0x0181, 0x0182, 0x0186, 0x0187, 0x0189, 0x018b, 0x018e, 0x018f, 0x0190, 0x0191, + 0x0193, 0x0194, 0x0196, 0x0197, 0x0198, 0x019c, 0x019d, 0x019f, 0x01a0, 0x01a6, 0x01a7, 0x01a9, 0x01ac, 0x01ae, 0x01af, 0x01b1, 0x01b3, 0x01b7, 0x01b8, 0x01c4, + 0x01c5, 0x01c7, 0x01c8, 0x01ca, 0x01cb, 0x01de, 0x01f1, 0x01f2, 0x01f6, 0x01f7, 0x01f8, 0x0220, 0x0222, 0x023a, 0x023b, 0x023d, 0x023e, 0x0241, 0x0243, 0x0244, + 0x0245, 0x0246, 0x0370, 0x0376, 0x037f, 0x0386, 0x0388, 0x038c, 0x038e, 0x0391, 0x03a3, 0x03cf, 0x03d8, 0x03f4, 0x03f7, 0x03f9, 0x03fa, 0x03fd, 0x0400, 0x0410, + 0x0460, 0x048a, 0x04c0, 0x04c1, 0x04d0, 0x0531, 0x10a0, 0x10c7, 0x13a0, 0x13f0, 0x1c90, 0x1cbd, 0x1e00, 0x1e9e, 0x1ea0, 0x1f08, 0x1f18, 0x1f28, 0x1f38, 0x1f48, + 0x1f59, 0x1f68, 0x1f88, 0x1f98, 0x1fa8, 0x1fb8, 0x1fba, 0x1fbc, 0x1fc8, 0x1fcc, 0x1fd8, 0x1fda, 0x1fe8, 0x1fea, 0x1fec, 0x1ff8, 0x1ffa, 0x1ffc, 0x2126, 0x212a, + 0x212b, 0x2132, 0x2160, 0x2183, 0x24b6, 0x2c00, 0x2c60, 0x2c62, 0x2c63, 0x2c64, 0x2c67, 0x2c6d, 0x2c6e, 0x2c6f, 0x2c70, 0x2c72, 0x2c7e, 0x2c80, 0x2ceb, 0x2cf2, + 0xa640, 0xa680, 0xa722, 0xa732, 0xa779, 0xa77d, 0xa77e, 0xa78b, 0xa78d, 0xa790, 0xa796, 0xa7aa, 0xa7ab, 0xa7ac, 0xa7ad, 0xa7ae, 0xa7b0, 0xa7b1, 0xa7b2, 0xa7b3, + 0xa7b4, 0xa7c2, 0xa7c4, 0xa7c5, 0xa7c6, 0xa7c7, 0xa7f5, 0xff21, 0x10400, 0x104b0, 0x10c80, 0x118a0, 0x16e40, 0x1e900, +) + +@SharedImmutable +private val rangeLength = intArrayOf( + 0x2011a, 0x20117, 0x20107, 0x122f, -0xc6eff, 0x1205, 0x120f, 0x122d, -0x78eff, 0x1205, 0xd2101, 0x1203, 0xce101, 0x1101, 0xcd102, 0x1101, 0x4f101, 0xca101, 0xcb101, 0x1101, + 0xcd101, 0xcf101, 0xd3101, 0xd1101, 0x1101, 0xd3101, 0xd5101, 0xd6101, 0x1205, 0xda101, 0x1101, 0xda101, 0x1101, 0xda101, 0x1101, 0xd9102, 0x1203, 0xdb101, 0x1405, 0x2101, + 0x1101, 0x2101, 0x1101, 0x2101, 0x1211, 0x1211, 0x2101, 0x1203, -0x60eff, -0x37eff, 0x1227, -0x81eff, 0x1211, 0x2a2b101, 0x1101, -0xa2eff, 0x2a28101, 0x1101, -0xc2eff, 0x45101, + 0x47101, 0x1209, 0x1203, 0x1101, 0x74101, 0x26101, 0x25103, 0x40101, 0x3f102, 0x20111, 0x20109, 0x8101, 0x1217, -0x3beff, 0x1101, -0x6eff, 0x1101, -0x81efd, 0x50110, 0x20120, + 0x1221, 0x1235, 0xf101, 0x120d, 0x125f, 0x30126, 0x1c60126, 0x1c60607, 0x97d0150, 0x8106, -0xbbfed5, -0xbbfefd, 0x1295, -0x1dbeeff, 0x125f, -0x7ef8, -0x7efa, -0x7ef8, -0x7ef8, -0x7efa, + -0x7df9, -0x7ef8, -0x7ef8, -0x7ef8, -0x7ef8, -0x7efe, -0x49efe, -0x8eff, -0x55efc, -0x8eff, -0x7efe, -0x63efe, -0x7efe, -0x6fefe, -0x6eff, -0x7fefe, -0x7defe, -0x8eff, -0x1d5ceff, -0x20beeff, + -0x2045eff, 0x1c101, 0x10110, 0x1101, 0x1a11a, 0x3012f, 0x1101, -0x29f6eff, -0xee5eff, -0x29e6eff, 0x1205, -0x2a1beff, -0x29fceff, -0x2a1eeff, -0x2a1deff, 0x1304, -0x2a3eefe, 0x1263, 0x1203, 0x1101, + 0x122d, 0x121b, 0x120d, 0x123d, 0x1203, -0x8a03eff, 0x1209, 0x1101, -0xa527eff, 0x1203, 0x1213, -0xa543eff, -0xa54eeff, -0xa54aeff, -0xa540eff, -0xa543eff, -0xa511eff, -0xa529eff, -0xa514eff, 0x3a0101, + 0x120b, 0x1101, -0x2feff, -0xa542eff, -0x8a37eff, 0x1203, 0x1101, 0x2011a, 0x28128, 0x28124, 0x40133, 0x20120, 0x20120, 0x22122, +) + +internal fun Int.lowercaseCodePoint(): Int { + if (this in 0x41..0x5a) { + return this + 32 + } + if (this < 0x80) { + return this + } + val index = binarySearchRange(rangeStart, this) + return equalDistanceMapping(this, rangeStart[index], rangeLength[index]) +} + +internal fun Char.lowercaseCharImpl(): Char { + return toInt().lowercaseCodePoint().toChar() +} diff --git a/kotlin-native/runtime/src/main/kotlin/generated/_OneToManyLowercaseMappings.kt b/kotlin-native/runtime/src/main/kotlin/generated/_OneToManyLowercaseMappings.kt new file mode 100644 index 00000000000..334d1245de2 --- /dev/null +++ b/kotlin-native/runtime/src/main/kotlin/generated/_OneToManyLowercaseMappings.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package kotlin.text + +// +// NOTE: THIS FILE IS AUTO-GENERATED by the GenerateUnicodeData.kt +// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib +// + +// 1 mappings totally +internal fun Char.lowercaseImpl(): String { + if (this == '\u0130') { + return "\u0069\u0307" + } + return lowercaseCharImpl().toString() +} diff --git a/kotlin-native/runtime/src/main/kotlin/generated/_OneToManyUppercaseMappings.kt b/kotlin-native/runtime/src/main/kotlin/generated/_OneToManyUppercaseMappings.kt new file mode 100644 index 00000000000..8a047c2ff98 --- /dev/null +++ b/kotlin-native/runtime/src/main/kotlin/generated/_OneToManyUppercaseMappings.kt @@ -0,0 +1,48 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package kotlin.text + +// +// NOTE: THIS FILE IS AUTO-GENERATED by the GenerateUnicodeData.kt +// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib +// + +// 102 mappings totally +@SharedImmutable +private val keys = intArrayOf( + 0x00df, 0x0149, 0x01f0, 0x0390, 0x03b0, 0x0587, 0x1e96, 0x1e97, 0x1e98, 0x1e99, 0x1e9a, 0x1f50, 0x1f52, 0x1f54, 0x1f56, 0x1f80, 0x1f81, 0x1f82, 0x1f83, 0x1f84, + 0x1f85, 0x1f86, 0x1f87, 0x1f88, 0x1f89, 0x1f8a, 0x1f8b, 0x1f8c, 0x1f8d, 0x1f8e, 0x1f8f, 0x1f90, 0x1f91, 0x1f92, 0x1f93, 0x1f94, 0x1f95, 0x1f96, 0x1f97, 0x1f98, + 0x1f99, 0x1f9a, 0x1f9b, 0x1f9c, 0x1f9d, 0x1f9e, 0x1f9f, 0x1fa0, 0x1fa1, 0x1fa2, 0x1fa3, 0x1fa4, 0x1fa5, 0x1fa6, 0x1fa7, 0x1fa8, 0x1fa9, 0x1faa, 0x1fab, 0x1fac, + 0x1fad, 0x1fae, 0x1faf, 0x1fb2, 0x1fb3, 0x1fb4, 0x1fb6, 0x1fb7, 0x1fbc, 0x1fc2, 0x1fc3, 0x1fc4, 0x1fc6, 0x1fc7, 0x1fcc, 0x1fd2, 0x1fd3, 0x1fd6, 0x1fd7, 0x1fe2, + 0x1fe3, 0x1fe4, 0x1fe6, 0x1fe7, 0x1ff2, 0x1ff3, 0x1ff4, 0x1ff6, 0x1ff7, 0x1ffc, 0xfb00, 0xfb01, 0xfb02, 0xfb03, 0xfb04, 0xfb05, 0xfb06, 0xfb13, 0xfb14, 0xfb15, + 0xfb16, 0xfb17, +) +@SharedImmutable +private val values = arrayOf( + "\u0053\u0053", "\u02BC\u004E", "\u004A\u030C", "\u0399\u0308\u0301", "\u03A5\u0308\u0301", "\u0535\u0552", "\u0048\u0331", "\u0054\u0308", "\u0057\u030A", "\u0059\u030A", "\u0041\u02BE", "\u03A5\u0313", "\u03A5\u0313\u0300", "\u03A5\u0313\u0301", "\u03A5\u0313\u0342", "\u1F08\u0399", "\u1F09\u0399", "\u1F0A\u0399", "\u1F0B\u0399", "\u1F0C\u0399", + "\u1F0D\u0399", "\u1F0E\u0399", "\u1F0F\u0399", "\u1F08\u0399", "\u1F09\u0399", "\u1F0A\u0399", "\u1F0B\u0399", "\u1F0C\u0399", "\u1F0D\u0399", "\u1F0E\u0399", "\u1F0F\u0399", "\u1F28\u0399", "\u1F29\u0399", "\u1F2A\u0399", "\u1F2B\u0399", "\u1F2C\u0399", "\u1F2D\u0399", "\u1F2E\u0399", "\u1F2F\u0399", "\u1F28\u0399", + "\u1F29\u0399", "\u1F2A\u0399", "\u1F2B\u0399", "\u1F2C\u0399", "\u1F2D\u0399", "\u1F2E\u0399", "\u1F2F\u0399", "\u1F68\u0399", "\u1F69\u0399", "\u1F6A\u0399", "\u1F6B\u0399", "\u1F6C\u0399", "\u1F6D\u0399", "\u1F6E\u0399", "\u1F6F\u0399", "\u1F68\u0399", "\u1F69\u0399", "\u1F6A\u0399", "\u1F6B\u0399", "\u1F6C\u0399", + "\u1F6D\u0399", "\u1F6E\u0399", "\u1F6F\u0399", "\u1FBA\u0399", "\u0391\u0399", "\u0386\u0399", "\u0391\u0342", "\u0391\u0342\u0399", "\u0391\u0399", "\u1FCA\u0399", "\u0397\u0399", "\u0389\u0399", "\u0397\u0342", "\u0397\u0342\u0399", "\u0397\u0399", "\u0399\u0308\u0300", "\u0399\u0308\u0301", "\u0399\u0342", "\u0399\u0308\u0342", "\u03A5\u0308\u0300", + "\u03A5\u0308\u0301", "\u03A1\u0313", "\u03A5\u0342", "\u03A5\u0308\u0342", "\u1FFA\u0399", "\u03A9\u0399", "\u038F\u0399", "\u03A9\u0342", "\u03A9\u0342\u0399", "\u03A9\u0399", "\u0046\u0046", "\u0046\u0049", "\u0046\u004C", "\u0046\u0046\u0049", "\u0046\u0046\u004C", "\u0053\u0054", "\u0053\u0054", "\u0544\u0546", "\u0544\u0535", "\u0544\u053B", + "\u054E\u0546", "\u0544\u053D", +) + +internal fun Char.oneToManyUppercase(): String? { + if (this < '\u00df') { + return null + } + + val code = this.toInt() + val index = binarySearchRange(keys, code) + if (keys[index] == code) { + return values[index] + } + return null +} + +internal fun Char.uppercaseImpl(): String { + return oneToManyUppercase() ?: uppercaseCharImpl().toString() +} diff --git a/kotlin-native/runtime/src/main/kotlin/generated/_StringLowercase.kt b/kotlin-native/runtime/src/main/kotlin/generated/_StringLowercase.kt new file mode 100644 index 00000000000..b45f11d8ce8 --- /dev/null +++ b/kotlin-native/runtime/src/main/kotlin/generated/_StringLowercase.kt @@ -0,0 +1,161 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package kotlin.text + +// +// NOTE: THIS FILE IS AUTO-GENERATED by the GenerateUnicodeData.kt +// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib +// + +@SharedImmutable +private val casedStart = intArrayOf( + 0x00aa, 0x00ba, 0x02b0, 0x02c0, 0x02e0, 0x0345, 0x037a, 0x1d2c, 0x1d78, 0x1d9b, 0x2071, 0x207f, 0x2090, 0x2160, 0x2170, 0x24b6, 0x24d0, 0x2c7c, 0xa69c, 0xa770, + 0xa7f8, 0xab5c, 0x10400, 0x104b0, 0x104d8, 0x10c80, 0x10cc0, 0x118a0, 0x16e40, 0x1d400, 0x1d456, 0x1d49e, 0x1d4a2, 0x1d4a5, 0x1d4a9, 0x1d4ae, 0x1d4bb, 0x1d4bd, 0x1d4c5, 0x1d507, + 0x1d50d, 0x1d516, 0x1d51e, 0x1d53b, 0x1d540, 0x1d546, 0x1d54a, 0x1d552, 0x1d6a8, 0x1d6c2, 0x1d6dc, 0x1d6fc, 0x1d716, 0x1d736, 0x1d750, 0x1d770, 0x1d78a, 0x1d7aa, 0x1d7c4, 0x1e900, + 0x1f130, 0x1f150, 0x1f170, +) +@SharedImmutable +private val casedEnd = intArrayOf( + 0x00aa, 0x00ba, 0x02b8, 0x02c1, 0x02e4, 0x0345, 0x037a, 0x1d6a, 0x1d78, 0x1dbf, 0x2071, 0x207f, 0x209c, 0x216f, 0x217f, 0x24cf, 0x24e9, 0x2c7d, 0xa69d, 0xa770, + 0xa7f9, 0xab5f, 0x1044f, 0x104d3, 0x104fb, 0x10cb2, 0x10cf2, 0x118df, 0x16e7f, 0x1d454, 0x1d49c, 0x1d49f, 0x1d4a2, 0x1d4a6, 0x1d4ac, 0x1d4b9, 0x1d4bb, 0x1d4c3, 0x1d505, 0x1d50a, + 0x1d514, 0x1d51c, 0x1d539, 0x1d53e, 0x1d544, 0x1d546, 0x1d550, 0x1d6a5, 0x1d6c0, 0x1d6da, 0x1d6fa, 0x1d714, 0x1d734, 0x1d74e, 0x1d76e, 0x1d788, 0x1d7a8, 0x1d7c2, 0x1d7cb, 0x1e943, + 0x1f149, 0x1f169, 0x1f189, +) + +// Lu + Ll + Lt + Other_Lowercase + Other_Uppercase (PropList.txt of Unicode Character Database files) +// Declared internal for testing +internal fun Int.isCased(): Boolean { + if (this <= Char.MAX_VALUE.toInt()) { + when (toChar().getCategoryValue()) { + CharCategory.UPPERCASE_LETTER.value, + CharCategory.LOWERCASE_LETTER.value, + CharCategory.TITLECASE_LETTER.value -> return true + } + } + val index = binarySearchRange(casedStart, this) + return index >= 0 && this <= casedEnd[index] +} + +@SharedImmutable +private val caseIgnorableStart = intArrayOf( + 0x0027, 0x002e, 0x003a, 0x00b7, 0x0387, 0x055f, 0x05f4, 0x2018, 0x2019, 0x2024, 0x2027, 0xfe13, 0xfe52, 0xfe55, 0xff07, 0xff0e, 0xff1a, 0x101fd, 0x102e0, 0x10376, + 0x10a01, 0x10a05, 0x10a0c, 0x10a38, 0x10a3f, 0x10ae5, 0x10d24, 0x10eab, 0x10f46, 0x11001, 0x11038, 0x1107f, 0x110b3, 0x110b9, 0x110bd, 0x110cd, 0x11100, 0x11127, 0x1112d, 0x11173, + 0x11180, 0x111b6, 0x111c9, 0x111cf, 0x1122f, 0x11234, 0x11236, 0x1123e, 0x112df, 0x112e3, 0x11300, 0x1133b, 0x11340, 0x11366, 0x11370, 0x11438, 0x11442, 0x11446, 0x1145e, 0x114b3, + 0x114ba, 0x114bf, 0x114c2, 0x115b2, 0x115bc, 0x115bf, 0x115dc, 0x11633, 0x1163d, 0x1163f, 0x116ab, 0x116ad, 0x116b0, 0x116b7, 0x1171d, 0x11722, 0x11727, 0x1182f, 0x11839, 0x1193b, + 0x1193e, 0x11943, 0x119d4, 0x119da, 0x119e0, 0x11a01, 0x11a33, 0x11a3b, 0x11a47, 0x11a51, 0x11a59, 0x11a8a, 0x11a98, 0x11c30, 0x11c38, 0x11c3f, 0x11c92, 0x11caa, 0x11cb2, 0x11cb5, + 0x11d31, 0x11d3a, 0x11d3c, 0x11d3f, 0x11d47, 0x11d90, 0x11d95, 0x11d97, 0x11ef3, 0x13430, 0x16af0, 0x16b30, 0x16b40, 0x16f4f, 0x16f8f, 0x16fe0, 0x16fe3, 0x1bc9d, 0x1bca0, 0x1d167, + 0x1d173, 0x1d185, 0x1d1aa, 0x1d242, 0x1da00, 0x1da3b, 0x1da75, 0x1da84, 0x1da9b, 0x1daa1, 0x1e000, 0x1e008, 0x1e01b, 0x1e023, 0x1e026, 0x1e130, 0x1e2ec, 0x1e8d0, 0x1e944, 0x1f3fb, + 0xe0001, 0xe0020, 0xe0100, +) +@SharedImmutable +private val caseIgnorableEnd = intArrayOf( + 0x0027, 0x002e, 0x003a, 0x00b7, 0x0387, 0x055f, 0x05f4, 0x2018, 0x2019, 0x2024, 0x2027, 0xfe13, 0xfe52, 0xfe55, 0xff07, 0xff0e, 0xff1a, 0x101fd, 0x102e0, 0x1037a, + 0x10a03, 0x10a06, 0x10a0f, 0x10a3a, 0x10a3f, 0x10ae6, 0x10d27, 0x10eac, 0x10f50, 0x11001, 0x11046, 0x11081, 0x110b6, 0x110ba, 0x110bd, 0x110cd, 0x11102, 0x1112b, 0x11134, 0x11173, + 0x11181, 0x111be, 0x111cc, 0x111cf, 0x11231, 0x11234, 0x11237, 0x1123e, 0x112df, 0x112ea, 0x11301, 0x1133c, 0x11340, 0x1136c, 0x11374, 0x1143f, 0x11444, 0x11446, 0x1145e, 0x114b8, + 0x114ba, 0x114c0, 0x114c3, 0x115b5, 0x115bd, 0x115c0, 0x115dd, 0x1163a, 0x1163d, 0x11640, 0x116ab, 0x116ad, 0x116b5, 0x116b7, 0x1171f, 0x11725, 0x1172b, 0x11837, 0x1183a, 0x1193c, + 0x1193e, 0x11943, 0x119d7, 0x119db, 0x119e0, 0x11a0a, 0x11a38, 0x11a3e, 0x11a47, 0x11a56, 0x11a5b, 0x11a96, 0x11a99, 0x11c36, 0x11c3d, 0x11c3f, 0x11ca7, 0x11cb0, 0x11cb3, 0x11cb6, + 0x11d36, 0x11d3a, 0x11d3d, 0x11d45, 0x11d47, 0x11d91, 0x11d95, 0x11d97, 0x11ef4, 0x13438, 0x16af4, 0x16b36, 0x16b43, 0x16f4f, 0x16f9f, 0x16fe1, 0x16fe4, 0x1bc9e, 0x1bca3, 0x1d169, + 0x1d182, 0x1d18b, 0x1d1ad, 0x1d244, 0x1da36, 0x1da6c, 0x1da75, 0x1da84, 0x1da9f, 0x1daaf, 0x1e006, 0x1e018, 0x1e021, 0x1e024, 0x1e02a, 0x1e13d, 0x1e2ef, 0x1e8d6, 0x1e94b, 0x1f3ff, + 0xe0001, 0xe007f, 0xe01ef, +) + +// Mn + Me + Cf + Lm + Sk + Word_Break=MidLetter + Word_Break=MidNumLet + Word_Break=Single_Quote (WordBreakProperty.txt of Unicode Character Database files) +// Declared internal for testing +internal fun Int.isCaseIgnorable(): Boolean { + if (this <= Char.MAX_VALUE.toInt()) { + when (toChar().getCategoryValue()) { + CharCategory.NON_SPACING_MARK.value, + CharCategory.ENCLOSING_MARK.value, + CharCategory.FORMAT.value, + CharCategory.MODIFIER_LETTER.value, + CharCategory.MODIFIER_SYMBOL.value -> return true + } + } + val index = binarySearchRange(caseIgnorableStart, this) + return index >= 0 && this <= caseIgnorableEnd[index] +} + +private fun String.codePointBefore(index: Int): Int { + val low = this[index] + if (low.isLowSurrogate() && index - 1 >= 0) { + val high = this[index - 1] + if (high.isHighSurrogate()) { + return Char.toCodePoint(high, low) + } + } + return low.toInt() +} + +// \p{cased} (\p{case-ignorable})* Sigma !( (\p{case-ignorable})* \p{cased} ) +// The regular-expression operator * is "possessive", consuming as many characters as possible, with no backup. +// This is significant in the case of Final_Sigma, because the sets of case-ignorable and cased characters are not disjoint. +private fun String.isFinalSigmaAt(index: Int): Boolean { + if (this[index] == '\u03A3' && index > 0) { + var i = index - 1 + var codePoint: Int = 0 + while (i >= 0) { + codePoint = codePointBefore(i) + if (codePoint.isCaseIgnorable()) { + i -= codePoint.charCount() + } else { + break + } + } + if (i >= 0 && codePoint.isCased()) { + var j = index + 1 + while (j < length) { + codePoint = codePointAt(j) + if (codePoint.isCaseIgnorable()) { + j += codePoint.charCount() + } else { + break + } + } + if (j >= length || !codePoint.isCased()) { + return true + } + } + } + return false +} + +internal fun String.lowercaseImpl(): String { + var unchangedIndex = 0 + while (unchangedIndex < this.length) { + val codePoint = codePointAt(unchangedIndex) + if (codePoint.lowercaseCodePoint() != codePoint) { // '\u0130' and '\u03A3' have lowercase corresponding mapping in UnicodeData.txt, no need to check them separately + break + } + unchangedIndex += codePoint.charCount() + } + if (unchangedIndex == this.length) { + return this + } + + val sb = StringBuilder(this.length) + sb.appendRange(this, 0, unchangedIndex) + + var index = unchangedIndex + + while (index < this.length) { + if (this[index] == '\u0130') { + sb.append("\u0069\u0307") + index++ + continue + } + if (isFinalSigmaAt(index)) { + sb.append('\u03C2') + index++ + continue + } + val codePoint = codePointAt(index) + val lowercaseCodePoint = codePoint.lowercaseCodePoint() + sb.appendCodePoint(lowercaseCodePoint) + index += codePoint.charCount() + } + + return sb.toString() +} diff --git a/kotlin-native/runtime/src/main/kotlin/generated/_StringUppercase.kt b/kotlin-native/runtime/src/main/kotlin/generated/_StringUppercase.kt new file mode 100644 index 00000000000..b806ccb2588 --- /dev/null +++ b/kotlin-native/runtime/src/main/kotlin/generated/_StringUppercase.kt @@ -0,0 +1,67 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package kotlin.text + +// +// NOTE: THIS FILE IS AUTO-GENERATED by the GenerateUnicodeData.kt +// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib +// + +internal fun String.codePointAt(index: Int): Int { + val high = this[index] + if (high.isHighSurrogate() && index + 1 < this.length) { + val low = this[index + 1] + if (low.isLowSurrogate()) { + return Char.toCodePoint(high, low) + } + } + return high.toInt() +} + +internal fun Int.charCount(): Int = if (this >= Char.MIN_SUPPLEMENTARY_CODE_POINT) 2 else 1 + +internal fun StringBuilder.appendCodePoint(codePoint: Int) { + if (codePoint < Char.MIN_SUPPLEMENTARY_CODE_POINT) { + append(codePoint.toChar()) + } else { + append(Char.MIN_HIGH_SURROGATE + ((codePoint - 0x10000) shr 10)) + append(Char.MIN_LOW_SURROGATE + (codePoint and 0x3ff)) + } +} + +internal fun String.uppercaseImpl(): String { + var unchangedIndex = 0 + while (unchangedIndex < this.length) { + val codePoint = codePointAt(unchangedIndex) + if (this[unchangedIndex].oneToManyUppercase() != null || codePoint.uppercaseCodePoint() != codePoint) { + break + } + unchangedIndex += codePoint.charCount() + } + if (unchangedIndex == this.length) { + return this + } + + val sb = StringBuilder(this.length) + sb.appendRange(this, 0, unchangedIndex) + + var index = unchangedIndex + + while (index < this.length) { + val specialCasing = this[index].oneToManyUppercase() + if (specialCasing != null) { + sb.append(specialCasing) + index++ + continue + } + val codePoint = codePointAt(index) + val uppercaseCodePoint = codePoint.uppercaseCodePoint() + sb.appendCodePoint(uppercaseCodePoint) + index += codePoint.charCount() + } + + return sb.toString() +} diff --git a/kotlin-native/runtime/src/main/kotlin/generated/_UppercaseMappings.kt b/kotlin-native/runtime/src/main/kotlin/generated/_UppercaseMappings.kt new file mode 100644 index 00000000000..dbf18dade46 --- /dev/null +++ b/kotlin-native/runtime/src/main/kotlin/generated/_UppercaseMappings.kt @@ -0,0 +1,72 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package kotlin.text + +// +// NOTE: THIS FILE IS AUTO-GENERATED by the GenerateUnicodeData.kt +// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib +// + +// 189 ranges totally +@SharedImmutable +private val rangeStart = intArrayOf( + 0x0061, 0x00b5, 0x00e0, 0x00f8, 0x00ff, 0x0101, 0x0131, 0x0133, 0x013a, 0x014b, 0x017a, 0x017f, 0x0180, 0x0183, 0x0188, 0x0192, 0x0195, 0x0199, 0x019a, 0x019e, + 0x01a1, 0x01a8, 0x01b0, 0x01b6, 0x01bd, 0x01bf, 0x01c5, 0x01c6, 0x01c8, 0x01c9, 0x01cb, 0x01cc, 0x01ce, 0x01dd, 0x01df, 0x01f2, 0x01f3, 0x01f5, 0x01fb, 0x0223, + 0x023c, 0x023f, 0x0242, 0x0249, 0x0250, 0x0251, 0x0252, 0x0253, 0x0254, 0x0256, 0x0259, 0x025b, 0x025c, 0x0260, 0x0261, 0x0263, 0x0265, 0x0266, 0x0268, 0x0269, + 0x026a, 0x026b, 0x026c, 0x026f, 0x0271, 0x0272, 0x0275, 0x027d, 0x0280, 0x0282, 0x0283, 0x0287, 0x0288, 0x0289, 0x028a, 0x028c, 0x0292, 0x029d, 0x029e, 0x0345, + 0x0371, 0x0377, 0x037b, 0x03ac, 0x03ad, 0x03b1, 0x03c2, 0x03c3, 0x03cc, 0x03cd, 0x03d0, 0x03d1, 0x03d5, 0x03d6, 0x03d7, 0x03d9, 0x03f0, 0x03f1, 0x03f2, 0x03f3, + 0x03f5, 0x03f8, 0x0430, 0x0450, 0x0461, 0x048b, 0x04c2, 0x04cf, 0x04d1, 0x0561, 0x10d0, 0x10fd, 0x13f8, 0x1c80, 0x1c81, 0x1c82, 0x1c83, 0x1c85, 0x1c86, 0x1c87, + 0x1c88, 0x1d79, 0x1d7d, 0x1d8e, 0x1e01, 0x1e9b, 0x1ea1, 0x1f00, 0x1f10, 0x1f20, 0x1f30, 0x1f40, 0x1f51, 0x1f60, 0x1f70, 0x1f72, 0x1f76, 0x1f78, 0x1f7a, 0x1f7c, + 0x1f80, 0x1f90, 0x1fa0, 0x1fb0, 0x1fb3, 0x1fbe, 0x1fc3, 0x1fd0, 0x1fe0, 0x1fe5, 0x1ff3, 0x214e, 0x2170, 0x2184, 0x24d0, 0x2c30, 0x2c61, 0x2c65, 0x2c66, 0x2c68, + 0x2c73, 0x2c81, 0x2cec, 0x2cf3, 0x2d00, 0x2d27, 0xa641, 0xa681, 0xa723, 0xa733, 0xa77a, 0xa77f, 0xa78c, 0xa793, 0xa794, 0xa797, 0xa7b5, 0xa7c3, 0xa7ca, 0xa7f6, + 0xab53, 0xab70, 0xff41, 0x10428, 0x104d8, 0x10cc0, 0x118c0, 0x16e60, 0x1e922, +) + +@SharedImmutable +private val rangeLength = intArrayOf( + -0x1fee6, 0x2e7101, -0x1fee9, -0x1fef9, 0x79101, -0x0dd1, -0xe7eff, -0x0dfb, -0x0df1, -0x0dd3, -0x0dfb, -0x12beff, 0xc3101, -0x0dfd, -0x0bfb, -0x0eff, 0x61101, -0x0eff, 0xa3101, 0x82101, + -0x0dfb, -0x0afa, -0x0bfb, -0x0cfc, -0x0eff, 0x38101, -0x0eff, -0x1eff, -0x0eff, -0x1eff, -0x0eff, -0x1eff, -0x0df1, -0x4eeff, -0x0def, -0x0eff, -0x1eff, -0x0bfb, -0x0ddb, -0x0def, + -0x0eff, 0x2a3f102, -0x0afa, -0x0df9, 0x2a1f101, 0x2a1c101, 0x2a1e101, -0xd1eff, -0xcdeff, -0xccefe, -0xc9eff, -0xcaeff, 0xa54f101, -0xcceff, 0xa54b101, -0xceeff, 0xa528101, 0xa544101, -0xd0eff, -0xd2eff, + 0xa544101, 0x29f7101, 0xa541101, -0xd2eff, 0x29fd101, -0xd4eff, -0xd5eff, 0x29e7101, -0xd9eff, 0xa543101, -0xd9eff, 0xa52a101, -0xd9eff, -0x44eff, -0xd8efe, -0x46eff, -0xdaeff, 0xa515101, 0xa512101, 0x54101, + -0x0dfd, -0x0eff, 0x82103, -0x25eff, -0x24efd, -0x1feef, -0x1eeff, -0x1fef7, -0x3feff, -0x3eefe, -0x3deff, -0x38eff, -0x2eeff, -0x35eff, -0x7eff, -0x0de9, -0x55eff, -0x4feff, 0x7101, -0x73eff, + -0x5feff, -0x0cfc, -0x1fee0, -0x4fef0, -0x0ddf, -0x0dcb, -0x0df3, -0xeeff, -0x0da1, -0x2feda, 0xbc012b, 0xbc0103, -0x7efa, -0x186deff, -0x186ceff, -0x1863eff, -0x1861efe, -0x1862eff, -0x185beff, -0x1824eff, + 0x89c2101, 0x8a04101, 0xee6101, 0x8a38101, -0x0d6b, -0x3aeff, -0x0da1, 0x8108, 0x8106, 0x8108, 0x8108, 0x8106, 0x8207, 0x8108, 0x4a102, 0x56104, 0x64102, 0x80102, 0x70102, 0x7e102, + 0x8108, 0x8108, 0x8108, 0x8102, 0x9101, -0x1c24eff, 0x9101, 0x8102, 0x8102, 0x7101, 0x9101, -0x1beff, -0xfef0, -0x0eff, -0x19ee6, -0x2fed1, -0x0eff, -0x2a2aeff, -0x2a27eff, -0x0dfb, + -0x0cfc, -0x0d9d, -0x0dfd, -0x0eff, -0x1c5feda, -0x1c5f9f9, -0x0dd3, -0x0de5, -0x0df3, -0x0dc3, -0x0dfd, -0x0df7, -0x0afa, -0x0eff, 0x30101, -0x0ded, -0x0df5, -0x0afa, -0x0eff, -0x0eff, + -0x39feff, -0x97cfeb0, -0x1fee6, -0x27ed8, -0x27edc, -0x3fecd, -0x1fee0, -0x1fee0, -0x21ede, +) + +internal fun equalDistanceMapping(code: Int, start: Int, pattern: Int): Int { + val diff = code - start + + val length = pattern and 0xff + if (diff >= length) { + return code + } + + val distance = (pattern shr 8) and 0xf + if (diff % distance != 0) { + return code + } + + val mapping = pattern shr 12 + return code + mapping +} + +internal fun Int.uppercaseCodePoint(): Int { + if (this in 0x61..0x7a) { + return this - 32 + } + if (this < 0x80) { + return this + } + val index = binarySearchRange(rangeStart, this) + return equalDistanceMapping(this, rangeStart[index], rangeLength[index]) +} + +internal fun Char.uppercaseCharImpl(): Char { + return toInt().uppercaseCodePoint().toChar() +} diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/text/Char.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/text/Char.kt index b787df5e3d4..64922bc3aa4 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/text/Char.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/text/Char.kt @@ -149,8 +149,7 @@ public actual fun Char.isTitleCase(): Boolean { /** * Converts this character to upper case using Unicode mapping rules of the invariant locale. */ -@SymbolName("Kotlin_Char_toUpperCase") -external public actual fun Char.toUpperCase(): Char +public actual fun Char.toUpperCase(): Char = uppercaseCharImpl() /** * Converts this character to upper case using Unicode mapping rules of the invariant locale. @@ -163,7 +162,7 @@ external public actual fun Char.toUpperCase(): Char */ @SinceKotlin("1.4") @ExperimentalStdlibApi -public actual fun Char.uppercaseChar(): Char = toUpperCase() +public actual fun Char.uppercaseChar(): Char = uppercaseCharImpl() /** * Converts this character to upper case using Unicode mapping rules of the invariant locale. @@ -177,15 +176,12 @@ public actual fun Char.uppercaseChar(): Char = toUpperCase() */ @SinceKotlin("1.4") @ExperimentalStdlibApi -public actual fun Char.uppercase(): String { - return uppercaseChar().toString() -} +public actual fun Char.uppercase(): String = uppercaseImpl() /** * Converts this character to lower case using Unicode mapping rules of the invariant locale. */ -@SymbolName("Kotlin_Char_toLowerCase") -external public actual fun Char.toLowerCase(): Char +public actual fun Char.toLowerCase(): Char = lowercaseCharImpl() /** * Converts this character to lower case using Unicode mapping rules of the invariant locale. @@ -198,7 +194,7 @@ external public actual fun Char.toLowerCase(): Char */ @SinceKotlin("1.4") @ExperimentalStdlibApi -public actual fun Char.lowercaseChar(): Char = toLowerCase() +public actual fun Char.lowercaseChar(): Char = lowercaseCharImpl() /** * Converts this character to lower case using Unicode mapping rules of the invariant locale. @@ -212,9 +208,7 @@ public actual fun Char.lowercaseChar(): Char = toLowerCase() */ @SinceKotlin("1.4") @ExperimentalStdlibApi -public actual fun Char.lowercase(): String { - return lowercaseChar().toString() -} +public actual fun Char.lowercase(): String = lowercaseImpl() /** * Returns `true` if this character is a Unicode high-surrogate code unit (also known as leading-surrogate code unit). diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/text/Strings.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/text/Strings.kt index 092521f7ca1..c3ac426e23e 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/text/Strings.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/text/Strings.kt @@ -43,19 +43,38 @@ public actual fun String?.equals(other: String?, ignoreCase: Boolean): Boolean { return false return if (!ignoreCase) this.equals(other) + else if (length != other.length) + false else - stringEqualsIgnoreCase(this, other) + unsafeRangeEqualsIgnoreCase(0, other, 0, length) } -@SymbolName("Kotlin_String_equalsIgnoreCase") -internal external fun stringEqualsIgnoreCase(thiz: String, other: String): Boolean - /** * Returns a new string with all occurrences of [oldChar] replaced with [newChar]. */ +public actual fun String.replace(oldChar: Char, newChar: Char, ignoreCase: Boolean): String { + return if (!ignoreCase) + replace(oldChar, newChar) + else + replaceIgnoreCase(oldChar, newChar) +} + @SymbolName("Kotlin_String_replace") -public actual external fun String.replace( - oldChar: Char, newChar: Char, ignoreCase: Boolean): String +private external fun String.replace(oldChar: Char, newChar: Char): String + +@OptIn(ExperimentalStdlibApi::class) +private fun String.replaceIgnoreCase(oldChar: Char, newChar: Char): String { + val charArray = CharArray(length) + val oldCharLower = oldChar.lowercaseChar() + + for (index in 0 until length) { + val thisChar = this[index] + val thisCharLower = thisChar.lowercaseChar() + charArray[index] = if (thisCharLower == oldCharLower) newChar else thisChar + } + + return charArray.concatToString() +} /** * Returns a new string obtained by replacing all occurrences of the [oldValue] substring in this string @@ -147,16 +166,41 @@ public actual fun CharSequence.regionMatches( * @param otherOffset the start offset in the other string of the substring to compare. * @param length the length of the substring to compare. */ -@SymbolName("Kotlin_String_regionMatches") -public external fun String.regionMatches( +public fun String.regionMatches( thisOffset: Int, other: String, otherOffset: Int, length: Int, - ignoreCase: Boolean = false): Boolean + ignoreCase: Boolean = false): Boolean { + if (length < 0 || thisOffset < 0 || otherOffset < 0 + || thisOffset + length > this.length + || otherOffset + length > other.length) { + return false + } + return if (!ignoreCase) + unsafeRangeEquals(thisOffset, other, otherOffset, length) + else + unsafeRangeEqualsIgnoreCase(thisOffset, other, otherOffset, length) +} + +// Bounds must be checked before calling this method +@SymbolName("Kotlin_String_unsafeRangeEquals") +private external fun String.unsafeRangeEquals(thisOffset: Int, other: String, otherOffset: Int, length: Int): Boolean + +// Bounds must be checked before calling this method +@OptIn(ExperimentalStdlibApi::class) +private fun String.unsafeRangeEqualsIgnoreCase(thisOffset: Int, other: String, otherOffset: Int, length: Int): Boolean { + for (index in 0 until length) { + val thisCharLower = this[thisOffset + index].lowercaseChar() + val otherCharLower = other[otherOffset + index].lowercaseChar() + if (thisCharLower != otherCharLower) { + return false + } + } + return true +} /** * Returns a copy of this string converted to upper case using the rules of the default locale. */ -@SymbolName("Kotlin_String_toUpperCase") -public actual external fun String.toUpperCase(): String +public actual fun String.toUpperCase(): String = uppercaseImpl() /** * Returns a copy of this string converted to upper case using Unicode mapping rules of the invariant locale. @@ -168,13 +212,12 @@ public actual external fun String.toUpperCase(): String */ @SinceKotlin("1.4") @ExperimentalStdlibApi -public actual fun String.uppercase(): String = toUpperCase() +public actual fun String.uppercase(): String = uppercaseImpl() /** * Returns a copy of this string converted to lower case using the rules of the default locale. */ -@SymbolName("Kotlin_String_toLowerCase") -public actual external fun String.toLowerCase(): String +public actual fun String.toLowerCase(): String = lowercaseImpl() /** * Returns a copy of this string converted to lower case using Unicode mapping rules of the invariant locale. @@ -186,7 +229,7 @@ public actual external fun String.toLowerCase(): String */ @SinceKotlin("1.4") @ExperimentalStdlibApi -public actual fun String.lowercase(): String = toLowerCase() +public actual fun String.lowercase(): String = lowercaseImpl() /** * Returns a [CharArray] containing characters of this string. @@ -358,8 +401,25 @@ public actual fun String.encodeToByteArray(startIndex: Int, endIndex: Int, throw unsafeStringToUtf8(startIndex, endIndex - startIndex) } -@SymbolName("Kotlin_String_compareToIgnoreCase") -internal external fun compareToIgnoreCase(thiz: String, other: String): Int +@OptIn(ExperimentalStdlibApi::class) +internal fun compareToIgnoreCase(thiz: String, other: String): Int { + val length = minOf(thiz.length, other.length) + + for (index in 0 until length) { + val thisLowerChar = thiz[index].lowercaseChar() + val otherLowerChar = other[index].lowercaseChar() + if (thisLowerChar != otherLowerChar) { + return if (thisLowerChar < otherLowerChar) -1 else 1 + } + } + + return if (thiz.length == other.length) + 0 + else if (thiz.length < other.length) + -1 + else + 1 +} public actual fun String.compareTo(other: String, ignoreCase: Boolean): Int { return if (!ignoreCase) this.compareTo(other)