Last active
May 25, 2020 11:08
-
-
Save eastari/3f5f39b35b3dcaca363adc35df323387 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
init<S: Sequence>(unicodeScalars ucs: S) where S.Iterator.Element == UnicodeScalar { | |
var s = "" | |
s.unicodeScalars.append(contentsOf: ucs) | |
self = s | |
} | |
var underlineUnicode: String? { | |
let underlineUnicode: UInt32 = 818 | |
guard let underlineUnicodeScalar = Unicode.Scalar(underlineUnicode) else { return nil } | |
var resultString = "" | |
for unicodeScalar in self.unicodeScalars { | |
guard let characterUnicodeScalar = Unicode.Scalar(unicodeScalar.value) else { return nil } | |
let underlineCharacter = String(unicodeScalars: [characterUnicodeScalar, underlineUnicodeScalar]) | |
resultString.append(underlineCharacter) | |
} | |
return resultString | |
} | |
} | |
print("test".underlineUnicode) | |
// Optional("t̲e̲s̲t̲") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment