Treat String Like A Pebble With Grapheme At Kotlin π«§
The Easy Way To Use Emoji π
In Android, String is encoded in UTF-8, which means characters like emojis may not count as a single character.
"π".length == 2
"π§βπ§βπ§βπ§".length == 11
Many applications display the character count when users enter text, such as nicknames or posts.
However, due to certain issues, emojis are not counted correctly.
AS-IS | TO-BE |
---|---|
![]() |
![]() |
To address this inconvenience, Pebble Is Coming!
Add the codes below to your root build.gradle
file (not your module-level build.gradle file):
allprojects {
repositories {
mavenCentral()
}
}
And, Add the dependency below to your module build.gradle
file:
dependencies {
implementation("io.github.chattymin:pebble:0.1.0")
}
"π".graphemeLength == 1
"π".isEmoji() == true
"Hello Pebble π Welcome!".containsEmoji() == true
"Helloπ This is Pebble!π«§ Welcπ§βπ§βπ§βπ§ome :)".extractEmojis() == ["π", "π«§", "π§βπ§βπ§βπ§"]
"Helloπ This is Pebble!π«§ Welcπ§βπ§βπ§βπ§ome :)".filterEmojis() == "Hello This is Pebble! Welcome :)"
In addition to this, various types of extension functions are also available.
The goal is to cover all ranges officially provided by Kotlin.
You can explore and use various extension functions within the Pebble
module :)
Contributions are always welcome!
Feel free to make an issue everything that you want to contribute!
Welcome New Extensions, Performance Improvements, and all ways of working with stringsβjust like Pebble!
Copyright 2025 chattymin (Dongmin Park)
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.