File tree Expand file tree Collapse file tree 2 files changed +15
-10
lines changed
Sources/SwiftProtobufPluginLibrary Expand file tree Collapse file tree 2 files changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -107,9 +107,16 @@ struct InternalCodeGeneratorParameter: CodeGeneratorParameter {
107
107
return [ ]
108
108
}
109
109
let parts = parameter. components ( separatedBy: " , " )
110
- let asPairs = parts. map { partition ( string: $0, atFirstOccurrenceOf: " = " ) }
111
- let result = asPairs. map { ( key: trimWhitespace ( $0) , value: trimWhitespace ( $1) ) }
112
- return result
110
+ return parts. map { s -> ( key: String , value: String ) in
111
+ guard let index = s. range ( of: " = " ) ? . lowerBound else {
112
+ // Key only, no value ("baz" in example).
113
+ return ( trimWhitespace ( s) , " " )
114
+ }
115
+ return (
116
+ key: trimWhitespace ( s [ ..< index] ) ,
117
+ value: trimWhitespace ( s [ s. index ( after: index) ... ] )
118
+ )
119
+ }
113
120
}
114
121
}
115
122
Original file line number Diff line number Diff line change 10
10
11
11
import Foundation
12
12
13
- func partition( string: String , atFirstOccurrenceOf substring: String ) -> ( String , String ) {
14
- guard let index = string. range ( of: substring) ? . lowerBound else {
15
- return ( string, " " )
16
- }
17
- return ( String ( string [ ..< index] ) ,
18
- String ( string [ string. index ( after: index) ... ] ) )
13
+ @inlinable
14
+ func trimWhitespace( _ s: String ) -> String {
15
+ return s. trimmingCharacters ( in: . whitespacesAndNewlines)
19
16
}
20
17
21
- func trimWhitespace( _ s: String ) -> String {
18
+ @inlinable
19
+ func trimWhitespace( _ s: String . SubSequence ) -> String {
22
20
return s. trimmingCharacters ( in: . whitespacesAndNewlines)
23
21
}
You can’t perform that action at this time.
0 commit comments