int r = preciseLength(enc, bytes, p, p + len), c; if (!MBCLEN_CHARFOUND_P(r)) { return NeighborChar.NOT_CHAR; c = codePoint(enc, bytes, p, p + len) + 1; l = codeLength(enc, c); if (l == 0) return NeighborChar.NOT_CHAR; if (l != len) return NeighborChar.WRAPPED; EncodingUtils.encMbcput(c, bytes, p, enc); r = preciseLength(enc, bytes, p, p + len); if (!MBCLEN_CHARFOUND_P(r)) { return NeighborChar.NOT_CHAR; if (i < 0) return NeighborChar.WRAPPED; bytes[p + i] = (byte)((bytes[p + i] & 0xff) + 1); l = preciseLength(enc, bytes, p, p + len); if (MBCLEN_CHARFOUND_P(l)) { l = MBCLEN_CHARFOUND_LEN(l); if (l == len) { return NeighborChar.FOUND; if (MBCLEN_INVALID_P(l) && i < len - 1) { int len2; int l2; for (len2 = len-1; 0 < len2; len2--) { l2 = preciseLength(enc, bytes, p, p + len2); if (!MBCLEN_INVALID_P(l2)) break;
oc = obytes[op] & 0xff; } else { c = preciseCodePoint(enc, bytes, p, end); oc = preciseCodePoint(enc, obytes, op, oend); cl = ocl = 1; } else { cl = preciseLength(enc, bytes, p, end); ocl = preciseLength(enc, obytes, op, oend); cl = length(enc, bytes, p, end); ocl = length(enc, obytes, op, oend); int ret = caseCmp(bytes, p, obytes, op, cl < ocl ? cl : ocl); if (ret != 0) return ret < 0 ? -1 : 1; if (cl != ocl) return cl < ocl ? -1 : 1;
@Override public Object object(Object parameter) { if (checkStringSafety) StringSupport.checkStringSafety(((IRubyObject) parameter).getRuntime(), (IRubyObject) parameter); return ((RubyString) parameter).getByteList().unsafeBytes(); }
public static int encCodepointLength(byte[] pBytes, int p, int e, int[] len_p, Encoding enc) { int r; if (e <= p) throw new IllegalArgumentException("empty string"); r = StringSupport.preciseLength(enc, pBytes, p, e); if (!StringSupport.MBCLEN_CHARFOUND_P(r)) { throw new IllegalArgumentException("invalid byte sequence in " + enc); } if (len_p != null) len_p[0] = StringSupport.MBCLEN_CHARFOUND_LEN(r); return StringSupport.codePoint(enc, pBytes, p, e); }
public static int codeRangeScan(Encoding enc, byte[]bytes, int p, int len) { if (enc == ASCIIEncoding.INSTANCE) { return searchNonAscii(bytes, p, p + len) != -1 ? CR_VALID : CR_7BIT; } if (enc.isAsciiCompatible()) { return codeRangeScanAsciiCompatible(enc, bytes, p, len); } return codeRangeScanNonAsciiCompatible(enc, bytes, p, len); }
public static int length(Encoding enc, byte[]bytes, int p, int end) { int n = enc.length(bytes, p, end); if (MBCLEN_CHARFOUND_P(n) && MBCLEN_CHARFOUND_LEN(n) <= end - p) return MBCLEN_CHARFOUND_LEN(n); int min = enc.minLength(); return min <= end - p ? min : end - p; }
r = preciseLength(read_enc, cbuf.ptr, cbuf.off, cbuf.off + cbuf.len); if (!StringSupport.MBCLEN_NEEDMORE_P(r)) break; if (cbuf.len == cbuf.capa) { if (StringSupport.MBCLEN_INVALID_P(r)) { r = read_enc.length(cbuf.ptr, cbuf.off, cbuf.off + cbuf.len); str = shiftCbuf(context, r, str); cr = StringSupport.CR_BROKEN; } else { str = shiftCbuf(context, StringSupport.MBCLEN_CHARFOUND_LEN(r), str); cr = StringSupport.CR_VALID; if (StringSupport.MBCLEN_CHARFOUND_LEN(r) == 1 && read_enc.isAsciiCompatible() && Encoding.isAscii(((RubyString) str).getByteList().get(0))) { cr = StringSupport.CR_7BIT; r = preciseLength(enc, rbuf.ptr, rbuf.off, rbuf.off + rbuf.len); if (StringSupport.MBCLEN_CHARFOUND_P(r) && (n = StringSupport.MBCLEN_CHARFOUND_LEN(r)) <= rbuf.len) { str = RubyString.newString(runtime, rbuf.ptr, rbuf.off, n); rbuf.off += n; else if (StringSupport.MBCLEN_NEEDMORE_P(r)) { str = RubyString.newString(runtime, rbuf.ptr, rbuf.off, rbuf.len); rbuf.len = 0; rbuf.len--; ByteList strByteList = ((RubyString) str).getByteList(); r = preciseLength(enc, strByteList.unsafeBytes(), strByteList.getBegin(), strByteList.getBegin() + strByteList.length());
if (fptr.cbuf.len != 0) { if (fptr.encs.enc != null) r = StringSupport.preciseLength(fptr.encs.enc, fptr.cbuf.ptr, fptr.cbuf.off, fptr.cbuf.off + fptr.cbuf.len); else r = StringSupport.CONSTRUCT_MBCLEN_CHARFOUND(1); if (!StringSupport.MBCLEN_NEEDMORE_P(r)) break; if (fptr.cbuf.len == fptr.cbuf.capa) { if (!StringSupport.MBCLEN_CHARFOUND_P(r)) { enc = fptr.encs.enc; throw runtime.newArgumentError("invalid byte sequence in " + enc); if (StringSupport.MBCLEN_INVALID_P(r)) { enc = fptr.encs.enc; throw runtime.newArgumentError("invalid byte sequence in " + enc); n = StringSupport.MBCLEN_CHARFOUND_LEN(r); if (fptr.encs.enc != null) { c = StringSupport.codePoint(runtime, fptr.encs.enc, fptr.cbuf.ptr, fptr.cbuf.off, fptr.cbuf.off + fptr.cbuf.len); enc = fptr.inputEncoding(runtime); while (fptr.fillbuf(context) >= 0) { r = StringSupport.preciseLength(enc, fptr.rbuf.ptr, fptr.rbuf.off, fptr.rbuf.off + fptr.rbuf.len); if (StringSupport.MBCLEN_CHARFOUND_P(r) && (n = StringSupport.MBCLEN_CHARFOUND_LEN(r)) <= fptr.rbuf.len) { c = StringSupport.codePoint(runtime, fptr.encs.enc, fptr.rbuf.ptr, fptr.rbuf.off, fptr.rbuf.off + fptr.rbuf.len); fptr.rbuf.off += n; fptr.rbuf.len -= n;
r = StringSupport.preciseLength(read, bytes.getUnsafeBytes(), 0, bytes.getRealSize()); if (!StringSupport.MBCLEN_NEEDMORE_P(r)) { if (StringSupport.MBCLEN_INVALID_P(r)) { r = StringSupport.length(read, bytes.getUnsafeBytes(), 0, bytes.getRealSize()); } else { cr = StringSupport.CR_VALID; if (StringSupport.MBCLEN_CHARFOUND_LEN(r) == 1 && read.isAsciiCompatible() && Encoding.isAscii(bytes.get(0))) { cr = StringSupport.CR_7BIT;
private IRubyObject multiByteLStrip(ThreadContext context, Encoding enc, byte[]bytes, int s, int end) { final Ruby runtime = context.runtime; int p = s; while (p < end) { int c = codePoint(runtime, enc, bytes, p, end); if (!ASCII.isSpace(c)) break; p += codeLength(enc, c); } if (p > s) { view(p - s, end - p); return this; } return context.nil; }
oc = obytes[op] & 0xff; } else { c = StringSupport.preciseCodePoint(enc, bytes, p, end); oc = StringSupport.preciseCodePoint(enc, obytes, op, oend); cl = StringSupport.length(enc, bytes, p, end); ocl = StringSupport.length(enc, obytes, op, oend); int ret = StringSupport.caseCmp(bytes, p, obytes, op, cl < ocl ? cl : ocl); if (ret != 0) return ret < 0 ? RubyFixnum.minus_one(runtime) : RubyFixnum.one(runtime); if (cl != ocl) return cl < ocl ? RubyFixnum.minus_one(runtime) : RubyFixnum.one(runtime);
private IRubyObject multiByteSwapcase(Ruby runtime, Encoding enc, byte[]bytes, int s, int end) { boolean modify = false; while (s < end) { int c = codePoint(runtime, enc, bytes, s, end); if (enc.isUpper(c)) { enc.codeToMbc(toLower(enc, c), bytes, s); modify = true; } else if (enc.isLower(c)) { enc.codeToMbc(toUpper(enc, c), bytes, s); modify = true; } s += codeLength(runtime, enc, c); } return modify ? this : runtime.getNil(); }
while (chLen < enc.maxLength() && StringSupport.MBCLEN_NEEDMORE_P(StringSupport.preciseLength(enc, chBuf, 0, chLen))) { p = readEscapedByte(runtime, chBuf, chLen++, bytes, p, end, str, mode); int cl = StringSupport.preciseLength(enc, chBuf, 0, chLen); if (cl == -1) { raisePreprocessError(runtime, str, "invalid multibyte escape", mode); // MBCLEN_INVALID_P
private boolean is7BitASCII(ByteList value) { return StringSupport.codeRangeScan(value.getEncoding(), value) == StringSupport.CR_7BIT; }
private void fixBrokenTrailingCharacter(ByteList result) throws IOException { // fix broken trailing character int extraBytes = StringSupport.bytesToFixBrokenTrailingCharacter(result.getUnsafeBytes(), result.getBegin(), result.getRealSize(), getReadEncoding(), result.length()); for (int i = 0; i < extraBytes; i++) { int read = bufferedStream.read(); if (read == -1) break; result.append(read); } }
int c, cc; int n = enc.length(pBytes, p, pend); if (!MBCLEN_CHARFOUND_P(n)) { if (p > prev) result.cat(pBytes, prev, p - prev); n = enc.minLength(); n = MBCLEN_CHARFOUND_LEN(n); c = enc.mbcToCode(pBytes, p, pend); p += n; if (p - n > prev) result.cat(pBytes, prev, p - n - prev); result.modify(); Sprintf.sprintf(runtime, result.getByteList(), StringSupport.escapedCharFormat(c, unicode_p), (c & 0xFFFFFFFFL)); prev = p;
public static int codePoint(Ruby runtime, Encoding enc, byte[] bytes, int p, int end) { try { return codePoint(enc, bytes, p, end); } catch (IllegalArgumentException e) { throw runtime.newArgumentError(e.getMessage()); } }
public static int encAscget(byte[] bytes, int offset, int end, int[] chlen, Encoding enc) { int c; int l; if (enc.isAsciiCompatible()) { c = bytes[offset]; if (!Encoding.isAscii((byte)c)) { return -1; } if (chlen != null) chlen[0] = 1; return c; } l = StringSupport.preciseLength(enc, bytes, offset, end); if (StringSupport.MBCLEN_CHARFOUND_LEN(l) == 0) { return -1; } c = enc.mbcToCode(bytes, offset, end); if (!Encoding.isAscii(c)) { return -1; } if (chlen != null) chlen[0] = 1; return c; }
int n = StringSupport.preciseLength(enc, pBytes, p, pend); if (!StringSupport.MBCLEN_CHARFOUND_P(n)) { if (p > prev) result.cat(pBytes, prev, p - prev); n = enc.minLength(); n = StringSupport.MBCLEN_CHARFOUND_LEN(n); c = enc.mbcToCode(pBytes, p, pend); p += n;
public final RubyString cat(int code, Encoding enc) { int n = codeLength(enc, code); modify(value.getRealSize() + n); enc.codeToMbc(code, value.getUnsafeBytes(), value.getBegin() + value.getRealSize()); value.setRealSize(value.getRealSize() + n); return this; }