Desktop: use skija's BreakIterator for characters
Android implementation of BreakIterator for characters differs from OpenJDK implementation and is more correct. skija has an alternative implementation of BreakIterator. This CL switches desktop actual implementation of related functions to this implementation
Change-Id: Iedec397ead4c023ad060ee29f04e918d938681d4
Test: ./gradlew :compose:foundation:foundation:desktopTest
Relnote: N/A
diff --git a/compose/foundation/foundation/api/1.0.0-beta08.txt b/compose/foundation/foundation/api/1.0.0-beta08.txt
index 7187ced..2815f66 100644
--- a/compose/foundation/foundation/api/1.0.0-beta08.txt
+++ b/compose/foundation/foundation/api/1.0.0-beta08.txt
@@ -649,6 +649,9 @@
public final class StringHelpersKt {
}
+ public final class StringHelpers_androidKt {
+ }
+
public final class StringHelpers_jvmKt {
}
diff --git a/compose/foundation/foundation/api/current.txt b/compose/foundation/foundation/api/current.txt
index 7187ced..2815f66 100644
--- a/compose/foundation/foundation/api/current.txt
+++ b/compose/foundation/foundation/api/current.txt
@@ -649,6 +649,9 @@
public final class StringHelpersKt {
}
+ public final class StringHelpers_androidKt {
+ }
+
public final class StringHelpers_jvmKt {
}
diff --git a/compose/foundation/foundation/api/public_plus_experimental_1.0.0-beta08.txt b/compose/foundation/foundation/api/public_plus_experimental_1.0.0-beta08.txt
index 5c3058e..6620135 100644
--- a/compose/foundation/foundation/api/public_plus_experimental_1.0.0-beta08.txt
+++ b/compose/foundation/foundation/api/public_plus_experimental_1.0.0-beta08.txt
@@ -685,6 +685,9 @@
public final class StringHelpersKt {
}
+ public final class StringHelpers_androidKt {
+ }
+
public final class StringHelpers_jvmKt {
}
diff --git a/compose/foundation/foundation/api/public_plus_experimental_current.txt b/compose/foundation/foundation/api/public_plus_experimental_current.txt
index 5c3058e..6620135 100644
--- a/compose/foundation/foundation/api/public_plus_experimental_current.txt
+++ b/compose/foundation/foundation/api/public_plus_experimental_current.txt
@@ -685,6 +685,9 @@
public final class StringHelpersKt {
}
+ public final class StringHelpers_androidKt {
+ }
+
public final class StringHelpers_jvmKt {
}
diff --git a/compose/foundation/foundation/api/restricted_1.0.0-beta08.txt b/compose/foundation/foundation/api/restricted_1.0.0-beta08.txt
index 7187ced..2815f66 100644
--- a/compose/foundation/foundation/api/restricted_1.0.0-beta08.txt
+++ b/compose/foundation/foundation/api/restricted_1.0.0-beta08.txt
@@ -649,6 +649,9 @@
public final class StringHelpersKt {
}
+ public final class StringHelpers_androidKt {
+ }
+
public final class StringHelpers_jvmKt {
}
diff --git a/compose/foundation/foundation/api/restricted_current.txt b/compose/foundation/foundation/api/restricted_current.txt
index 7187ced..2815f66 100644
--- a/compose/foundation/foundation/api/restricted_current.txt
+++ b/compose/foundation/foundation/api/restricted_current.txt
@@ -649,6 +649,9 @@
public final class StringHelpersKt {
}
+ public final class StringHelpers_androidKt {
+ }
+
public final class StringHelpers_jvmKt {
}
diff --git a/compose/foundation/foundation/src/androidMain/kotlin/androidx/compose/foundation/text/StringHelpers.android.kt b/compose/foundation/foundation/src/androidMain/kotlin/androidx/compose/foundation/text/StringHelpers.android.kt
new file mode 100644
index 0000000..7d434a5
--- /dev/null
+++ b/compose/foundation/foundation/src/androidMain/kotlin/androidx/compose/foundation/text/StringHelpers.android.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.compose.foundation.text
+
+import java.text.BreakIterator
+
+internal actual fun String.findPrecedingBreak(index: Int): Int {
+ val it = BreakIterator.getCharacterInstance()
+ it.setText(this)
+ return it.preceding(index)
+}
+
+internal actual fun String.findFollowingBreak(index: Int): Int {
+ val it = BreakIterator.getCharacterInstance()
+ it.setText(this)
+ return it.following(index)
+}
\ No newline at end of file
diff --git a/compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/text/StringHelpers.desktop.kt b/compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/text/StringHelpers.desktop.kt
new file mode 100644
index 0000000..c82e59b
--- /dev/null
+++ b/compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/text/StringHelpers.desktop.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.compose.foundation.text
+
+import org.jetbrains.skija.BreakIterator
+
+internal actual fun String.findPrecedingBreak(index: Int): Int {
+ val it = BreakIterator.makeCharacterInstance()
+ it.setText(this)
+ return it.preceding(index)
+}
+
+internal actual fun String.findFollowingBreak(index: Int): Int {
+ val it = BreakIterator.makeCharacterInstance()
+ it.setText(this)
+ return it.following(index)
+}
\ No newline at end of file
diff --git a/compose/foundation/foundation/src/desktopTest/kotlin/androidx/compose/foundation/text/selection/StringHelpersTest.kt b/compose/foundation/foundation/src/desktopTest/kotlin/androidx/compose/foundation/text/selection/StringHelpersTest.kt
new file mode 100644
index 0000000..650354d
--- /dev/null
+++ b/compose/foundation/foundation/src/desktopTest/kotlin/androidx/compose/foundation/text/selection/StringHelpersTest.kt
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.compose.foundation.text.selection
+
+import androidx.compose.foundation.text.findFollowingBreak
+import androidx.compose.foundation.text.findPrecedingBreak
+import com.google.common.truth.Truth.assertThat
+
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+@RunWith(JUnit4::class)
+class StringHelpersTest {
+ val complexString = "\uD83E\uDDD1\uD83C\uDFFF\u200D\uD83E\uDDB0"
+
+ @Test
+ fun StringHelpersTest_findFollowingBreak() {
+ val result = complexString.findFollowingBreak(0)
+ assertThat(result).isEqualTo(7)
+ }
+
+ @Test
+ fun StringHelpersTest_findPrecedingBreak() {
+ val result = complexString.findPrecedingBreak(7)
+ assertThat(result).isEqualTo(0)
+ }
+}
\ No newline at end of file
diff --git a/compose/foundation/foundation/src/jvmMain/kotlin/androidx/compose/foundation/text/StringHelpers.jvm.kt b/compose/foundation/foundation/src/jvmMain/kotlin/androidx/compose/foundation/text/StringHelpers.jvm.kt
index 83d6794..410519b 100644
--- a/compose/foundation/foundation/src/jvmMain/kotlin/androidx/compose/foundation/text/StringHelpers.jvm.kt
+++ b/compose/foundation/foundation/src/jvmMain/kotlin/androidx/compose/foundation/text/StringHelpers.jvm.kt
@@ -16,19 +16,5 @@
package androidx.compose.foundation.text
-import java.text.BreakIterator
-
internal actual fun StringBuilder.appendCodePointX(codePoint: Int): StringBuilder =
- this.appendCodePoint(codePoint)
-
-internal actual fun String.findPrecedingBreak(index: Int): Int {
- val it = BreakIterator.getCharacterInstance()
- it.setText(this)
- return it.preceding(index)
-}
-
-internal actual fun String.findFollowingBreak(index: Int): Int {
- val it = BreakIterator.getCharacterInstance()
- it.setText(this)
- return it.following(index)
-}
\ No newline at end of file
+ this.appendCodePoint(codePoint)
\ No newline at end of file
diff --git a/compose/ui/ui-text/api/1.0.0-beta08.txt b/compose/ui/ui-text/api/1.0.0-beta08.txt
index ee4cd82..d0abc49 100644
--- a/compose/ui/ui-text/api/1.0.0-beta08.txt
+++ b/compose/ui/ui-text/api/1.0.0-beta08.txt
@@ -77,7 +77,7 @@
public final class JvmAnnotatedString_jvmKt {
}
- public final class JvmCharHelpers_jvmKt {
+ public final class JvmCharHelpers_androidKt {
}
public final class MultiParagraph {
diff --git a/compose/ui/ui-text/api/current.ignore b/compose/ui/ui-text/api/current.ignore
index 9b440ea..5bb1213 100644
--- a/compose/ui/ui-text/api/current.ignore
+++ b/compose/ui/ui-text/api/current.ignore
@@ -15,6 +15,10 @@
Attempted to remove @NonNull annotation from Field ImeOptions.keyboardType
+RemovedClass: androidx.compose.ui.text.JvmCharHelpers_jvmKt:
+ Removed class androidx.compose.ui.text.JvmCharHelpers_jvmKt
+
+
RemovedDeprecatedMethod: androidx.compose.ui.text.input.InputEventCallback#onImeAction(androidx.compose.ui.text.input.ImeAction):
Removed deprecated method androidx.compose.ui.text.input.InputEventCallback.onImeAction(androidx.compose.ui.text.input.ImeAction)
diff --git a/compose/ui/ui-text/api/current.txt b/compose/ui/ui-text/api/current.txt
index ee4cd82..d0abc49 100644
--- a/compose/ui/ui-text/api/current.txt
+++ b/compose/ui/ui-text/api/current.txt
@@ -77,7 +77,7 @@
public final class JvmAnnotatedString_jvmKt {
}
- public final class JvmCharHelpers_jvmKt {
+ public final class JvmCharHelpers_androidKt {
}
public final class MultiParagraph {
diff --git a/compose/ui/ui-text/api/public_plus_experimental_1.0.0-beta08.txt b/compose/ui/ui-text/api/public_plus_experimental_1.0.0-beta08.txt
index 8bc2de0..2f0a4c8 100644
--- a/compose/ui/ui-text/api/public_plus_experimental_1.0.0-beta08.txt
+++ b/compose/ui/ui-text/api/public_plus_experimental_1.0.0-beta08.txt
@@ -86,7 +86,7 @@
public final class JvmAnnotatedString_jvmKt {
}
- public final class JvmCharHelpers_jvmKt {
+ public final class JvmCharHelpers_androidKt {
}
public final class MultiParagraph {
diff --git a/compose/ui/ui-text/api/public_plus_experimental_current.txt b/compose/ui/ui-text/api/public_plus_experimental_current.txt
index 8bc2de0..2f0a4c8 100644
--- a/compose/ui/ui-text/api/public_plus_experimental_current.txt
+++ b/compose/ui/ui-text/api/public_plus_experimental_current.txt
@@ -86,7 +86,7 @@
public final class JvmAnnotatedString_jvmKt {
}
- public final class JvmCharHelpers_jvmKt {
+ public final class JvmCharHelpers_androidKt {
}
public final class MultiParagraph {
diff --git a/compose/ui/ui-text/api/restricted_1.0.0-beta08.txt b/compose/ui/ui-text/api/restricted_1.0.0-beta08.txt
index ee4cd82..d0abc49 100644
--- a/compose/ui/ui-text/api/restricted_1.0.0-beta08.txt
+++ b/compose/ui/ui-text/api/restricted_1.0.0-beta08.txt
@@ -77,7 +77,7 @@
public final class JvmAnnotatedString_jvmKt {
}
- public final class JvmCharHelpers_jvmKt {
+ public final class JvmCharHelpers_androidKt {
}
public final class MultiParagraph {
diff --git a/compose/ui/ui-text/api/restricted_current.ignore b/compose/ui/ui-text/api/restricted_current.ignore
index 9b440ea..5bb1213 100644
--- a/compose/ui/ui-text/api/restricted_current.ignore
+++ b/compose/ui/ui-text/api/restricted_current.ignore
@@ -15,6 +15,10 @@
Attempted to remove @NonNull annotation from Field ImeOptions.keyboardType
+RemovedClass: androidx.compose.ui.text.JvmCharHelpers_jvmKt:
+ Removed class androidx.compose.ui.text.JvmCharHelpers_jvmKt
+
+
RemovedDeprecatedMethod: androidx.compose.ui.text.input.InputEventCallback#onImeAction(androidx.compose.ui.text.input.ImeAction):
Removed deprecated method androidx.compose.ui.text.input.InputEventCallback.onImeAction(androidx.compose.ui.text.input.ImeAction)
diff --git a/compose/ui/ui-text/api/restricted_current.txt b/compose/ui/ui-text/api/restricted_current.txt
index ee4cd82..d0abc49 100644
--- a/compose/ui/ui-text/api/restricted_current.txt
+++ b/compose/ui/ui-text/api/restricted_current.txt
@@ -77,7 +77,7 @@
public final class JvmAnnotatedString_jvmKt {
}
- public final class JvmCharHelpers_jvmKt {
+ public final class JvmCharHelpers_androidKt {
}
public final class MultiParagraph {
diff --git a/compose/ui/ui-text/src/jvmMain/kotlin/androidx/compose/ui/text/JvmCharHelpers.jvm.kt b/compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/JvmCharHelpers.android.kt
similarity index 100%
rename from compose/ui/ui-text/src/jvmMain/kotlin/androidx/compose/ui/text/JvmCharHelpers.jvm.kt
rename to compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/JvmCharHelpers.android.kt
diff --git a/compose/ui/ui-text/src/desktopMain/kotlin/androidx/compose/ui/text/JvmCharHelpers.desktop.kt b/compose/ui/ui-text/src/desktopMain/kotlin/androidx/compose/ui/text/JvmCharHelpers.desktop.kt
new file mode 100644
index 0000000..71dcbc2e
--- /dev/null
+++ b/compose/ui/ui-text/src/desktopMain/kotlin/androidx/compose/ui/text/JvmCharHelpers.desktop.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.compose.ui.text
+
+import org.jetbrains.skija.BreakIterator
+
+internal actual fun String.findPrecedingBreak(index: Int): Int {
+ val it = BreakIterator.makeCharacterInstance()
+ it.setText(this)
+ return it.preceding(index)
+}
+
+internal actual fun String.findFollowingBreak(index: Int): Int {
+ val it = BreakIterator.makeCharacterInstance()
+ it.setText(this)
+ return it.following(index)
+}
\ No newline at end of file