final boolean singleByteOptimizable(Encoding enc) { return StringSupport.isSingleByteOptimizable(this, enc); }
final boolean singleByteOptimizable(Encoding enc) { return StringSupport.isSingleByteOptimizable(this, enc); }
final boolean singleByteOptimizable() { return StringSupport.isSingleByteOptimizable(this, EncodingUtils.STR_ENC_GET(this)); }
final boolean singleByteOptimizable() { return StringSupport.isSingleByteOptimizable(this, EncodingUtils.STR_ENC_GET(this)); }
public int rbStrOffset(int pos) { return strOffset(pos, isSingleByteOptimizable(this, getEncoding())); }
public int rbStrOffset(int pos) { return strOffset(pos, isSingleByteOptimizable(this, getEncoding())); }
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 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 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 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 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 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); }
@Override public IRubyObject size(IRubyObject[] args) { Ruby runtime = getRuntime(); ByteList value = getByteList(); Encoding enc = value.getEncoding(); if (!enc.isUnicode() || isSingleByteOptimizable(RubyString.this, enc)) return rubyLength(runtime); Regex reg = RubyRegexp.getRegexpFromCache(runtime, GRAPHEME_CLUSTER_PATTERN, enc, RegexpOptions.NULL_OPTIONS); int beg = value.getBegin(); int end = beg + value.getRealSize(); Matcher matcher = reg.matcher(value.getUnsafeBytes(), beg, end); int count = 0; while (beg < end) { int len = matcher.match(beg, end, Option.DEFAULT); if (len <= 0) break; count++; beg += len; } return RubyFixnum.newFixnum(runtime, count); } };
@Override public IRubyObject size(IRubyObject[] args) { Ruby runtime = getRuntime(); ByteList value = getByteList(); Encoding enc = value.getEncoding(); if (!enc.isUnicode() || isSingleByteOptimizable(RubyString.this, enc)) return rubyLength(runtime); Regex reg = RubyRegexp.getRegexpFromCache(runtime, GRAPHEME_CLUSTER_PATTERN, enc, RegexpOptions.NULL_OPTIONS); int beg = value.getBegin(); int end = beg + value.getRealSize(); Matcher matcher = reg.matcher(value.getUnsafeBytes(), beg, end); int count = 0; while (beg < end) { int len = matcher.match(beg, end, Option.DEFAULT); if (len <= 0) break; count++; beg += len; } return RubyFixnum.newFixnum(runtime, count); } };
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; } }
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 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); }
RubyString str = this; Encoding enc = str.getEncoding(); if (!enc.isUnicode() || isSingleByteOptimizable(str, enc)) { return enumerateChars(context, name, block, wantarray);
RubyString str = this; Encoding enc = str.getEncoding(); if (!enc.isUnicode() || isSingleByteOptimizable(str, enc)) { return enumerateChars(context, name, block, wantarray);