@@ -49,25 +49,34 @@ extension AttributedString {
49
49
/// Add a AttributedString to another AttributedString and return a new AttributedString instance.
50
50
///
51
51
/// - Parameters:
52
- /// - lhs: NSAttributedString to add.
53
- /// - rhs: NSAttributedString to add.
54
- /// - Returns: New instance with added NSAttributedString .
52
+ /// - lhs: AttributedString to add.
53
+ /// - rhs: AttributedString to add.
54
+ /// - Returns: New instance with added AttributedString .
55
55
public static func + ( lhs: AttributedString , rhs: AttributedString ) -> AttributedString {
56
56
let string = NSMutableAttributedString ( attributedString: lhs. value)
57
57
string. append ( rhs. value)
58
58
return . init( string)
59
59
}
60
60
61
- /// Add a AttributedString to another AttributedString.
61
+ /// Add a String to another AttributedString.
62
62
///
63
63
/// - Parameters:
64
- /// - lhs: NSAttributedString to add to.
64
+ /// - lhs: AttributedString to add to.
65
65
/// - rhs: String to add.
66
66
public static func += ( lhs: inout AttributedString , rhs: String ) {
67
67
lhs += AttributedString ( . init( string: rhs) )
68
68
}
69
+
70
+ /// Add a AttributedString to another String.
71
+ ///
72
+ /// - Parameters:
73
+ /// - lhs: String to add to.
74
+ /// - rhs: AttributedString to add.
75
+ public static func += ( lhs: inout String , rhs: AttributedString ) {
76
+ lhs += rhs. value. string
77
+ }
69
78
70
- /// Add a NSAttributedString to another AttributedString and return a new AttributedString instance.
79
+ /// Add a String to another AttributedString and return a new AttributedString instance.
71
80
///
72
81
/// - Parameters:
73
82
/// - lhs: AttributedString to add.
@@ -76,4 +85,91 @@ extension AttributedString {
76
85
public static func + ( lhs: AttributedString , rhs: String ) -> AttributedString {
77
86
return lhs + AttributedString( . init( string: rhs) )
78
87
}
88
+
89
+ /// Add a NSAttributedString to another AttributedString.
90
+ ///
91
+ /// - Parameters:
92
+ /// - lhs: AttributedString to add to.
93
+ /// - rhs: NSAttributedString to add.
94
+ public static func += ( lhs: inout AttributedString , rhs: NSAttributedString ) {
95
+ lhs += AttributedString ( rhs)
96
+ }
97
+
98
+ /// Add a AttributedString to another NSMutableAttributedString.
99
+ ///
100
+ /// - Parameters:
101
+ /// - lhs: NSMutableAttributedString to add to.
102
+ /// - rhs: AttributedString to add.
103
+ public static func += ( lhs: inout NSMutableAttributedString , rhs: AttributedString ) {
104
+ lhs. append ( rhs. value)
105
+ }
106
+
107
+ /// Add a NSAttributedString to another AttributedString and return a new AttributedString instance.
108
+ ///
109
+ /// - Parameters:
110
+ /// - lhs: AttributedString to add.
111
+ /// - rhs: NSAttributedString to add.
112
+ /// - Returns: New instance with added NSAttributedString.
113
+ public static func + ( lhs: AttributedString , rhs: NSAttributedString ) -> AttributedString {
114
+ return lhs + AttributedString( rhs)
115
+ }
116
+
117
+ /// Add a AttributedString.Style to another AttributedString.
118
+ ///
119
+ /// - Parameters:
120
+ /// - lhs: AttributedString to add to.
121
+ /// - rhs: AttributedString.Style to add.
122
+ public static func += ( lhs: inout AttributedString , rhs: AttributedString . Style ) {
123
+ lhs += ( rhs, . init( location: 0 , length: lhs. value. string. count) )
124
+ }
125
+
126
+ /// Add a AttributedString.Style to another AttributedString.
127
+ ///
128
+ /// - Parameters:
129
+ /// - lhs: AttributedString to add to.
130
+ /// - rhs: AttributedString.Style to add.
131
+ public static func += ( lhs: inout AttributedString , rhs: ( AttributedString . Style , NSRange ) ) {
132
+ lhs += ( [ rhs. 0 ] , rhs. 1 )
133
+ }
134
+
135
+ /// Add a AttributedString.Style to another AttributedString.
136
+ ///
137
+ /// - Parameters:
138
+ /// - lhs: AttributedString to add to.
139
+ /// - rhs: AttributedString.Style to add.
140
+ public static func += ( lhs: inout AttributedString , rhs: ( [ AttributedString . Style ] , NSRange ) ) {
141
+ lhs = lhs + rhs
142
+ }
143
+
144
+ /// Add a AttributedString.Style to another AttributedString and return a new AttributedString instance.
145
+ ///
146
+ /// - Parameters:
147
+ /// - lhs: AttributedString to add.
148
+ /// - rhs: AttributedString.Style to add.
149
+ /// - Returns: New instance with added AttributedString.Style.
150
+ public static func + ( lhs: AttributedString , rhs: AttributedString . Style ) -> AttributedString {
151
+ return lhs + ( rhs, . init( location: 0 , length: lhs. value. string. count) )
152
+ }
153
+
154
+ /// Add a AttributedString.Style to another AttributedString and return a new AttributedString instance.
155
+ ///
156
+ /// - Parameters:
157
+ /// - lhs: AttributedString to add.
158
+ /// - rhs: AttributedString.Style to add.
159
+ /// - Returns: New instance with added AttributedString.Style.
160
+ public static func + ( lhs: AttributedString , rhs: ( AttributedString . Style , NSRange ) ) -> AttributedString {
161
+ return lhs + ( [ rhs. 0 ] , rhs. 1 )
162
+ }
163
+
164
+ /// Add a AttributedString.Style to another AttributedString and return a new AttributedString instance.
165
+ ///
166
+ /// - Parameters:
167
+ /// - lhs: AttributedString to add.
168
+ /// - rhs: AttributedString.Style to add.
169
+ /// - Returns: New instance with added AttributedString.Style.
170
+ public static func + ( lhs: AttributedString , rhs: ( [ AttributedString . Style ] , NSRange ) ) -> AttributedString {
171
+ let string = NSMutableAttributedString ( attributedString: lhs. value)
172
+ rhs. 0 . forEach { string. addAttributes ( $0. attributes, range: rhs. 1 ) }
173
+ return . init( string)
174
+ }
79
175
}
0 commit comments