File tree Expand file tree Collapse file tree 3 files changed +9
-4
lines changed
Tests/StencilSwiftKitTests Expand file tree Collapse file tree 3 files changed +9
-4
lines changed Original file line number Diff line number Diff line change 14
14
15
15
### Bug Fixes
16
16
17
- _ None_
17
+ * ` swiftIdentifier ` : fix crash on empty string.
18
+ [ David Jennes] ( https://github.com/djbe )
19
+ [ #105 ] ( https://github.com/SwiftGen/StencilSwiftKit/pull/105 )
18
20
19
21
### Internal Changes
20
22
Original file line number Diff line number Diff line change @@ -114,10 +114,9 @@ enum SwiftIdentifier {
114
114
static func prefixWithUnderscoreIfNeeded( string: String ,
115
115
forbiddenChars exceptions: String = " " ) -> String {
116
116
117
- let ( head , _ ) = identifierCharacterSets ( exceptions : exceptions )
117
+ guard let firstChar = string . unicodeScalars . first else { return " " }
118
118
119
- let chars = string. unicodeScalars
120
- let firstChar = chars [ chars. startIndex]
119
+ let ( head, _) = identifierCharacterSets ( exceptions: exceptions)
121
120
let prefix = !head. longCharacterIsMember ( firstChar. value) ? " _ " : " "
122
121
123
122
return prefix + string
Original file line number Diff line number Diff line change @@ -47,6 +47,10 @@ class SwiftIdentifierTests: XCTestCase {
47
47
SwiftIdentifier . identifier ( from: " hello$world^this*contains%a=lot@of<forbidden>chars!does#it/still:work.anyway? " ) ,
48
48
" HelloWorldThisContainsALotOfForbiddenCharsDoesItStillWorkAnyway " )
49
49
}
50
+
51
+ func testEmptyString( ) {
52
+ XCTAssertEqual ( SwiftIdentifier . identifier ( from: " " ) , " " )
53
+ }
50
54
}
51
55
52
56
extension SwiftIdentifierTests {
You can’t perform that action at this time.
0 commit comments