File tree 1 file changed +14
-10
lines changed 1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,17 @@ extension IntegerLiteralExprSyntax {
31
31
case . hex: return 16
32
32
}
33
33
}
34
+
35
+ /// The prefix that is used to express an integer literal with this
36
+ /// radix in Swift source code, e.g., "0x" for hexadecimal.
37
+ public var literalPrefix : String {
38
+ switch self {
39
+ case . binary: return " 0b "
40
+ case . octal: return " 0o "
41
+ case . hex: return " 0x "
42
+ case . decimal: return " "
43
+ }
44
+ }
34
45
}
35
46
36
47
public var radix : Radix {
@@ -67,15 +78,8 @@ extension IntegerLiteralExprSyntax {
67
78
/// ```
68
79
public func split( ) -> ( prefix: String , value: Substring ) {
69
80
let text = self . literal. text
70
- switch self . radix {
71
- case . binary:
72
- return ( " 0b " , text. dropFirst ( 2 ) )
73
- case . octal:
74
- return ( " 0o " , text. dropFirst ( 2 ) )
75
- case . decimal:
76
- return ( " " , Substring ( text) )
77
- case . hex:
78
- return ( " 0x " , text. dropFirst ( 2 ) )
79
- }
81
+ let radix = self . radix
82
+ let literalPrefix = radix. literalPrefix
83
+ return ( literalPrefix, text. dropFirst ( literalPrefix. count) )
80
84
}
81
85
}
You can’t perform that action at this time.
0 commit comments