swift-displaywidth

0.0.3

wcwidth implementation with the latest Unicode spec
ainame/swift-displaywidth

What's New

swift-displaywidth 0.0.3

2025-09-14T23:47:06Z

The project was renamed from swift-wcwidth to swift-displaywidth.
It seems common to name a project like this as wcwidth but it is confusion that there's POSIX wcwidth(3) already.
It's more obvious since Swift has C interoperability by default.

swift-displaywidth

Swift Version Swift Package Manager License GitHub Release Build Status

Small, testable display width implementation in Swift. Provides simple functions to measure display width of Unicode scalars, characters, and strings with an option to treat East Asian "Ambiguous" width as full-width.

Usage

Add to your Package.swift:

dependencies: [
    .package(url: "https://github.com/ainame/swift-displaywidth", from: "0.0.2")
]

Then:

import DisplayWidth

// call as function
let displayWidth = DisplayWidth()
displayWidth("A")        // 1
displayWidth("")       // 2
displayWidth("👩‍💻")       // 2
displayWidth("e\u{0301}") // 1 (e + combining acute)

// If your environment treat ambiguous chars as full-width,
// you can set this option.
let displayWidth = DisplayWidth(treatAmbiguousAsFullWidth: true)

Links

Description

  • Swift Tools 6.1.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Sep 21 2025 08:09:27 GMT-0900 (Hawaii-Aleutian Daylight Time)