From 7da7595db4556a7a8844850b04b236375c65c5b3 Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 3 Dec 2018 12:36:29 -0600 Subject: [PATCH] Add String and Character extensions to Tools --- Sources/AOC2018/tools.swift | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Sources/AOC2018/tools.swift b/Sources/AOC2018/tools.swift index 44f5a80..50dccab 100644 --- a/Sources/AOC2018/tools.swift +++ b/Sources/AOC2018/tools.swift @@ -27,4 +27,19 @@ struct Tools { } return retVal } -} \ No newline at end of file +} + +extension Character { + var isAscii: Bool { + return unicodeScalars.first?.isASCII == true + } + var ascii: UInt32? { + return isAscii ? unicodeScalars.first?.value : nil + } +} + +extension StringProtocol { + var ascii: [UInt32] { + return compactMap { $0.ascii } + } +}