Skip to content

Commit

Permalink
Merge branch 'main' into brad/parse-config-version
Browse files Browse the repository at this point in the history
  • Loading branch information
SlayterDev committed Sep 12, 2024
2 parents b7b43d2 + 966fa49 commit a5c9cae
Show file tree
Hide file tree
Showing 32 changed files with 1,336 additions and 95 deletions.
2 changes: 1 addition & 1 deletion Core/FeatureFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ extension FeatureFlag: FeatureFlagSourceProviding {
case .newTabPageSections:
return .remoteDevelopment(.feature(.newTabPageImprovements))
case .duckPlayer:
return .remoteReleasable(.feature(.duckPlayer))
return .remoteReleasable(.subfeature(DuckPlayerSubfeature.enableDuckPlayer))
case .sslCertificatesBypass:
return .remoteReleasable(.subfeature(SslCertificatesSubfeature.allowBypass))
case .syncPromotionBookmarks:
Expand Down
82 changes: 82 additions & 0 deletions Core/NSAttributedStringExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,86 @@ extension NSAttributedString {
newString.setAttributes([.font: newFont], range: string.fullRange)
return newString
}

/// Creates a new `NSAttributedString` initialized with the characters and attributes of the current attributed string plus the specified font.
///
/// - Parameter font: The `UIFont` to apply to the text in the `NSAttributedString`.
/// - Returns: A new `NSAttributedString`initialized with characters and attributes of the current attributed string plus the specified font.
public func withFont(_ font: UIFont) -> NSAttributedString {
with(attribute: .font, value: font)
}

/// Creates a new `NSAttributedString` initialized with the characters and attributes of the current attributed string plus the specified text color
///
/// - Parameter color: The color to apply to the text
/// - Returns: A new `NSAttributedString` initialized with characters and attributes of the current attributed string plus the text color
public func withTextColor(_ color: UIColor) -> NSAttributedString {
with(attribute: .foregroundColor, value: color)
}

/// Creates a new `NSAttributedString` initialized with the characters and attributes of the current attributed string plus the specified attribute
///
/// - Parameters:
/// - key: The attribute key to apply. This should be one of the keys defined in `NSAttributedString.Key`.
/// - value: The value associated with the attribute key. This can be any object compatible with the attribute.
/// - range: An optional `NSRange` specifying the range within the `NSAttributedString` to apply the attribute.
/// If `nil`, the attribute is applied to the entire `NSAttributedString`.
/// - Returns: A new `NSAttributedString` with the specified attribute applied.
public func with(attribute key: NSAttributedString.Key, value: Any, in range: NSRange? = nil) -> NSAttributedString {
with(attributes: [key: value], in: range)
}

/// Creates a new `NSAttributedString` initialized with the characters and attributes of the current attributed string plus the specified attributes
///
/// - Parameters:
/// - attributes: A dictionary of attributes to apply, where the keys are of type `NSAttributedString.Key` and the values
/// are objects compatible with the attributes (e.g., `UIFont`, `UIColor`).
/// - range: An optional `NSRange` specifying the range within the `NSAttributedString` to apply the attributes.
/// If `nil`, the attributes are applied to the entire `NSAttributedString`.
/// - Returns: A new `NSAttributedString` with the specified attributes applied.
public func with(attributes: [NSAttributedString.Key: Any], in range: NSRange? = nil) -> NSAttributedString {
let mutableString = NSMutableAttributedString(attributedString: self)
mutableString.addAttributes(attributes, range: range ?? string.nsRange)
return mutableString
}
}

/// Concatenates two `NSAttributedString` instances, returning a new `NSAttributedString`.
///
/// - Parameters:
/// - lhs: The left-hand side `NSAttributedString` to which the `rhs` `NSAttributedString` will be appended.
/// - rhs: The `NSAttributedString` to append to the `lhs` `NSAttributedString`.
/// - Returns: A new `NSAttributedString` that is the result of concatenating `lhs` and `rhs`.
public func + (lhs: NSAttributedString, rhs: NSAttributedString) -> NSAttributedString {
let mutable = NSMutableAttributedString(attributedString: lhs)
mutable.append(rhs)
return mutable
}

/// Concatenates an `NSAttributedString` with a `String`, returning a new `NSAttributedString`.
///
/// - Parameters:
/// - lhs: The left-hand side `NSAttributedString` to which the `String` will be appended.
/// - rhs: The `String` to append to the `lhs` `NSAttributedString`.
/// - Returns: A new `NSAttributedString` which is the result of concatenating `lhs` with `rhs`.
public func + (lhs: NSAttributedString, rhs: String) -> NSAttributedString {
lhs + NSAttributedString(string: rhs)
}

/// Concatenates a `String` with an `NSAttributedString`, returning a new `NSAttributedString`.
///
/// - Parameters:
/// - lhs: The `String` to prepend to the `rhs` `NSAttributedString`.
/// - rhs: The right-hand side `NSAttributedString` that will be appended to the `lhs` `String`.
/// - Returns: A new `NSAttributedString` which is the result of concatenating `lhs` with `rhs`.
public func + (lhs: String, rhs: NSAttributedString) -> NSAttributedString {
NSAttributedString(string: lhs) + rhs
}

private extension String {

var nsRange: NSRange {
NSRange(startIndex..., in: self)
}

}
Loading

0 comments on commit a5c9cae

Please sign in to comment.