public static void replaceInternal19(int beg, int len, CodeRangeable source, CodeRangeable repl) { Encoding enc = source.checkEncoding(repl); source.modify(); source.keepCodeRange(); ByteList sourceBL = source.getByteList(); byte[] sourceBytes = sourceBL.unsafeBytes(); int sourceBeg = sourceBL.begin(); int sourceEnd = sourceBeg + sourceBL.realSize(); boolean singlebyte = isSingleByteOptimizable(source, source.getByteList().getEncoding()); int p = nth(enc, sourceBytes, sourceBeg, sourceEnd, beg, singlebyte); if (p == -1) p = sourceEnd; int e = nth(enc, sourceBytes, p, sourceEnd, len, singlebyte); if (e == -1) e = sourceEnd; /* error check */ beg = p - sourceBeg; /* physical position */ len = e - p; /* physical length */ replaceInternal(beg, len, source, repl); associateEncoding(source, enc); int cr = CodeRangeSupport.codeRangeAnd(source.getCodeRange(), repl.getCodeRange()); if (cr != CR_BROKEN) source.setCodeRange(cr); }
public static void associateEncoding(CodeRangeable string, Encoding enc) { final ByteList value = string.getByteList(); if (value.getEncoding() != enc) { if (!CodeRangeSupport.isCodeRangeAsciiOnly(string) || !enc.isAsciiCompatible()) string.clearCodeRange(); value.setEncoding(enc); } }
private static int strLengthFromRubyStringFull(CodeRangeable string, ByteList bytes, Encoding enc) { if (string.isCodeRangeValid() && enc.isUTF8()) return utf8Length(bytes); long lencr = strLengthWithCodeRange(bytes, enc); int cr = unpackArg(lencr); if (cr != 0) string.setCodeRange(cr); return unpackResult(lencr); }
public static boolean areComparableViaCodeRange(CodeRangeable string, CodeRangeable other) { int cr1 = string.scanForCodeRange(); int cr2 = other.scanForCodeRange(); if (cr1 == CR_7BIT && (cr2 == CR_7BIT || other.getByteList().getEncoding().isAsciiCompatible())) return true; if (cr2 == CR_7BIT && string.getByteList().getEncoding().isAsciiCompatible()) return true; return false; }
final ByteList srcList = srcStr.getByteList(); final ByteList replList = replStr.getByteList(); int cr = self.getCodeRange(); Encoding e1 = self.checkEncoding(srcStr); Encoding e2 = self.checkEncoding(replStr); Encoding enc = e1 == e2 ? e1 : srcStr.checkEncoding(replStr); if (srcStr.getByteList().getRealSize() > 1 && EncodingUtils.encAscget(trSrc.buf, trSrc.p, trSrc.pend, l, enc) == '^' && trSrc.p + 1 < trSrc.pend){ self.modifyAndKeepCodeRange(); int s = self.getByteList().getBegin(); int send = s + self.getByteList().getRealSize(); byte sbytes[] = self.getByteList().getUnsafeBytes(); int max = self.getByteList().getRealSize(); int save = -1; byte[] buf = new byte[max]; self.getByteList().setUnsafeBytes(buf); self.getByteList().setRealSize(t); } else if (enc.isSingleByte() || (singlebyte && hash == null)) { while (s < send) { int clen, tlen, max = (int)(self.getByteList().realSize() * 1.2); byte[] buf = new byte[max]; int t = 0;
rubyString.modify(); rubyString.keepCodeRange(); final ByteList value = rubyString.getByteList(); rubyString.setCodeRange(cr);
public static int encCrStrBufCat(Ruby runtime, CodeRangeable str, byte[] ptrBytes, int ptr, int len, Encoding ptrEnc, int ptr_cr) { Encoding strEnc = str.getByteList().getEncoding(); Encoding resEnc; int str_cr, res_cr; boolean incompatible = false; str_cr = str.getByteList().getRealSize() > 0 ? str.getCodeRange() : StringSupport.CR_7BIT; if (!EncodingUtils.encAsciicompat(strEnc) || !EncodingUtils.encAsciicompat(ptrEnc)) { if (len == 0) return ptr_cr; if (str.getByteList().getRealSize() == 0) { strBufCat(runtime, str, ptrBytes, ptr, len); str.getByteList().setEncoding(ptrEnc); str.setCodeRange(ptr_cr); return ptr_cr; str_cr = str.scanForCodeRange(); str.getByteList().setEncoding(resEnc); str.setCodeRange(res_cr);
public static boolean areComparable(CodeRangeable string, CodeRangeable other) { ByteList otherValue = other.getByteList(); if (string.getByteList().getEncoding() == otherValue.getEncoding() || string.getByteList().getRealSize() == 0 || otherValue.getRealSize() == 0) return true; return areComparableViaCodeRange(string, other); }
public static boolean isCodeRangeAsciiOnly(CodeRangeable string) { return string.getCodeRange() == CR_7BIT; }
public static int strLengthFromRubyString(CodeRangeable string, final ByteList bytes, final Encoding enc) { if (isSingleByteOptimizable(string, enc)) return bytes.getRealSize(); // NOTE: strLengthFromRubyStringFull but without string.setCodeRange(..) if (string.isCodeRangeValid() && enc.isUTF8()) return utf8Length(bytes); long lencr = strLengthWithCodeRange(bytes, enc); return unpackResult(lencr); }
final ByteList srcList = srcStr.getByteList(); final ByteList replList = replStr.getByteList(); int cr = self.getCodeRange(); Encoding e1 = self.checkEncoding(srcStr); Encoding e2 = self.checkEncoding(replStr); Encoding enc = e1 == e2 ? e1 : srcStr.checkEncoding(replStr); if (srcStr.getByteList().getRealSize() > 1 && EncodingUtils.encAscget(trSrc.buf, trSrc.p, trSrc.pend, l, enc) == '^' && trSrc.p + 1 < trSrc.pend){ self.modifyAndKeepCodeRange(); int s = self.getByteList().getBegin(); int send = s + self.getByteList().getRealSize(); byte sbytes[] = self.getByteList().getUnsafeBytes(); int max = self.getByteList().getRealSize(); int save = -1; byte[] buf = new byte[max]; self.getByteList().setUnsafeBytes(buf); self.getByteList().setRealSize(t); } else if (enc.isSingleByte() || (singlebyte && hash == null)) { while (s < send) { int clen, tlen, max = (int)(self.getByteList().realSize() * 1.2); byte[] buf = new byte[max]; int t = 0;
public static boolean areComparableViaCodeRange(CodeRangeable string, CodeRangeable other) { int cr1 = string.scanForCodeRange(); int cr2 = other.scanForCodeRange(); if (cr1 == CR_7BIT && (cr2 == CR_7BIT || other.getByteList().getEncoding().isAsciiCompatible())) return true; if (cr2 == CR_7BIT && string.getByteList().getEncoding().isAsciiCompatible()) return true; return false; }
rubyString.modify(); rubyString.keepCodeRange(); final ByteList value = rubyString.getByteList(); rubyString.setCodeRange(cr);
public static int encCrStrBufCat(Ruby runtime, CodeRangeable str, byte[] ptrBytes, int ptr, int len, Encoding ptrEnc, int ptr_cr) { Encoding strEnc = str.getByteList().getEncoding(); Encoding resEnc; int str_cr, res_cr; boolean incompatible = false; str_cr = str.getByteList().getRealSize() > 0 ? str.getCodeRange() : StringSupport.CR_7BIT; if (!EncodingUtils.encAsciicompat(strEnc) || !EncodingUtils.encAsciicompat(ptrEnc)) { if (len == 0) return ptr_cr; if (str.getByteList().getRealSize() == 0) { strBufCat(runtime, str, ptrBytes, ptr, len); str.getByteList().setEncoding(ptrEnc); str.setCodeRange(ptr_cr); return ptr_cr; str_cr = str.scanForCodeRange(); str.getByteList().setEncoding(resEnc); str.setCodeRange(res_cr);
public static boolean areComparable(CodeRangeable string, CodeRangeable other) { ByteList otherValue = other.getByteList(); if (string.getByteList().getEncoding() == otherValue.getEncoding() || string.getByteList().getRealSize() == 0 || otherValue.getRealSize() == 0) return true; return areComparableViaCodeRange(string, other); }
public static boolean isCodeRangeAsciiOnly(CodeRangeable string) { return string.getCodeRange() == CR_7BIT; }
public static int strLengthFromRubyString(CodeRangeable string, final ByteList bytes, final Encoding enc) { if (isSingleByteOptimizable(string, enc)) return bytes.getRealSize(); // NOTE: strLengthFromRubyStringFull but without string.setCodeRange(..) if (string.isCodeRangeValid() && enc.isUTF8()) return utf8Length(bytes); long lencr = strLengthWithCodeRange(bytes, enc); return unpackResult(lencr); }
public static void replaceInternal19(int beg, int len, CodeRangeable source, CodeRangeable repl) { Encoding enc = source.checkEncoding(repl); source.modify(); source.keepCodeRange(); ByteList sourceBL = source.getByteList(); byte[] sourceBytes = sourceBL.unsafeBytes(); int sourceBeg = sourceBL.begin(); int sourceEnd = sourceBeg + sourceBL.realSize(); boolean singlebyte = isSingleByteOptimizable(source, source.getByteList().getEncoding()); int p = nth(enc, sourceBytes, sourceBeg, sourceEnd, beg, singlebyte); if (p == -1) p = sourceEnd; int e = nth(enc, sourceBytes, p, sourceEnd, len, singlebyte); if (e == -1) e = sourceEnd; /* error check */ beg = p - sourceBeg; /* physical position */ len = e - p; /* physical length */ replaceInternal(beg, len, source, repl); associateEncoding(source, enc); int cr = CodeRangeSupport.codeRangeAnd(source.getCodeRange(), repl.getCodeRange()); if (cr != CR_BROKEN) source.setCodeRange(cr); }
public static boolean isAsciiOnly(CodeRangeable string) { return string.getByteList().getEncoding().isAsciiCompatible() && string.scanForCodeRange() == CR_7BIT; }
public static int strLengthFromRubyString(CodeRangeable string, Encoding enc) { final ByteList bytes = string.getByteList(); if (isSingleByteOptimizable(string, enc)) return bytes.getRealSize(); return strLengthFromRubyStringFull(string, bytes, enc); }