Skip to content

Commit e60126b

Browse files
committed
Add support for decoding CVC4 1.8 strings
1 parent 07fa1d5 commit e60126b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/main/scala/inox/utils/StringUtils.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ object StringUtils {
1717
}
1818

1919
def encodeByte(b: Byte): String = "\\x" + toHex((b >> 4) & 0xF) + toHex(b & 0xF)
20-
def decodeHex(s: String): Byte = ((fromHex(s.charAt(2)) << 4) + fromHex(s.charAt(3))).toByte
20+
def decodeHex(s: String): Byte = ((fromHex(s.charAt(0)) << 4) + fromHex(s.charAt(1))).toByte
2121

2222
private val hex = """^\\x[0-9A-Fa-f]{2}""".r
23+
private val uhex1 = """(?s)^\\u\{([0-9A-Fa-f])\}(.*)""".r
24+
private val uhex2 = """(?s)^\\u\{([0-9A-Fa-f]{2})\}(.*)""".r
2325

2426
object Hex {
2527
def unapply(s: String): Option[(Byte, String)] = {
2628
if (hex.findFirstIn(s).isDefined) {
2729
val (head, s2) = s.splitAt(4)
28-
Some((decodeHex(head), s2))
30+
Some((decodeHex(head.drop(2)), s2))
2931
} else {
3032
None
3133
}
@@ -44,6 +46,8 @@ object StringUtils {
4446
}
4547

4648
def decode(s: String): String = if (s.isEmpty) s else (s match {
49+
case uhex1(head, s2) => (fromHex(head.charAt(0)) & 0xF).toChar + decode(s2)
50+
case uhex2(head, s2) => (decodeHex(head) & 0xFF).toChar + decode(s2)
4751
case JavaEncoded(b, s2) => (b & 0xFF).toChar + decode(s2)
4852
case _ => s.head + decode(s.tail)
4953
})

0 commit comments

Comments
 (0)