File tree Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,17 @@ extension IntegerLiteralExprSyntax {
3131 case . hex: return 16
3232 }
3333 }
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+ }
3445 }
3546
3647 public var radix : Radix {
@@ -67,15 +78,8 @@ extension IntegerLiteralExprSyntax {
6778 /// ```
6879 public func split( ) -> ( prefix: String , value: Substring ) {
6980 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) )
8084 }
8185}
You can’t perform that action at this time.
0 commit comments