Skip to content

Commit c212017

Browse files
committed
#48 Fixed unicode rendering
1 parent c888d49 commit c212017

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

Sources/SwiftRichString/Extensions/AttributedString+Ext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public extension AttributedString {
156156
/// - Parameter style: style to use.
157157
/// - Returns: same instance of the receiver with - eventually - modified attributes.
158158
public func remove(_ style: StyleProtocol) -> Self {
159-
self.removeAttributes(Array(style.attributes.keys), range: NSMakeRange(0, self.string.count))
159+
self.removeAttributes(Array(style.attributes.keys), range: NSMakeRange(0, self.length))
160160
return self
161161
}
162162

Sources/SwiftRichString/Style/StyleProtocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public extension StyleProtocol {
5656
func set(to source: String, range: NSRange?) -> AttributedString {
5757
let attributedText = NSMutableAttributedString(string: source)
5858
self.fontData?.addAttributes(to: attributedText, range: nil)
59-
attributedText.addAttributes(self.attributes, range: (range ?? NSMakeRange(0, source.count)))
59+
attributedText.addAttributes(self.attributes, range: (range ?? NSMakeRange(0, attributedText.length)))
6060
return attributedText
6161
}
6262

Sources/SwiftRichString/Style/StyleRegEx.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ public class StyleRegEx: StyleProtocol {
9090

9191
public func add(to source: AttributedString, range: NSRange?) -> AttributedString {
9292
if let base = self.baseStyle {
93-
source.addAttributes(base.attributes, range: (range ?? NSMakeRange(0, source.string.count)))
93+
source.addAttributes(base.attributes, range: (range ?? NSMakeRange(0, source.length)))
9494
}
9595
return self.applyStyle(to: source, add: true, range: range)
9696
}
9797

9898
public func set(to source: AttributedString, range: NSRange?) -> AttributedString {
9999
if let base = self.baseStyle {
100-
source.setAttributes(base.attributes, range: (range ?? NSMakeRange(0, source.string.count)))
100+
source.setAttributes(base.attributes, range: (range ?? NSMakeRange(0, source.length)))
101101
}
102102
return self.applyStyle(to: source, add: false, range: range)
103103
}
@@ -112,7 +112,7 @@ public class StyleRegEx: StyleProtocol {
112112
/// - range: range, `nil` to apply the style to entire string.
113113
/// - Returns: modified attributed string
114114
private func applyStyle(to str: AttributedString, add: Bool, range: NSRange?) -> AttributedString {
115-
let rangeValue = (range ?? NSMakeRange(0, str.string.count))
115+
let rangeValue = (range ?? NSMakeRange(0, str.length))
116116

117117
let matchOpts = NSRegularExpression.MatchingOptions(rawValue: 0)
118118
self.regex.enumerateMatches(in: str.string, options: matchOpts, range: rangeValue) {

0 commit comments

Comments
 (0)