81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 | 
90 |
PunycodeSwift
91 |
92 |
PunycodeSwift
is a pure Swift library to allows you to encode and decode punycoded
strings by using String extension.
93 |
What is Punycode?
94 |
95 |
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)
96 |
Requirements
97 |
98 |
99 | - macOS 10.13 or later
100 | - iOS 12.0 or later
101 | - tvOS 12.0 or later
102 | - watchOS 4.0 or later
103 | - visionOS 1.0 or later
104 | - Swift 5.0 or later
105 |
106 |
Installation
107 |
Swift Package Manager
108 |
109 |
Add the following to your Package.swift
file.
110 |
111 |
112 | macOS, iOS, tvOS, watchOS, visionOS, and Swift 5
113 | dependencies: [
114 | .package(url: "https://github.com/gumob/PunycodeSwift.git", .upToNextMajor(from: "3.0.0"))
115 | ]
116 |
117 | macOS, iOS, tvOS, and Swift 5
118 | dependencies: [
119 | .package(url: "https://github.com/gumob/PunycodeSwift.git", .upToNextMajor(from: "2.1.1"))
120 | ]
121 |
122 |
123 |
Carthage
124 |
125 |
Add the following to your Cartfile
and follow these instructions.
126 |
127 |
128 | macOS, iOS, tvOS, watchOS, visionOS, and Swift 5
129 | github "gumob/PunycodeSwift" ~> 3.0
130 |
131 | macOS, iOS, tvOS, and Swift 5
132 | github "gumob/PunycodeSwift" ~> 2.0
133 |
134 | macOS, iOS, tvOS, and Swift 4
135 | github "gumob/PunycodeSwift" ~> 1.0
136 |
137 |
138 |
CocoaPods
139 |
140 |
To integrate TLDExtract into your project, add the following to your Podfile
.
141 |
142 |
143 | macOS, iOS, tvOS, watchOS, visionOS, and Swift 5.0
144 | pod 'Punycode', '~> 3.0'
145 |
146 | macOS, iOS, tvOS, and Swift 5.0
147 | pod 'Punycode', '~> 2.0'
148 |
149 | macOS, iOS, tvOS, and Swift 4.2
150 | pod 'Punycode', '~> 1.0'
151 |
152 |
153 |
Usage
154 |
155 |
Full documentation is available at https://gumob.github.io/PunycodeSwift/swiftdoc/.
156 |
Encode and decode IDNA:
157 |
import Punycode
158 |
159 | var sushi: String = "寿司"
160 |
161 | sushi = sushi.idnaEncoded!
162 | print(sushi) // xn--sprr0q
163 |
164 | sushi = sushi.idnaDecoded!
165 | print(sushi) // "寿司"
166 |
167 |
Encode and decode Punycode directly:
168 |
import Punycode
169 |
170 | var sushi: String = "寿司"
171 |
172 | sushi = sushi.punycodeEncoded!
173 | print(sushi) // sprr0q
174 |
175 | sushi = sushi.punycodeDecoded!
176 | print(sushi) // "寿司"
177 |
178 |
Copyright
179 |
180 |
Punycode is released under MIT license, which means you can modify it, redistribute it or use it however you like.
181 |
182 |
183 |