Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hylo-lang/swift-punycode
Swift implementation of the Punycode encoding
https://github.com/hylo-lang/swift-punycode
Last synced: 29 days ago
JSON representation
Swift implementation of the Punycode encoding
- Host: GitHub
- URL: https://github.com/hylo-lang/swift-punycode
- Owner: hylo-lang
- Created: 2023-07-10T17:10:55.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-07-10T17:15:43.000Z (over 1 year ago)
- Last Synced: 2024-11-13T08:12:31.390Z (3 months ago)
- Language: Swift
- Size: 4.88 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Swift Punycode
**Swift Punycode** is a Swift implementation of the Punycode encoding, as described in RFC 3492.
Punycode is a simple and efficient transfer encoding syntax designed to uniquely and reversibly transforms a Unicode string into an ASCII string.
ASCII characters in the Unicode string are represented literally, and non-ASCII characters are represented by ASCII characters.
## Usage**Swift Punycode** adds two methods to `Swift.String`.
- `String.punycode(delimiter:encodingDigitWith:)` encodes a string into Punycode.
- `String.init?(punycode:delimiter:decodingDigitWith:)` decoes a Punycode string.For example:
```swift
import Punycodelet greetings = "みなさん、こんにちは!"
let encoded = greetings.punycode()
print(encoded) // Prints "!-63t0lg6d7bk7a1ksic"let decoded = String(punycode: encoded)!
print(decoded) // Prints "みなさん、こんにちは!"
```By default, the separator between the literal part and the digits is `"-"`, as specified in RFC 3492.
Further, digits are encoded as single characters in base 36 (e.g., 5 => "5", 11 => "b").## Installation
To use the **Swift Punycode** in a SwiftPM project, add the following line to the dependencies in your `Package.swift` file:
```swift
.package(url: "https://github.com/val-lang/swift-punycode", from: "1.0.0"),
```Include `"Punycode"` as a dependency for your executable target:
```swift
.target(name: "", dependencies: [
.product(name: "Punycode", package: "swift-punycode"),
]),
```Finally, add `import Punycode` to your source code.