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 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 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; }
/** * 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()); }
/** * 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 int rindex(ByteList source, int sourceChars, int subChars, int pos, CodeRangeable subStringCodeRangeable, Encoding enc) { if (subStringCodeRangeable.scanForCodeRange() == CR_BROKEN) return -1; final ByteList subString = subStringCodeRangeable.getByteList(); final int srcLen = source.getRealSize(); final int subLen = subString.getRealSize(); if (sourceChars < subChars || srcLen < subLen) return -1; if (sourceChars - pos < subChars) pos = sourceChars - subChars; if (sourceChars == 0) return pos; byte[] srcBytes = source.getUnsafeBytes(); final int srcBeg = source.getBegin(); if (pos == 0) { if (ByteList.memcmp(srcBytes, srcBeg, subString.getUnsafeBytes(), subString.getBegin(), subLen) == 0) { return 0; } return -1; } int s = nth(enc, srcBytes, srcBeg, srcBeg + srcLen, pos); return strRindex(srcBytes, srcBeg, srcLen, subString.getUnsafeBytes(), subString.getBegin(), subLen, s, pos, enc); }
public static int rindex(ByteList source, int sourceChars, int subChars, int pos, CodeRangeable subStringCodeRangeable, Encoding enc) { if (subStringCodeRangeable.scanForCodeRange() == CR_BROKEN) return -1; final ByteList subString = subStringCodeRangeable.getByteList(); final int srcLen = source.getRealSize(); final int subLen = subString.getRealSize(); if (sourceChars < subChars || srcLen < subLen) return -1; if (sourceChars - pos < subChars) pos = sourceChars - subChars; if (sourceChars == 0) return pos; byte[] srcBytes = source.getUnsafeBytes(); final int srcBeg = source.getBegin(); if (pos == 0) { if (ByteList.memcmp(srcBytes, srcBeg, subString.getUnsafeBytes(), subString.getBegin(), subLen) == 0) { return 0; } return -1; } int s = nth(enc, srcBytes, srcBeg, srcBeg + srcLen, pos); return strRindex(srcBytes, srcBeg, srcLen, subString.getUnsafeBytes(), subString.getBegin(), subLen, s, pos, enc); }
public static int index(CodeRangeable sourceString, CodeRangeable otherString, int offset, Encoding enc) { if (otherString.scanForCodeRange() == CR_BROKEN) return -1; int sourceLen = strLengthFromRubyString(sourceString); int otherLen = strLengthFromRubyString(otherString); if (offset < 0) { offset += sourceLen; if (offset < 0) return -1; } final ByteList source = sourceString.getByteList(); final ByteList other = otherString.getByteList(); if (sourceLen - offset < otherLen) return -1; byte[] bytes = source.getUnsafeBytes(); int p = source.getBegin(); int end = p + source.getRealSize(); if (offset != 0) { offset = isSingleByteOptimizable(sourceString, enc) ? offset : offset(enc, bytes, p, end, offset); p += offset; } if (otherLen == 0) return offset; while (true) { int pos = source.indexOf(other, p - source.getBegin()); if (pos < 0) return pos; pos -= (p - source.getBegin()); int t = enc.rightAdjustCharHead(bytes, p, p + pos, end); if (t == p + pos) return pos + offset; if ((sourceLen -= t - p) <= 0) return -1; offset += t - p; p = t; } }
public static int index(CodeRangeable sourceString, CodeRangeable otherString, int offset, Encoding enc) { if (otherString.scanForCodeRange() == CR_BROKEN) return -1; int sourceLen = strLengthFromRubyString(sourceString); int otherLen = strLengthFromRubyString(otherString); if (offset < 0) { offset += sourceLen; if (offset < 0) return -1; } final ByteList source = sourceString.getByteList(); final ByteList other = otherString.getByteList(); if (sourceLen - offset < otherLen) return -1; byte[] bytes = source.getUnsafeBytes(); int p = source.getBegin(); int end = p + source.getRealSize(); if (offset != 0) { offset = isSingleByteOptimizable(sourceString, enc) ? offset : offset(enc, bytes, p, end, offset); p += offset; } if (otherLen == 0) return offset; while (true) { int pos = source.indexOf(other, p - source.getBegin()); if (pos < 0) return pos; pos -= (p - source.getBegin()); int t = enc.rightAdjustCharHead(bytes, p, p + pos, end); if (t == p + pos) return pos + offset; if ((sourceLen -= t - p) <= 0) return -1; offset += t - p; p = t; } }
str_cr = str.scanForCodeRange();
str_cr = str.scanForCodeRange();