public boolean isGlobal() { return _isGlobal; }
public boolean ignoreCase() { return _ignoreCase; }
static StringValue fromUtf8(StringValue source)
{
StringValue target = new UnicodeBuilderValue();
int len = source.length();
for (int i = 0; i < len; i++) {
char ch = source.charAt(i);
if (ch < 0x80) {
target.append(ch);
}
else if ((ch & 0xe0) == 0xc0) {
if (len <= i + 1) {
log.fine(L.l("Regexp: bad UTF-8 sequence, saw EOF"));
return null;
}
char ch2 = source.charAt(++i);
target.append((char) (((ch & 0x1f) << 6)
+ (ch2 & 0x3f)));
}
else if ((ch & 0xf0) == 0xe0) {
if (len <= i + 2) {
log.fine(L.l("Regexp: bad UTF-8 sequence, saw EOF"));
return null;
}
char ch2 = source.charAt(++i);
char ch3 = source.charAt(++i);
target.append((char) (((ch & 0x0f) << 12)
+ ((ch2 & 0x3f) << 6)
+ (ch3 & 0x3f)));
}
else {
if (i + 3 >= len) {
log.fine(L.l("Regexp: bad UTF-8 sequence, saw EOF"));
return null;
}
char ch2 = source.charAt(++i);
char ch3 = source.charAt(++i);
char ch4 = source.charAt(++i);
int codePoint = ((ch & 0x07) << 18)
+ ((ch2 & 0x3F) << 12)
+ ((ch3 & 0x3F) << 6)
+ (ch4 & 0x3F);
int high = ((codePoint - 0x10000) >> 10) + 0xD800;
int low = (codePoint & 0x3FF) + 0xDC00;
target.append((char) high);
target.append((char) low);
}
}
return target;
}