File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
src/main/scala/inox/utils Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -17,15 +17,17 @@ object StringUtils {
17
17
}
18
18
19
19
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
21
21
22
22
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
23
25
24
26
object Hex {
25
27
def unapply (s : String ): Option [(Byte , String )] = {
26
28
if (hex.findFirstIn(s).isDefined) {
27
29
val (head, s2) = s.splitAt(4 )
28
- Some ((decodeHex(head), s2))
30
+ Some ((decodeHex(head.drop( 2 ) ), s2))
29
31
} else {
30
32
None
31
33
}
@@ -44,6 +46,8 @@ object StringUtils {
44
46
}
45
47
46
48
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)
47
51
case JavaEncoded (b, s2) => (b & 0xFF ).toChar + decode(s2)
48
52
case _ => s.head + decode(s.tail)
49
53
})
You can’t perform that action at this time.
0 commit comments