GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - futamura/PunycodeSwift: PunycodeSwift is a pure Swift library to allows you to encode and decode punycoded strings

BranchesTags
Open more actions menu

Latest commit

 

History

376 Commits
376 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
Punycode.xcodeproj
Punycode.xcodeproj
 
 
Sources
Sources
 
 
Tests
Tests
 
 
fastlane
fastlane
 
 
scripts
scripts
 
 
.gitignore
.gitignore
 
 
.mise.toml
.mise.toml
 
 
.spi.yml
.spi.yml
 
 
.swift-format
.swift-format
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CLAUDE.md
CLAUDE.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
FUNDING.yml
FUNDING.yml
 
 
Gemfile
Gemfile
 
 
Gemfile.lock
Gemfile.lock
 
 
LICENSE
LICENSE
 
 
Package.swift
Package.swift
 
 
README.md
README.md
 
 
SECURITY.md
SECURITY.md
 
 
codecov.yml
codecov.yml
 
 
run.sh
run.sh
 
 

Repository files navigation

Swift Package Manager compatible Carthage compatible Swift Package Index Platforms Build codecov License

PunycodeSwift

PunycodeSwift is a pure Swift library to allows you to encode and decode punycoded strings by using String extension.

What is Punycode?

Punycode is a representation of Unicode with the limited ASCII character subset used for Internet host names. Using Punycode, host names containing Unicode characters are transcoded to a subset of ASCII consisting of letters, digits, and hyphen, which is called the Letter-Digit-Hyphen (LDH) subset. For example, München (German name for Munich) is encoded as Mnchen-3ya. (Wikipedia)

Requirements

  • macOS 10.13 or later
  • iOS 12.0 or later
  • tvOS 12.0 or later
  • watchOS 4.0 or later
  • visionOS 1.0 or later
  • Linux
  • Swift 5.9 or later (Xcode 15 or later) for Swift Package Manager

Installation

Swift Package Manager is the recommended way to install PunycodeSwift.

Important

CocoaPods distribution ended with 4.0.0: versions 4.0.0 and later are available via Swift Package Manager (and Carthage on a best-effort basis) only. If you are using CocoaPods, please migrate to Swift Package Manager.

Swift Package Manager

Add the following to your Package.swift file.

  • macOS, iOS, tvOS, watchOS, visionOS, Linux, and Swift 5.9 (Xcode 15) or later

    dependencies: [
        .package(url: "https://github.com/futamura/PunycodeSwift.git", .upToNextMajor(from: "4.0.0"))
    ]
  • macOS, iOS, tvOS, watchOS, visionOS, and Swift 5

    dependencies: [
        .package(url: "https://github.com/futamura/PunycodeSwift.git", .upToNextMajor(from: "3.0.0"))
    ]
  • macOS, iOS, tvOS, and Swift 5

    dependencies: [
        .package(url: "https://github.com/futamura/PunycodeSwift.git", .upToNextMajor(from: "2.1.1"))
    ]

Carthage

Note

Carthage itself is in maintenance mode. Carthage compatibility is kept on a best-effort basis and is no longer verified by CI.

Add the following to your Cartfile and follow these instructions.

  • macOS, iOS, tvOS, watchOS, visionOS, and Swift 5.9 or later

    github "futamura/PunycodeSwift" ~> 4.0
    
  • macOS, iOS, tvOS, watchOS, visionOS, and Swift 5

    github "futamura/PunycodeSwift" ~> 3.0
    
  • macOS, iOS, tvOS, and Swift 5

    github "futamura/PunycodeSwift" ~> 2.0
    
  • macOS, iOS, tvOS, and Swift 4

    github "futamura/PunycodeSwift" ~> 1.0
    

CocoaPods

Warning

CocoaPods distribution has ended: 3.0.0 is the last version published as a pod. Existing versions remain installable until the trunk archive disappears, but no new versions will be published. Please migrate to Swift Package Manager.

Existing installations reference the pod as follows.

  • macOS, iOS, tvOS, watchOS, visionOS, and Swift 5.0

    pod 'Punycode', '~> 3.0'
  • macOS, iOS, tvOS, and Swift 5.0

    pod 'Punycode', '~> 2.0'
  • macOS, iOS, tvOS, and Swift 4.2

    pod 'Punycode', '~> 1.0'

Usage

Full documentation is available at https://futamura.github.io/PunycodeSwift/documentation/punycode/.

Encode and decode IDNA:

import Punycode

var sushi: String = "寿司"

sushi = sushi.idnaEncoded!
print(sushi)  // xn--sprr0q

sushi = sushi.idnaDecoded!
print(sushi)  // "寿司"

Encode and decode the host of a URL:

idnaEncoded expects a bare hostname. For a full URL, use idnaEncodedURL / idnaDecodedURL, which transform only the host and leave the scheme, userinfo, port, path, query, and fragment unchanged.

import Punycode

var url: String = "http://www.ラーメン.寿司.co.jp/メニュー"

url = url.idnaEncodedURL!
print(url)  // http://www.xn--4dkp5a8a.xn--sprr0q.co.jp/メニュー

url = url.idnaDecodedURL!
print(url)  // http://www.ラーメン.寿司.co.jp/メニュー

Encode and decode Punycode directly:

punycodeEncoded / punycodeDecoded are the raw RFC 3492 transformation of a single label: no xn-- prefix is added and dots are not treated as label separators.

import Punycode

var sushi: String = "寿司"

sushi = sushi.punycodeEncoded!
print(sushi)  // sprr0q

sushi = sushi.punycodeDecoded!
print(sushi)  // "寿司"

Copyright

Punycode is released under MIT license, which means you can modify it, redistribute it or use it however you like.

About

PunycodeSwift is a pure Swift library to allows you to encode and decode punycoded strings

futamura.github.io/PunycodeSwift/documentation/punycode/

Topics

carthageidnaiosmacospunycodeswift-package-managerswift5tvosvisionoswatchos

Resources

Readme
MIT license

Contributing

Contributing

Security policy

Security policy
Activity

Stars

32 stars

Watchers

2 watching

Forks

12 forks
Report repository

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.