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
…564)

* perf: adjust files structure, move Swift extension to Swift group

* fix: replace newlines with whitespaces cannot work in Adobe Acrobat

* perf: add replacingNewlinesWithWhitespace() for Swift String extension
  • Loading branch information
tisfeng authored May 25, 2024
1 parent 3f7c83a commit a55487c
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 30 deletions.
48 changes: 19 additions & 29 deletions Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
033C30FC2A7409C40095926A /* TTTDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = 033C30FB2A7409C40095926A /* TTTDictionary.m */; };
033C31002A74CECE0095926A /* EZAppleDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = 033C30FF2A74CECE0095926A /* EZAppleDictionary.m */; };
0342A9812AD64924002A9F5F /* NSString+EZSplit.m in Sources */ = {isa = PBXBuildFile; fileRef = 0342A9802AD64924002A9F5F /* NSString+EZSplit.m */; };
034749772B37279200FF679C /* String+EncryptAES.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03FD68BD2B1E151A00FD388E /* String+EncryptAES.swift */; };
03542A30293645DF00C34C33 /* EZAppleService.m in Sources */ = {isa = PBXBuildFile; fileRef = 03542A2F293645DF00C34C33 /* EZAppleService.m */; };
03542A342936F70F00C34C33 /* EZLanguageManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 03542A332936F70F00C34C33 /* EZLanguageManager.m */; };
03542A3A2937AE6400C34C33 /* EZQueryService.m in Sources */ = {isa = PBXBuildFile; fileRef = 03542A392937AE6400C34C33 /* EZQueryService.m */; };
Expand Down Expand Up @@ -307,8 +306,8 @@
A0B65CA0F31AC8ECFB8347CC /* Pods_EasydictTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 378E73A7EA8FC8FB9C975A63 /* Pods_EasydictTests.framework */; };
B87AC7E36367075BA5D13234 /* Pods_Easydict.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6372B33DFF803C7096A82250 /* Pods_Easydict.framework */; };
C415C0AD2B450D4800A9D231 /* GeminiService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C415C0AC2B450D4800A9D231 /* GeminiService.swift */; };
C4BFDD7A2BE61F550094026B /* Vortex in Frameworks */ = {isa = PBXBuildFile; productRef = C4BFDD792BE61F550094026B /* Vortex */; };
C490BF722BE910B70021E40A /* AdvancedTabItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C490BF712BE910B70021E40A /* AdvancedTabItemView.swift */; };
C4BFDD7A2BE61F550094026B /* Vortex in Frameworks */ = {isa = PBXBuildFile; productRef = C4BFDD792BE61F550094026B /* Vortex */; };
C4DD01E92B12B3C80025EE8E /* TencentService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4DD01E82B12B3C80025EE8E /* TencentService.swift */; };
C4DD01EB2B12BA250025EE8E /* TencentResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4DD01EA2B12BA250025EE8E /* TencentResponse.swift */; };
C4DD01ED2B12BE9B0025EE8E /* TencentTranslateType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4DD01EC2B12BE9B0025EE8E /* TencentTranslateType.swift */; };
Expand Down Expand Up @@ -1019,6 +1018,17 @@
path = EasydictTests;
sourceTree = "<group>";
};
0317516C2C018A8800EFB343 /* Others */ = {
isa = PBXGroup;
children = (
EA9943E72B534D8900EE7B97 /* LanguageDetectOptimizeExtensions.swift */,
EA9943ED2B5353AB00EE7B97 /* WindowTypeExtensions.swift */,
EA9943EF2B5354C400EE7B97 /* ShowWindowPositionExtensions.swift */,
EA9943F12B5358BF00EE7B97 /* LanguageExtensions.swift */,
);
path = Others;
sourceTree = "<group>";
};
03247E37296AE8C800AFCD67 /* LoadingAnimationView */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1337,7 +1347,6 @@
038954372A25A94E00EFFDC3 /* Utility */ = {
isa = PBXGroup;
children = (
03CF88602B137ECB0030C199 /* Swift */,
03CAB9522ADBEF5000DA94A3 /* SystemUtility */,
030570DF2ADB916E00C9905E /* AppleScript */,
03D8B26A292DBC8800D5A811 /* EZCategory */,
Expand Down Expand Up @@ -1371,8 +1380,9 @@
038A723E2B62C07B004995E3 /* String */ = {
isa = PBXGroup;
children = (
038A723F2B62C0B9004995E3 /* String+Regex.swift */,
033A8EAD2BDFE09B00030C08 /* String+Extension.swift */,
038A723F2B62C0B9004995E3 /* String+Regex.swift */,
03FD68BD2B1E151A00FD388E /* String+EncryptAES.swift */,
);
path = String;
sourceTree = "<group>";
Expand Down Expand Up @@ -2009,18 +2019,6 @@
path = SystemUtility;
sourceTree = "<group>";
};
03CF88602B137ECB0030C199 /* Swift */ = {
isa = PBXGroup;
children = (
0A2A05A42B59755F00EEA142 /* Bundle */,
0A2BA9622B4A3CBB002872A4 /* Notification */,
0A2BA95E2B49A967002872A4 /* Binding */,
03FD68BC2B1E14B500FD388E /* String */,
03CF88612B137ED60030C199 /* Array */,
);
path = Swift;
sourceTree = "<group>";
};
03CF88612B137ED60030C199 /* Array */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2185,14 +2183,6 @@
path = Volcano;
sourceTree = "<group>";
};
03FD68BC2B1E14B500FD388E /* String */ = {
isa = PBXGroup;
children = (
03FD68BD2B1E151A00FD388E /* String+EncryptAES.swift */,
);
path = String;
sourceTree = "<group>";
};
0A2A05A42B59755F00EEA142 /* Bundle */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2517,14 +2507,15 @@
EA9943E62B534D7C00EE7B97 /* Extensions */ = {
isa = PBXGroup;
children = (
0317516C2C018A8800EFB343 /* Others */,
0A2A05A42B59755F00EEA142 /* Bundle */,
0A2BA9622B4A3CBB002872A4 /* Notification */,
0A2BA95E2B49A967002872A4 /* Binding */,
03CF88612B137ED60030C199 /* Array */,
03779F162BB256C5008D3C42 /* URL */,
038F1F8D2BAD835500CD2F65 /* AppKit */,
EA1013412B5DBDA5005E43F9 /* Defaults */,
038A723E2B62C07B004995E3 /* String */,
EA9943E72B534D8900EE7B97 /* LanguageDetectOptimizeExtensions.swift */,
EA9943ED2B5353AB00EE7B97 /* WindowTypeExtensions.swift */,
EA9943EF2B5354C400EE7B97 /* ShowWindowPositionExtensions.swift */,
EA9943F12B5358BF00EE7B97 /* LanguageExtensions.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -2917,7 +2908,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
034749772B37279200FF679C /* String+EncryptAES.swift in Sources */,
03022F312B370B7100B63209 /* EasydictSwiftTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
17 changes: 17 additions & 0 deletions Easydict/Swift/Utility/Extensions/String/String+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@
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)
}

/// 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 @@ -30,4 +38,13 @@ extension NSString {
}
return self
}

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 a55487c

Please sign in to comment.