Skip to content

Commit 6612327

Browse files
authored
Merge pull request #13 from JakeWharton/jw.stdlib.2023-01-23
Remove functions provided by the Kotlin stdlib
2 parents adbc5d9 + a7262f8 commit 6612327

File tree

6 files changed

+16
-126
lines changed

6 files changed

+16
-126
lines changed

src/commonImplementation/kotlin/CodePoints.kt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,6 @@ actual object CodePoints {
1919
return CommonCodePoints.charCount(codePoint)
2020
}
2121

22-
actual inline fun isSurrogate(char: Char): Boolean {
23-
return CommonCodePoints.isSurrogate(char)
24-
}
25-
26-
actual inline fun isHighSurrogate(char: Char): Boolean {
27-
return CommonCodePoints.isHighSurrogate(char)
28-
}
29-
30-
actual inline fun isLowSurrogate(char: Char): Boolean {
31-
return CommonCodePoints.isLowSurrogate(char)
32-
}
33-
3422
actual inline fun isSurrogatePair(highSurrogate: Char, lowSurrogate: Char): Boolean {
3523
return CommonCodePoints.isSurrogatePair(highSurrogate, lowSurrogate)
3624
}

src/commonImplementation/kotlin/CommonCodePoints.kt

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ object CommonCodePoints {
55
private const val MAX_CODE_POINT = 0x10FFFF
66

77
private const val MIN_HIGH_SURROGATE = 0xD800
8-
private const val MAX_HIGH_SURROGATE = 0xDBFF
98
private const val MIN_LOW_SURROGATE = 0xDC00
10-
private const val MAX_LOW_SURROGATE = 0xDFFF
119

1210
private const val SURROGATE_DECODE_OFFSET =
1311
MIN_SUPPLEMENTARY_CODE_POINT - (MIN_HIGH_SURROGATE shl 10) - MIN_LOW_SURROGATE
@@ -31,20 +29,8 @@ object CommonCodePoints {
3129
return if (codePoint < MIN_SUPPLEMENTARY_CODE_POINT) 1 else 2
3230
}
3331

34-
fun isSurrogate(char: Char): Boolean {
35-
return char.code in MIN_HIGH_SURROGATE..MAX_LOW_SURROGATE
36-
}
37-
38-
fun isHighSurrogate(char: Char): Boolean {
39-
return char.code in MIN_HIGH_SURROGATE..MAX_HIGH_SURROGATE
40-
}
41-
42-
fun isLowSurrogate(char: Char): Boolean {
43-
return char.code in MIN_LOW_SURROGATE..MAX_LOW_SURROGATE
44-
}
45-
4632
fun isSurrogatePair(highSurrogate: Char, lowSurrogate: Char): Boolean {
47-
return isHighSurrogate(highSurrogate) && isLowSurrogate(lowSurrogate)
33+
return highSurrogate.isHighSurrogate() && lowSurrogate.isLowSurrogate()
4834
}
4935

5036
fun highSurrogate(codePoint: Int): Char {

src/commonImplementation/kotlin/CommonStringFunctions.kt

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package de.cketti.codepoints
22

3-
import de.cketti.codepoints.CommonCodePoints.isHighSurrogate
4-
import de.cketti.codepoints.CommonCodePoints.isLowSurrogate
53
import de.cketti.codepoints.CommonCodePoints.toCodePoint
64

75
object CommonStringFunctions {
86
fun codePointAt(text: String, index: Int): Int {
97
if (index !in text.indices) throw IndexOutOfBoundsException()
108

119
val firstChar = text[index]
12-
if (isHighSurrogate(firstChar) && index + 1 < text.length) {
10+
if (firstChar.isHighSurrogate() && index + 1 < text.length) {
1311
val nextChar = text[index + 1]
14-
if (isLowSurrogate(nextChar)) {
12+
if (nextChar.isLowSurrogate()) {
1513
return toCodePoint(firstChar, nextChar)
1614
}
1715
}
@@ -24,9 +22,9 @@ object CommonStringFunctions {
2422
if (startIndex !in text.indices) throw IndexOutOfBoundsException()
2523

2624
val firstChar = text[startIndex]
27-
if (isLowSurrogate(firstChar) && startIndex - 1 >= 0) {
25+
if (firstChar.isLowSurrogate() && startIndex - 1 >= 0) {
2826
val previousChar = text[startIndex - 1]
29-
if (isHighSurrogate(previousChar)) {
27+
if (previousChar.isHighSurrogate()) {
3028
return toCodePoint(previousChar, firstChar)
3129
}
3230
}
@@ -42,9 +40,9 @@ object CommonStringFunctions {
4240
do {
4341
val firstChar = text[index]
4442
index++
45-
if (isHighSurrogate(firstChar) && index < endIndex) {
43+
if (firstChar.isHighSurrogate() && index < endIndex) {
4644
val nextChar = text[index]
47-
if (isLowSurrogate(nextChar)) {
45+
if (nextChar.isLowSurrogate()) {
4846
index++
4947
}
5048
}
@@ -65,9 +63,9 @@ object CommonStringFunctions {
6563
if (currentIndex > text.lastIndex) throw IndexOutOfBoundsException()
6664
val firstChar = text[currentIndex]
6765
currentIndex++
68-
if (isHighSurrogate(firstChar) && currentIndex <= text.lastIndex) {
66+
if (firstChar.isHighSurrogate() && currentIndex <= text.lastIndex) {
6967
val nextChar = text[currentIndex]
70-
if (isLowSurrogate(nextChar)) {
68+
if (nextChar.isLowSurrogate()) {
7169
currentIndex++
7270
}
7371
}
@@ -80,9 +78,9 @@ object CommonStringFunctions {
8078
if (currentIndex < 0) throw IndexOutOfBoundsException()
8179
val firstChar = text[currentIndex]
8280
currentIndex--
83-
if (isLowSurrogate(firstChar) && currentIndex >= 0) {
81+
if (firstChar.isLowSurrogate() && currentIndex >= 0) {
8482
val previousChar = text[currentIndex]
85-
if (isHighSurrogate(previousChar)) {
83+
if (previousChar.isHighSurrogate()) {
8684
currentIndex--
8785
}
8886
}

src/commonMain/kotlin/CodePoints.kt

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,41 +31,12 @@ expect object CodePoints {
3131
*/
3232
fun charCount(codePoint: Int): Int
3333

34-
/**
35-
* Determines if the given `Char` value is a Unicode surrogate code unit.
36-
*
37-
* Such values do not represent characters by themselves, but are used in the representation of supplementary
38-
* characters in the UTF-16 encoding.
39-
*
40-
* A `Char` value is a surrogate code unit if and only if it is either a [low surrogate][isLowSurrogate] code unit
41-
* or a [high surrogate][isHighSurrogate] code unit.
42-
*/
43-
fun isSurrogate(char: Char): Boolean
44-
45-
/**
46-
* Determines if the given `Char` value is a Unicode high-surrogate code unit (also known as leading-surrogate
47-
* code unit).
48-
*
49-
* Such values do not represent characters by themselves, but are used in the representation of
50-
* [supplementary characters][isSupplementaryCodePoint] in the UTF-16 encoding.
51-
*/
52-
fun isHighSurrogate(char: Char): Boolean
53-
54-
/**
55-
* Determines if the given `Char` value is a Unicode low-surrogate code unit (also known as trailing-surrogate
56-
* code unit).
57-
*
58-
* Such values do not represent characters by themselves, but are used in the representation of
59-
* [supplementary characters][isSupplementaryCodePoint] in the UTF-16 encoding.
60-
*/
61-
fun isLowSurrogate(char: Char): Boolean
62-
6334
/**
6435
* Determines whether the specified pair of `Char` values is a valid Unicode surrogate pair.
6536
*
6637
* This method is equivalent to the expression:
6738
* ```kotlin
68-
* isHighSurrogate(highSurrogate) && isLowSurrogate(lowSurrogate)
39+
* highSurrogate.isHighSurrogate() && lowSurrogate.isLowSurrogate()
6940
* ```
7041
*/
7142
fun isSurrogatePair(highSurrogate: Char, lowSurrogate: Char): Boolean
@@ -77,8 +48,8 @@ expect object CodePoints {
7748
* If the specified character is not a supplementary character, an unspecified `Char` is returned.
7849
*
7950
* If [`isSupplementaryCodePoint(x)`][isSupplementaryCodePoint] is `true`, then
80-
* [isHighSurrogate]`(highSurrogate(x))` and
81-
* [toCodePoint][toCodePoint]`(highSurrogate(x), `[`lowSurrogate(x)`][lowSurrogate]`) == x` are also always `true`.
51+
* [isHighSurrogate]`(x.highSurrogate())` and
52+
* [toCodePoint][toCodePoint]`(x.highSurrogate(), `[`x.lowSurrogate()`][lowSurrogate]`) == x` are also always `true`.
8253
*/
8354
fun highSurrogate(codePoint: Int): Char
8455

@@ -89,8 +60,8 @@ expect object CodePoints {
8960
* If the specified character is not a supplementary character, an unspecified char is returned.
9061
*
9162
* If [`isSupplementaryCodePoint(x)`][isSupplementaryCodePoint] is `true`, then
92-
* [isLowSurrogate]`(lowSurrogate(x))` and
93-
* [toCodePoint][toCodePoint]`(`[`highSurrogate(x)`][highSurrogate], `lowSurrogate(x)) == x` are also always `true`.
63+
* [isLowSurrogate]`(x.lowSurrogate())` and
64+
* [toCodePoint][toCodePoint]`(`[`x.highSurrogate()`][highSurrogate], `x.lowSurrogate()) == x` are also always `true`.
9465
*/
9566
fun lowSurrogate(codePoint: Int): Char
9667

src/commonTest/kotlin/CodePointsTest.kt

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -52,47 +52,6 @@ class CodePointsTest {
5252
assertEquals(2, CodePoints.charCount(0x10FFFF))
5353
}
5454

55-
@Test
56-
fun isSurrogate() {
57-
assertTrue(CodePoints.isSurrogate('\uD800'))
58-
assertTrue(CodePoints.isSurrogate('\uDBFF'))
59-
assertTrue(CodePoints.isSurrogate('\uDC00'))
60-
assertTrue(CodePoints.isSurrogate('\uDFFF'))
61-
62-
assertFalse(CodePoints.isSurrogate('a'))
63-
assertFalse(CodePoints.isSurrogate(0xFFFF.toChar()))
64-
assertFalse(CodePoints.isSurrogate('\uD7FF'))
65-
assertFalse(CodePoints.isSurrogate('\uE000'))
66-
}
67-
68-
@Test
69-
fun isHighSurrogate() {
70-
assertTrue(CodePoints.isHighSurrogate('\uD800'))
71-
assertTrue(CodePoints.isHighSurrogate('\uDBFF'))
72-
73-
assertFalse(CodePoints.isHighSurrogate('\uDC00'))
74-
assertFalse(CodePoints.isHighSurrogate('\uDFFF'))
75-
76-
assertFalse(CodePoints.isHighSurrogate('a'))
77-
assertFalse(CodePoints.isHighSurrogate(0xFFFF.toChar()))
78-
assertFalse(CodePoints.isHighSurrogate('\uD7FF'))
79-
assertFalse(CodePoints.isHighSurrogate('\uE000'))
80-
}
81-
82-
@Test
83-
fun isLowSurrogate() {
84-
assertTrue(CodePoints.isLowSurrogate('\uDC00'))
85-
assertTrue(CodePoints.isLowSurrogate('\uDFFF'))
86-
87-
assertFalse(CodePoints.isLowSurrogate('\uD800'))
88-
assertFalse(CodePoints.isLowSurrogate('\uDBFF'))
89-
90-
assertFalse(CodePoints.isLowSurrogate('a'))
91-
assertFalse(CodePoints.isLowSurrogate(0xFFFF.toChar()))
92-
assertFalse(CodePoints.isLowSurrogate('\uD7FF'))
93-
assertFalse(CodePoints.isLowSurrogate('\uE000'))
94-
}
95-
9655
@Test
9756
fun isSurrogatePair() {
9857
assertTrue(CodePoints.isSurrogatePair('\uD800', '\uDC00'))

src/jvmMain/kotlin/CodePoints.kt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,6 @@ actual object CodePoints {
1919
return Character.charCount(codePoint)
2020
}
2121

22-
actual inline fun isSurrogate(char: Char): Boolean {
23-
return Character.isSurrogate(char)
24-
}
25-
26-
actual inline fun isHighSurrogate(char: Char): Boolean {
27-
return Character.isHighSurrogate(char)
28-
}
29-
30-
actual inline fun isLowSurrogate(char: Char): Boolean {
31-
return Character.isLowSurrogate(char)
32-
}
33-
3422
actual inline fun isSurrogatePair(highSurrogate: Char, lowSurrogate: Char): Boolean {
3523
return Character.isSurrogatePair(highSurrogate, lowSurrogate)
3624
}

0 commit comments

Comments
 (0)