Skip to content

Commit d2fd671

Browse files
committed
Merge branch 'release/3.7.1'
2 parents 4c9122f + 9d6a455 commit d2fd671

File tree

4 files changed

+29
-63
lines changed

4 files changed

+29
-63
lines changed

ExampleiOS/ViewController.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ class ViewController: UIViewController {
1717
override func viewDidLoad() {
1818
super.viewDidLoad()
1919

20-
let text = """
21-
- <img named="check" att="5"/> Performed!
22-
"""
23-
let base = Style {
24-
$0.font = UIFont.boldSystemFont(ofSize: 14)
25-
$0.color = UIColor(hexString: "#8E8E8E")
26-
}
27-
28-
let xmlStyle = StyleXML(base: base)
29-
xmlStyle.imageProvider = { imageName, attributes in
30-
fatalError()
31-
}
32-
20+
// let text = """
21+
//- <img named="check" att="5"/> Performed!
22+
//"""
23+
// let base = Style {
24+
// $0.font = UIFont.boldSystemFont(ofSize: 14)
25+
// $0.color = UIColor(hexString: "#8E8E8E")
26+
// }
27+
//
28+
// let xmlStyle = StyleXML(base: base)
29+
// xmlStyle.imageProvider = { imageName, attributes in
30+
// fatalError()
31+
// }
32+
//
3333
// self.textView?.attributedText = text.set(style: xmlStyle)
3434

3535
// return

Sources/SwiftRichString/Support/Extensions.swift

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,50 +37,16 @@ import UIKit
3737

3838
extension String {
3939

40-
// Current implementation by @alexaubry in
41-
// https://github.com/alexaubry/HTMLString
40+
private static let escapeAmpRegExp = try! NSRegularExpression(pattern: "&(?!(#[0-9]{2,4}|[A-z]{2,6});)", options: NSRegularExpression.Options(rawValue: 0))
41+
4242
public func escapeWithUnicodeEntities() -> String {
43-
var copy = self
44-
copy.addUnicodeEntities()
45-
return copy
46-
}
47-
48-
internal mutating func addUnicodeEntities() {
49-
var position: String.Index? = startIndex
50-
let requiredEscapes: Set<Character> = ["!", "\"", "$", "%", "&", "'", "+", ",", "<", "=", ">", "@", "[", "]", "`", "{", "}"]
51-
52-
while let cursorPosition = position {
53-
guard cursorPosition != endIndex else { break }
54-
let character = self[cursorPosition]
55-
56-
if requiredEscapes.contains(character) {
57-
// One of the required escapes for security reasons
58-
let escape = "&#\(character.asciiValue!);" // required escapes can can only be ASCII
59-
position = positionAfterReplacingCharacter(at: cursorPosition, with: escape)
60-
} else {
61-
// Not a required escape, no need to replace the character
62-
position = index(cursorPosition, offsetBy: 1, limitedBy: endIndex)
63-
}
64-
}
43+
let range = NSRange(location: 0, length: self.count)
44+
return String.escapeAmpRegExp.stringByReplacingMatches(in: self,
45+
options: NSRegularExpression.MatchingOptions(rawValue: 0),
46+
range: range,
47+
withTemplate: "&amp;")
6548
}
6649

67-
/// Replaces the character at the given position with the escape and returns the new position.
68-
fileprivate mutating func positionAfterReplacingCharacter(at position: String.Index, with escape: String) -> String.Index? {
69-
let nextIndex = index(position, offsetBy: 1)
70-
71-
if let fittingPosition = index(position, offsetBy: escape.count, limitedBy: endIndex) {
72-
// Check if we can fit the whole escape in the receiver
73-
replaceSubrange(position ..< nextIndex, with: escape)
74-
return fittingPosition
75-
} else {
76-
// If we can't, remove the character and insert the escape to make it fit.
77-
remove(at: position)
78-
insert(contentsOf: escape, at: position)
79-
return index(position, offsetBy: escape.count, limitedBy: endIndex)
80-
}
81-
}
82-
83-
8450
}
8551

8652
extension NSNumber {

SwiftRichString.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "SwiftRichString"
3-
s.version = "3.7.0"
3+
s.version = "3.7.1"
44
s.summary = "Elegant Strings & Attributed Strings Toolkit for Swift"
55
s.description = <<-DESC
66
SwiftRichString is the best toolkit to work easily with Strings and Attributed Strings.

SwiftRichString.xcodeproj/project.pbxproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,7 @@
16401640
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
16411641
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
16421642
MACOSX_DEPLOYMENT_TARGET = 10.11;
1643-
MARKETING_VERSION = 3.7.0;
1643+
MARKETING_VERSION = 3.7.1;
16441644
ONLY_ACTIVE_ARCH = NO;
16451645
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-iOS";
16461646
PRODUCT_NAME = SwiftRichString;
@@ -1666,7 +1666,7 @@
16661666
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
16671667
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
16681668
MACOSX_DEPLOYMENT_TARGET = 10.11;
1669-
MARKETING_VERSION = 3.7.0;
1669+
MARKETING_VERSION = 3.7.1;
16701670
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-iOS";
16711671
PRODUCT_NAME = SwiftRichString;
16721672
SKIP_INSTALL = YES;
@@ -1718,7 +1718,7 @@
17181718
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
17191719
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
17201720
MACOSX_DEPLOYMENT_TARGET = 10.11;
1721-
MARKETING_VERSION = 3.7.0;
1721+
MARKETING_VERSION = 3.7.1;
17221722
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-watchOS";
17231723
PRODUCT_NAME = SwiftRichString;
17241724
SDKROOT = watchos;
@@ -1745,7 +1745,7 @@
17451745
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
17461746
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
17471747
MACOSX_DEPLOYMENT_TARGET = 10.11;
1748-
MARKETING_VERSION = 3.7.0;
1748+
MARKETING_VERSION = 3.7.1;
17491749
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-watchOS";
17501750
PRODUCT_NAME = SwiftRichString;
17511751
SDKROOT = watchos;
@@ -1772,7 +1772,7 @@
17721772
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
17731773
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
17741774
MACOSX_DEPLOYMENT_TARGET = 10.11;
1775-
MARKETING_VERSION = 3.7.0;
1775+
MARKETING_VERSION = 3.7.1;
17761776
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-tvOS";
17771777
PRODUCT_NAME = SwiftRichString;
17781778
SDKROOT = appletvos;
@@ -1799,7 +1799,7 @@
17991799
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
18001800
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
18011801
MACOSX_DEPLOYMENT_TARGET = 10.11;
1802-
MARKETING_VERSION = 3.7.0;
1802+
MARKETING_VERSION = 3.7.1;
18031803
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-tvOS";
18041804
PRODUCT_NAME = SwiftRichString;
18051805
SDKROOT = appletvos;
@@ -1828,7 +1828,7 @@
18281828
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
18291829
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
18301830
MACOSX_DEPLOYMENT_TARGET = 10.11;
1831-
MARKETING_VERSION = 3.7.0;
1831+
MARKETING_VERSION = 3.7.1;
18321832
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-macOS";
18331833
PRODUCT_NAME = SwiftRichString;
18341834
SDKROOT = macosx;
@@ -1855,7 +1855,7 @@
18551855
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
18561856
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
18571857
MACOSX_DEPLOYMENT_TARGET = 10.11;
1858-
MARKETING_VERSION = 3.7.0;
1858+
MARKETING_VERSION = 3.7.1;
18591859
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-macOS";
18601860
PRODUCT_NAME = SwiftRichString;
18611861
SDKROOT = macosx;

0 commit comments

Comments
 (0)