Skip to content

Commit

Permalink
perf: add replacingNewlinesWithWhitespace() for Swift String extension
Browse files Browse the repository at this point in the history
  • Loading branch information
tisfeng committed May 25, 2024
1 parent 7657935 commit d7997da
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ extension String {
func trim() -> String {
trimmingCharacters(in: .whitespacesAndNewlines)
}

/// Replace all newlines with whitespaces.
/// For line breaks, currently macOS is `\n`, previously used `\r`, Windows is `\r\n`.
func replacingNewlinesWithWhitespace() -> String {
(self as NSString).replacingNewlinesWithWhitespace() as String
}
}

@objc
Expand All @@ -33,8 +39,6 @@ extension NSString {
return self
}

/// Replace all newlines with whitespaces.
/// For line breaks, currently macOS is `\n`, previously used `\n`, Windows is `\r\n`.
func replacingNewlinesWithWhitespace() -> NSString {
let newlines = ["\r\n", "\n", "\r"]
var newString = self
Expand Down

0 comments on commit d7997da

Please sign in to comment.