Swiftpack.co - Wevah/IDNA-Cocoa as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Wevah.
Wevah/IDNA-Cocoa 1.3.1
Simple interface for IDNA on String and NSString
⭐️ 59
🕓 2 years ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/Wevah/IDNA-Cocoa.git", from: "1.3.1")

IDNA Cocoa

v2.0b4 (2021) by Nate Weaver (Wevah)
https://derailer.org/
https://github.com/Wevah/Punycode-Cocoa

Swift

An IDNA String extension and NSString overlay, based on UTS #46. Currently implents the full conversion table and joiner validation.

Use this to convert internationalized domain names (IDN) between Unicode and ASCII.

To use in your own projects, this repository can be imported as a Swift package.

Alternatively, the files can be manually included: Everything in Sources/IDNA:

  • UTS46.swift
  • UTS46+Loading.swift
  • Data+Extensions.swift
  • Scanner+Extensions.swift
  • String+Punycode.swift

If your project needs to call from Objective-C make sure to include NSString+IDNA.swift for the NSString overlays.

(UTS46+Conversion.swift is for importing text files containing UTS #46 mappings and exporting to the binary format used by UTS46+Loading.swift, and isn't necessary if you just want to use the encoding/decoding routines.)

Note that these API currently don't do homograph detection.

Interface

String/NSString

Swift:
var idnaEncoded: String? { get }
Objective-C:
@property (readonly, copy, nullable) NSString *IDNAEncodedString;

If self contains non-ASCII, encodes the string's domain components as Punycode and prepends xn-- to the transformed components.


Swift:
var idnaDecoded: String? { get }
Objective-C:
@property (readonly, copy, nullable) NSString *IDNADecodedString;

Decodes a string returned by idnaEncoded/-IDNAEncodedString.


Swift:
var encodedURLString: String? { get }
var decodedURLString: String? { get }
Objective-C:
@property (readonly, copy, nullable) NSString *encodedURLString;
@property (readonly, copy, nullable) NSString *decodedURLString;

Performs Punycode encode/decode operations on each appropriate part (the domain bits) of an URL string, and URL encodes/decodes the path/query/fragment.


URL/NSURL

Swift:
init?(unicodeString: String)
Objective-C:
+ (nullable instancetype)URLWithUnicodeString:(NSString *)URLString;

Convenience initializer equivalent to URL(string: unicodeString.encodedURLString)/ [NSURL URLWithString:URLString.encodedURLString].


Swift:
var decodedURLString: String? { get }
Objective-C:
@property (readonly, copy, nullable) NSString *decodedURLString;

Convenience property equivalent to someURL.absoluteString.decodedURLString.


Swift:
init?(unicodeString: String, relativeTo url: URL?) {
Objective-C:
+ (nullable instancetype)URLWithUnicodeString:(NSString *)URLString relativeToURL:(nullable NSURL *)baseURL;

Convenience initializer for creating a URL from a Unicode string, relative to another URL.


© 2012–2022 Nate Weaver (Wevah)

GitHub

link
Stars: 59
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics