File tree Expand file tree Collapse file tree 1 file changed +4
-17
lines changed
Expand file tree Collapse file tree 1 file changed +4
-17
lines changed Original file line number Diff line number Diff line change @@ -65,27 +65,14 @@ class Parser {
6565 return result. trimmed
6666 }
6767
68- /// Split line from password file in to a key-value pair separted by `: `.
68+ /// Split line from password file in to a key-value pair separted by `:`.
6969 ///
7070 /// - Parameter line: Line from a password file
7171 /// - Returns: Pair of two `String`s of which the first one can be 'nil'
7272 static func getKeyValuePair( from line: String ) -> ( key: String ? , value: String ) {
73- let items = line. components ( separatedBy: " : " ) . map { String ( $0) . trimmingCharacters ( in: . whitespaces) }
74- var key : String ?
75- var value = " "
76- if items. count == 1 || ( items [ 0 ] . isEmpty && items [ 1 ] . isEmpty) {
77- // No ': ' found, or empty on both sides of ': '.
78- value = line
79- // "otpauth" special case
80- if value. hasPrefix ( Constants . OTPAUTH_URL_START) {
81- key = Constants . OTPAUTH
82- }
83- } else {
84- if !items[ 0 ] . isEmpty {
85- key = items [ 0 ]
86- }
87- value = items [ 1 ]
73+ if let separatorIdx = line. firstIndex ( of: " : " ) {
74+ return ( String ( line [ ..< separatorIdx] ) , String ( line [ line. index ( after: separatorIdx) ... ] ) . trimmingCharacters ( in: . whitespaces) )
8875 }
89- return ( key , value )
76+ return ( nil , line )
9077 }
9178}
You can’t perform that action at this time.
0 commit comments