mirror of
https://github.com/zhigang1992/GitHawk.git
synced 2026-06-06 06:29:32 +08:00
Some notes about this update: - Using apollo-codegen 0.17.0-alpha.13 for Swift 4 support - Upgraded SnapKit, HTMLImage to versions with Swift 4 support - Added 3.2 intermix support for local CocoaPods ([from here](https://github.com/CocoaPods/CocoaPods/issues/6791)) - Using alpha version of Apoolo iOS as well for Swift 4
74 lines
2.4 KiB
Swift
74 lines
2.4 KiB
Swift
import Foundation
|
|
|
|
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
|
|
|
|
extension NSString {
|
|
|
|
///
|
|
/// Returns a copy of the current `String` where every character incompatible with HTML Unicode
|
|
/// encoding (UTF-16 or UTF-8) is replaced by a decimal HTML entity.
|
|
///
|
|
/// ### Examples
|
|
///
|
|
/// | String | Result | Format |
|
|
/// |--------|--------|--------|
|
|
/// | `&` | `&` | Decimal entity (part of the Unicode special characters) |
|
|
/// | `Σ` | `Σ` | Not escaped (Unicode compliant) |
|
|
/// | `🇺🇸` | `🇺🇸` | Not escaped (Unicode compliant) |
|
|
/// | `a` | `a` | Not escaped (alphanumerical) |
|
|
///
|
|
|
|
@objc(stringByAddingUnicodeEntities)
|
|
public func addingUnicodeEntities() -> NSString {
|
|
return (self as String).addingUnicodeEntities as NSString
|
|
}
|
|
|
|
///
|
|
/// Returns a copy of the current `String` where every character incompatible with HTML ASCII
|
|
/// encoding is replaced by a decimal HTML entity.
|
|
///
|
|
/// ### Examples
|
|
///
|
|
/// | String | Result | Format |
|
|
/// |--------|--------|--------|
|
|
/// | `&` | `&` | Decimal entity |
|
|
/// | `Σ` | `Σ` | Decimal entity |
|
|
/// | `🇺🇸` | `🇺🇸` | Combined decimal entities (extented grapheme cluster) |
|
|
/// | `a` | `a` | Not escaped (alphanumerical) |
|
|
///
|
|
/// ### Performance
|
|
///
|
|
/// If your webpage is unicode encoded (UTF-16 or UTF-8) use `addingUnicodeEntities` instead,
|
|
/// as it is faster and produces a less bloated and more readable HTML.
|
|
///
|
|
|
|
@objc(stringByAddingASCIIEntities)
|
|
public func addingASCIIEntities() -> NSString {
|
|
return (self as String).addingASCIIEntities as NSString
|
|
}
|
|
|
|
///
|
|
/// Returns a copy of the current `String` where every HTML entity is replaced with the matching
|
|
/// Unicode character.
|
|
///
|
|
/// ### Examples
|
|
///
|
|
/// | String | Result | Format |
|
|
/// |--------|--------|--------|
|
|
/// | `&` | `&` | Keyword entity |
|
|
/// | `Σ` | `Σ` | Decimal entity |
|
|
/// | `č` | `č` | Hexadecimal entity |
|
|
/// | `🇺🇸` | `🇺🇸` | Combined decimal entities (extented grapheme cluster) |
|
|
/// | `a` | `a` | Not an entity |
|
|
/// | `&` | `&` | Not an entity |
|
|
///
|
|
|
|
@objc(stringByRemovingHTMLEntities)
|
|
public func removingHTMLEntities() -> NSString {
|
|
return (self as String).removingHTMLEntities as NSString
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|