Simple Cocoa methods for Punycode and IDNA on NSString
C C++ Objective-C Ruby
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Example
Pod
.gitignore
.travis.yml
LICENSE
Punycode-Cocoa.podspec
README.md

README.md

Punycode Cocoa

Build Status

v1.4 (2018) by Nate Weaver (Wevah)
https://derailer.org/
https://github.com/Wevah/Punycode-Cocoa

A simple punycode/IDNA category on NSString, based on code and documentation from RFC 3492 and RFC 3490.

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

To use in your own projects, all you need is NSStringPunycodeAdditions.h/m. This project includes a sample testing app.

Macros

Define PUNYCODE_COCOA_USE_WEBKIT to have Punycode Cocoa methods call internal WebKit methods instead of the custom implementations. Useful if you're already linking against WebKit, or want additional homograph attack protection. However, this probably won't be allowed on the App Store due to its use of private methods.

Define PUNYCODE_COCOA_USE_ICU to use ICU (by default the system's ICU).

Methods

NSString

@property (readonly, copy, nullable)	NSString *punycodeEncodedString;
@property (readonly, copy, nullable)	NSString *punycodeDecodedString;

Encodes or decodes a string to its punycode-encoded format, stripping variation selectors (U+FE00U+FE0F).

@property (readonly, copy, nullable) NSString *IDNAEncodedString;

If self contains non-ASCII, calls -punycodeEncodedString and prepends xn--.

@property (readonly, copy, nullable) NSString *IDNADecodedString;

Decodes a string returned by -IDNAEncodedString.

@property (readonly, copy, nullable) NSString *encodedURLString;
@property (readonly, copy, nullable) NSString *decodedURLString;

Performs encode/decode operations on each appropriate part (the domain bits) of an URL string.

NSURL

+ (nullable instancetype)URLWithUnicodeString:(NSString *)URLString;

Convenience method equivalent to [NSURL URLWithString:URLString.encodedURLString].

@property (readonly, copy, nullable) NSString *decodedURLString;

Convenience property equivalent to anURL.absoluteString.decodedURLString.


© 2012–2017 Nate Weaver (Wevah)