Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

124 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

swift-ascii

Development Status

ASCII validation, case conversion, line-ending normalization, and decimal serialization for Swift strings, characters, and integers, built on the INCITS 4-1986 (US-ASCII) specification.


Key Features

  • Validated String constructionString(ascii:) builds a string from bytes or ASCII.Code values and returns nil when any byte falls outside the 7-bit range (0x00–0x7F), instead of decoding it to a replacement character.
  • ASCII-only case conversionstring.ascii.uppercased() / .lowercased() fold the letters AZ / az and leave every non-ASCII scalar untouched.
  • Line-ending normalizationnormalized(to:) rewrites mixed LF, CR, and CRLF endings to one consistent style.
  • 7-bit ASCII predicatestring.ascii.isAllASCII reports whether a string contains only US-ASCII characters.
  • Decimal integer serializationInt, Int64, UInt, and UInt64 serialize to their ASCII decimal byte representation through Binary.Serializable.
  • INCITS 4-1986 grounding — classification, case, and format-effector behavior follow the US-ASCII specification.

Quick Start

import ASCII

// Reject non-ASCII on construction instead of decoding it to replacement characters.
let greeting = String(ascii: [104, 101, 108, 108, 111])  // "hello"
let rejected = String(ascii: [0xFF])                     // nil — 0xFF is not 7-bit ASCII

// Test whether a string is pure 7-bit ASCII.
let pure = "hello".ascii.isAllASCII   // true
let mixed = "café".ascii.isAllASCII   // false

// Fold only ASCII letters; non-ASCII scalars pass through unchanged.
let shout = "HELLO🌍".ascii.lowercased()  // "hello🌍"

// Normalize mixed CR / LF / CRLF line endings to a single style.
let body = "line1\nline2\r\nline3".normalized(to: .crlf)
// "line1\r\nline2\r\nline3"

Installation

dependencies: [
    .package(url: "https://github.com/swift-foundations/swift-ascii.git", branch: "main")
]
.target(
    name: "YourTarget",
    dependencies: [
        .product(name: "ASCII", package: "swift-ascii")
    ]
)

Requires Swift 6.3.1. The ASCII product supports Windows as a host platform; the repository's universal CI includes its required Windows build-and-test leg. Package.swift declares minimum deployment versions for Apple platforms: macOS 26, iOS 26, tvOS 26, watchOS 26, and visionOS 26.


Community

Discussion thread will be created at first public release.

License

Apache 2.0. See LICENSE.

About

ASCII validation, case conversion, and line-ending normalization for strings, characters, and integers in Swift.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Contributors

Languages