Skip to content

Commit

Permalink
fix: replace newlines with whitespaces cannot work in Adobe Acrobat
Browse files Browse the repository at this point in the history
  • Loading branch information
tisfeng committed May 25, 2024
1 parent b9eb62b commit 7657935
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Easydict/Swift/Utility/Extensions/String/String+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import Foundation

extension String {
/// Truncate string max lenght to 200.
func truncated(_ maxLength: Int = 200) -> String {
String(prefix(maxLength))
}

/// Trim whitespaces and newlines.
func trim() -> String {
trimmingCharacters(in: .whitespacesAndNewlines)
}
Expand All @@ -30,4 +32,15 @@ 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
for newline in newlines {
newString = replacingOccurrences(of: newline, with: " ") as NSString
}
return newString
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ - (void)receiveTitlebarAction:(EZTitlebarQuickAction)action {
break;
}
case EZTitlebarQuickActionReplaceNewlineWithSpace: {
self.inputText = [self.inputText stringByReplacingOccurrencesOfString:@"\n" withString:@" "];
self.inputText = [self.inputText replacingNewlinesWithWhitespace];
}
default:
break;
Expand Down

0 comments on commit 7657935

Please sign in to comment.