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 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 int strLengthFromRubyString(CodeRangeable string, Encoding enc) { final ByteList bytes = string.getByteList(); if (isSingleByteOptimizable(string, enc)) return bytes.getRealSize(); return strLengthFromRubyStringFull(string, bytes, enc); }
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; }
/** * rb_enc_compatible */ public static Encoding areCompatible(CodeRangeable string, CodeRangeable other) { Encoding enc1 = string.getByteList().getEncoding(); Encoding enc2 = other.getByteList().getEncoding(); if (enc1 == enc2) return enc1; if (other.getByteList().getRealSize() == 0) return enc1; if (string.getByteList().getRealSize() == 0) { return (enc1.isAsciiCompatible() && isAsciiOnly(other)) ? enc1 : enc2; } if (!enc1.isAsciiCompatible() || !enc2.isAsciiCompatible()) return null; return RubyEncoding.areCompatible(enc1, string.scanForCodeRange(), enc2, other.scanForCodeRange()); }
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; }
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); }
/** * rb_enc_compatible */ public static Encoding areCompatible(CodeRangeable string, CodeRangeable other) { Encoding enc1 = string.getByteList().getEncoding(); Encoding enc2 = other.getByteList().getEncoding(); if (enc1 == enc2) return enc1; if (other.getByteList().getRealSize() == 0) return enc1; if (string.getByteList().getRealSize() == 0) { return (enc1.isAsciiCompatible() && isAsciiOnly(other)) ? enc1 : enc2; } if (!enc1.isAsciiCompatible() || !enc2.isAsciiCompatible()) return null; return RubyEncoding.areCompatible(enc1, string.scanForCodeRange(), enc2, other.scanForCodeRange()); }
public static boolean isAsciiOnly(CodeRangeable string) { return string.getByteList().getEncoding().isAsciiCompatible() && string.scanForCodeRange() == CR_7BIT; }
public static boolean isAsciiOnly(CodeRangeable string) { return string.getByteList().getEncoding().isAsciiCompatible() && string.scanForCodeRange() == CR_7BIT; }
public static int strLengthFromRubyString(CodeRangeable string) { final ByteList bytes = string.getByteList(); if (isSingleByteOptimizable(string, bytes.getEncoding())) return bytes.getRealSize(); return strLengthFromRubyStringFull(string, bytes, bytes.getEncoding()); }
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); } }
@Override public final Encoding checkEncoding(CodeRangeable other) { Encoding enc = StringSupport.areCompatible(this, other); if (enc == null) throw getRuntime().newEncodingCompatibilityError("incompatible character encodings: " + value.getEncoding() + " and " + other.getByteList().getEncoding()); return enc; }
@Override public final Encoding checkEncoding(CodeRangeable other) { Encoding enc = StringSupport.areCompatible(this, other); if (enc == null) throw getRuntime().newEncodingCompatibilityError("incompatible character encodings: " + value.getEncoding() + " and " + other.getByteList().getEncoding()); return enc; }
public static int strLengthFromRubyString(CodeRangeable string) { final ByteList bytes = string.getByteList(); if (isSingleByteOptimizable(string, bytes.getEncoding())) return bytes.getRealSize(); return strLengthFromRubyStringFull(string, bytes, bytes.getEncoding()); }
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); } }
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 ByteList replaceInternal(int beg, int len, ByteListHolder source, CodeRangeable repl) { int oldLength = source.getByteList().getRealSize(); if (beg + len >= oldLength) len = oldLength - beg; ByteList replBytes = repl.getByteList(); int replLength = replBytes.getRealSize(); int newLength = oldLength + replLength - len; byte[] oldBytes = source.getByteList().getUnsafeBytes(); int oldBegin = source.getByteList().getBegin(); source.modify(newLength); if (replLength != len) { System.arraycopy(oldBytes, oldBegin + beg + len, source.getByteList().getUnsafeBytes(), beg + replLength, oldLength - (beg + len)); } if (replLength > 0) System.arraycopy(replBytes.getUnsafeBytes(), replBytes.getBegin(), source.getByteList().getUnsafeBytes(), beg, replLength); source.getByteList().setRealSize(newLength); return source.getByteList(); }
public static ByteList replaceInternal(int beg, int len, ByteListHolder source, CodeRangeable repl) { int oldLength = source.getByteList().getRealSize(); if (beg + len >= oldLength) len = oldLength - beg; ByteList replBytes = repl.getByteList(); int replLength = replBytes.getRealSize(); int newLength = oldLength + replLength - len; byte[] oldBytes = source.getByteList().getUnsafeBytes(); int oldBegin = source.getByteList().getBegin(); source.modify(newLength); if (replLength != len) { System.arraycopy(oldBytes, oldBegin + beg + len, source.getByteList().getUnsafeBytes(), beg + replLength, oldLength - (beg + len)); } if (replLength > 0) System.arraycopy(replBytes.getUnsafeBytes(), replBytes.getBegin(), source.getByteList().getUnsafeBytes(), beg, replLength); source.getByteList().setRealSize(newLength); return source.getByteList(); }
/** * MRI: chopped_length */ public static int choppedLength(CodeRangeable str) { ByteList bl = str.getByteList(); Encoding enc = bl.getEncoding(); int p, p2, beg, end; beg = bl.begin(); end = beg + bl.realSize(); if (beg > end) return 0; p = enc.prevCharHead(bl.unsafeBytes(), beg, end, end); if (p == 0) return 0; if (p > beg && EncodingUtils.encAscget(bl.unsafeBytes(), p, end, null, enc) == '\n') { p2 = enc.prevCharHead(bl.unsafeBytes(), beg, p, end); if (p2 != -1 && EncodingUtils.encAscget(bl.unsafeBytes(), p2, end, null, enc) == '\r') p = p2; } return p - beg; }