mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-16 08:50:40 +01:00
Compare fixed clipboard markers in native UTF-8 and UTF-16 representations
This commit is contained in:
1 parent
73cc0a8cdd
commit
4e4062a4df
1 file changed
+16
-2
+16
-2
@@ -5,12 +5,26 @@ final class MarkerCheck: NSObject {
|
||||
let gnome = NSTextField(labelWithString: "GNOME → Mac: not checked")
|
||||
let kde = NSTextField(labelWithString: "KDE → Mac: not checked")
|
||||
let copied = NSTextField(labelWithString: "Mac marker: not copied")
|
||||
let formats = NSTextField(labelWithString: "Known text formats: not checked")
|
||||
@objc func copyMarker() {
|
||||
NSPasteboard.general.clearContents()
|
||||
let ok = NSPasteboard.general.setString("UU-Mac-to-VM 中文🙂", forType: .string)
|
||||
copied.stringValue = ok ? "Mac marker: copied" : "Mac marker: failed"
|
||||
}
|
||||
func matches() -> Bool { NSPasteboard.general.string(forType: .string) == "UU-VM-to-Mac 中文🚀" }
|
||||
func matches() -> Bool {
|
||||
let board = NSPasteboard.general
|
||||
let utf16 = NSPasteboard.PasteboardType("public.utf16-plain-text")
|
||||
let known = board.types ?? []
|
||||
formats.stringValue = "Known text formats: UTF-8=\(known.contains(.string)), UTF-16=\(known.contains(utf16))"
|
||||
let marker = "UU-VM-to-Mac 中文🚀"
|
||||
if board.data(forType: .string) == Data(marker.utf8) { return true }
|
||||
guard let actual = board.data(forType: utf16) else { return false }
|
||||
for encoding in [String.Encoding.utf16, .utf16LittleEndian, .utf16BigEndian] {
|
||||
guard let expected = marker.data(using: encoding) else { continue }
|
||||
if actual == expected || actual == expected + Data([0, 0]) { return true }
|
||||
}
|
||||
return false
|
||||
}
|
||||
@objc func compareGnome() { gnome.stringValue = matches() ? "GNOME → Mac: PASS" : "GNOME → Mac: not matched" }
|
||||
@objc func compareKde() { kde.stringValue = matches() ? "KDE → Mac: PASS" : "KDE → Mac: not matched" }
|
||||
@objc func quit() { NSApp.terminate(nil) }
|
||||
@@ -25,7 +39,7 @@ final class MarkerCheck: NSObject {
|
||||
NSTextField(labelWithString: "Only fixed test-marker matches are displayed."),
|
||||
button("Copy Mac test marker", #selector(copyMarker)), copied,
|
||||
button("Compare GNOME VM marker", #selector(compareGnome)), gnome,
|
||||
button("Compare KDE VM marker", #selector(compareKde)), kde,
|
||||
button("Compare KDE VM marker", #selector(compareKde)), kde, formats,
|
||||
button("Quit test fixture", #selector(quit))])
|
||||
stack.orientation = .vertical; stack.spacing = 14
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
Reference in new issue
Block a user