public static byte[] bgl_escape_C_string( byte[] src, int start, int end )
{
int size = 0;
for (int i = start; i < end; ++i, ++size) {
if (src[i] == '\\') {
if ((i + 3 < end)
&& isdigit(src[i + 1])
&& isdigit(src[i + 2]) && isdigit(src[i + 3]))
i += 3;
else
i += 1;
}
}
int utf8shrink = 0;
byte[] result = new byte[size];
int j = 0;
for (int i = start; i < end; ++i, ++j) {
if (src[i] != '\\') {
result[j] = src[i];
} else {
byte cn = src[++i];
switch (cn) {
case (byte) '\0':
result[j] = (byte) '\\';
break;
case (byte) 'n':
result[j] = (byte) '\n';
break;
case (byte) 't':
result[j] = (byte) '\t';
break;
case (byte) 'b':
result[j] = (byte) '\b';
break;
case (byte) 'r':
result[j] = (byte) '\r';
break;
case (byte) 'f':
result[j] = (byte) '\f';
break;
case (byte) 'v':
result[j] = (byte) 11;
break;
default: {
if (i + 2 < end) {
byte s0 = src[i];
byte s1 = src[i + 1];
byte s2 = src[i + 2];
if (isdigit(s0) && isdigit(s1) && isdigit(s2)) {
result[j] = (byte) (64 * ((int) (s0 - '0'))
+ 8 * ((int) (s1 - '0'))
+ ((int) (s2 - '0')));
i += 2;
} else {
if (((s0 == (byte) 'x') || (s0 == (byte) 'X'))
&& isxdigit(s1)
&& isxdigit(s2) ) {
byte n1 = xdigit_to_byte( s1 );
byte n2 = xdigit_to_byte( s2 );
result[j] = (byte) (n1 * 16 + n2);
i += 2;
} else {
if (i + 4 < end) {
byte s3 = src[i + 3];
byte s4 = src[i + 4];
if( ((s0 == (byte) 'u') || (s0 == (byte) 'U'))
&& isxdigit(s1)
&& isxdigit(s2)
&& isxdigit(s3)
&& isxdigit(s4) ) {
byte n1 = xdigit_to_byte( s1 );
byte n2 = xdigit_to_byte( s2 );
byte n3 = xdigit_to_byte( s3 );
byte n4 = xdigit_to_byte( s4 );
char u =
(char)(n1*4096 + n2*512 + n3*16 + n4);
char[] ucs2 = make_ucs2_string( 1, u );
byte[] utf8 = ucs2_string_to_utf8_string( ucs2 );
bcopy(utf8, 0, result, j, STRING_LENGTH( utf8 ));
i += 4;
utf8shrink += (5 - STRING_LENGTH( utf8 ));
j += (STRING_LENGTH( utf8 ) - 1);
} else {
result[j] = cn;
}
} else {
result[j] = cn;
}
}
}
} else {
result[j] = cn;
}
}
break;
}
}
}
if( utf8shrink > 0 ) {
byte[] res = new byte[ size - utf8shrink ];
bcopy( result, 0, res, 0, size - utf8shrink );
return res;
} else {
return result;
}
}