swift-displaywidth

0.0.4

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

What's New

0.0.4

2026-03-26T23:19:36Z

0.0.4 lowers the supported Swift version to 6.0.

Changes in this release:

  • Lower Swift tools/version support from 6.2 to 6.0
  • Align declared platform minimums with the Locale.Language API used by LocaleAwareDisplayWidth
  • Update project documentation to match the new support policy

swift-displaywidth

Swift Version Swift Package Manager License GitHub Release Build Status

A portable/cross-platform implementation of wcwidth(3) with up-to-date Unicode spec. This project has own Unicode data tables generated from following files.

Why use this?

Instead of this library, there's wcwidth imported with import Darwin, import Musl, or import Glibc.

If that meets your requirements, you should just use it. However, this project has following superior points.

  • Portable/Cross-platform implementation that doesn't require a C library nor even Foundation
  • Up-to-date Unicode spec
  • Better support of Unicode grapheme clusters
  • Swift-friendly API

Usage

Add to your Package.swift:

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

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.0.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Mar 29 2026 11:08:06 GMT-0900 (Hawaii-Aleutian Daylight Time)