Skip to content

Commit e43c944

Browse files
committed
Moved digits macro to top-level definition
1 parent abd9171 commit e43c944

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

core/shared/src/main/scala-0.22/scodec/bits/ByteVectorPlatform.scala

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,25 @@ trait ByteVectorPlatform {
1414

1515
given FromDigits {
1616
override inline def fromDigits(digits: String): ByteVector =
17-
${ByteVectorFromDigits('digits, Expr(10))}
17+
${digitsToByteVector('digits, Expr(10))}
1818
override inline def fromDigits(digits: String, radix: Int): ByteVector =
19-
${ByteVectorFromDigits('digits, 'radix)}
19+
${digitsToByteVector('digits, 'radix)}
2020
}
2121
}
2222

2323

24-
object ByteVectorFromDigits {
25-
26-
def apply(digits: Expr[String], radix: Expr[Int])(given qctx: QuoteContext): Expr[ByteVector] =
27-
(digits, radix) match {
28-
case (Const(ds), Const(r)) =>
29-
if (r == 16) {
30-
'{ByteVector.fromValidHex($digits.tail)}
31-
} else {
32-
qctx.error(s"unsupported radix $r", radix)
33-
'{ByteVector.empty}
34-
}
35-
case other =>
36-
'{
37-
if ($radix == 16) ByteVector.fromValidHex($digits.tail)
38-
else throw FromDigits.MalformedNumber("unsupported radix")
39-
}
40-
}
41-
}
24+
def digitsToByteVector(digits: Expr[String], radix: Expr[Int])(given qctx: QuoteContext): Expr[ByteVector] =
25+
(digits, radix) match {
26+
case (Const(ds), Const(r)) =>
27+
if (r == 16) {
28+
'{ByteVector.fromValidHex($digits.tail)}
29+
} else {
30+
qctx.error(s"unsupported radix $r", radix)
31+
'{ByteVector.empty}
32+
}
33+
case other =>
34+
'{
35+
if ($radix == 16) ByteVector.fromValidHex($digits.tail)
36+
else throw FromDigits.MalformedNumber("unsupported radix")
37+
}
38+
}

0 commit comments

Comments
 (0)