
Determines displayed column width of characters and strings per Unicode Annex #11, handling ambiguous widths, CJK behaviour, grapheme clusters, and many ligatures for accurate terminal layout.
This is a Kotlin Multiplatform line-by-line transliteration port of unicode-rs/unicode-width.
Original Project: This port is based on unicode-rs/unicode-width. All design credit and project intent belong to the upstream authors; this repository is a faithful port to Kotlin Multiplatform with no behavioural changes intended.
This is an in-progress port. The goal is feature parity with the upstream Rust crate while providing a native Kotlin Multiplatform API. Every Kotlin file carries a // port-lint: source <path> header naming its upstream Rust counterpart so the AST-distance tool can track provenance.
The text below is reproduced and lightly edited from
https://github.com/unicode-rs/unicode-width. It is the upstream project's own description and remains under the upstream authors' authorship; links have been rewritten to absolute upstream URLs so they continue to resolve from this repository.
Determine displayed width of char and str types according to Unicode Standard Annex #11
and other portions of the Unicode standard.
This crate is #![no_std].
use unicode_width::UnicodeWidthStr;
fn main() {
let teststr = "Hello, world!";
let width = teststr.width();
println!("{}", teststr);
println!("The above string is {} columns wide.", width);
let width = teststr.width_cjk();
println!("The above string is {} columns wide (CJK).", width);
}NOTE: The computed width values may not match the actual rendered column width. For example, many Brahmic scripts like Devanagari have complex rendering rules which this crate does not currently handle (and will never fully handle, because the exact rendering depends on the font):
extern crate unicode_width;
use unicode_width::UnicodeWidthStr;
fn main() {
assert_eq!("क".width(), 1); // Devanagari letter Ka
assert_eq!("ष".width(), 1); // Devanagari letter Ssa
assert_eq!("क्ष".width(), 2); // Ka + Virama + Ssa
}Additionally, defective combining character sequences and nonstandard Korean jamo sequences may be rendered with a different width than what this crate says. (This is not an exhaustive list.) For a list of what this crate does handle, see docs.rs.
You can use this package in your project by adding the following
to your Cargo.toml:
[dependencies]
unicode-width = "0.2"\n as width 1 (#60)Modifier_Letters as narrow (#63)Grapheme_Cluster_Break=Prepend (#62)Note: If you are using unicode-width for linebreaking, the change treating \n as width 1 may cause behavior changes. It is recommended that in such cases you feed already-line segmented text to unicode-width. In other words, please apply higher level control character based line breaking protocols before feeding text to unicode-width. Relying on any character producing a stable width in this crate is likely the sign of a bug.
dependencies {
implementation("io.github.kotlinmania:unicode-width-kotlin:0.1.1")
}./gradlew build
./gradlew testSee AGENTS.md and CLAUDE.md for translator discipline, port-lint header convention, and Rust → Kotlin idiom mapping.
This Kotlin port is distributed under the same MIT license as the upstream unicode-rs/unicode-width. See LICENSE (and any sibling LICENSE-* / NOTICE files mirrored from upstream) for the full text.
Original work copyrighted by the unicode-width authors.
Kotlin port: Copyright (c) 2026 Sydney Renee and The Solace Project.
Thanks to the unicode-rs/unicode-width maintainers and contributors for the original Rust implementation. This port reproduces their work in Kotlin Multiplatform; bug reports about upstream design or behavior should go to the upstream repository.
This is a Kotlin Multiplatform line-by-line transliteration port of unicode-rs/unicode-width.
Original Project: This port is based on unicode-rs/unicode-width. All design credit and project intent belong to the upstream authors; this repository is a faithful port to Kotlin Multiplatform with no behavioural changes intended.
This is an in-progress port. The goal is feature parity with the upstream Rust crate while providing a native Kotlin Multiplatform API. Every Kotlin file carries a // port-lint: source <path> header naming its upstream Rust counterpart so the AST-distance tool can track provenance.
The text below is reproduced and lightly edited from
https://github.com/unicode-rs/unicode-width. It is the upstream project's own description and remains under the upstream authors' authorship; links have been rewritten to absolute upstream URLs so they continue to resolve from this repository.
Determine displayed width of char and str types according to Unicode Standard Annex #11
and other portions of the Unicode standard.
This crate is #![no_std].
use unicode_width::UnicodeWidthStr;
fn main() {
let teststr = "Hello, world!";
let width = teststr.width();
println!("{}", teststr);
println!("The above string is {} columns wide.", width);
let width = teststr.width_cjk();
println!("The above string is {} columns wide (CJK).", width);
}NOTE: The computed width values may not match the actual rendered column width. For example, many Brahmic scripts like Devanagari have complex rendering rules which this crate does not currently handle (and will never fully handle, because the exact rendering depends on the font):
extern crate unicode_width;
use unicode_width::UnicodeWidthStr;
fn main() {
assert_eq!("क".width(), 1); // Devanagari letter Ka
assert_eq!("ष".width(), 1); // Devanagari letter Ssa
assert_eq!("क्ष".width(), 2); // Ka + Virama + Ssa
}Additionally, defective combining character sequences and nonstandard Korean jamo sequences may be rendered with a different width than what this crate says. (This is not an exhaustive list.) For a list of what this crate does handle, see docs.rs.
You can use this package in your project by adding the following
to your Cargo.toml:
[dependencies]
unicode-width = "0.2"\n as width 1 (#60)Modifier_Letters as narrow (#63)Grapheme_Cluster_Break=Prepend (#62)Note: If you are using unicode-width for linebreaking, the change treating \n as width 1 may cause behavior changes. It is recommended that in such cases you feed already-line segmented text to unicode-width. In other words, please apply higher level control character based line breaking protocols before feeding text to unicode-width. Relying on any character producing a stable width in this crate is likely the sign of a bug.
dependencies {
implementation("io.github.kotlinmania:unicode-width-kotlin:0.1.1")
}./gradlew build
./gradlew testSee AGENTS.md and CLAUDE.md for translator discipline, port-lint header convention, and Rust → Kotlin idiom mapping.
This Kotlin port is distributed under the same MIT license as the upstream unicode-rs/unicode-width. See LICENSE (and any sibling LICENSE-* / NOTICE files mirrored from upstream) for the full text.
Original work copyrighted by the unicode-width authors.
Kotlin port: Copyright (c) 2026 Sydney Renee and The Solace Project.
Thanks to the unicode-rs/unicode-width maintainers and contributors for the original Rust implementation. This port reproduces their work in Kotlin Multiplatform; bug reports about upstream design or behavior should go to the upstream repository.