public TR(ByteList bytes) { p = bytes.getBegin(); pend = bytes.getRealSize() + p; buf = bytes.getUnsafeBytes(); now = max = 0; gen = false; }
@JRubyMethod(name = {"update", "<<"}, required = 1) public IRubyObject update(IRubyObject obj) { ByteList bytes = obj.convertToString().getByteList(); algo.update(bytes.getUnsafeBytes(), bytes.getBegin(), bytes.getRealSize()); return this; }
@JRubyMethod(name = "eos?") public RubyBoolean eos_p(ThreadContext context) { check(); return pos >= str.getByteList().getRealSize() ? context.tru : context.fals; }
@JRubyMethod(name = "chop") public IRubyObject chop(ThreadContext context) { Ruby runtime = context.runtime; if (value.getRealSize() == 0) return newEmptyString(runtime, getMetaClass(), value.getEncoding()).infectBy(this); return makeShared(runtime, 0, StringSupport.choppedLength(this)); }
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 RubyString newStringShared(Ruby runtime, RubyClass clazz, ByteList bytes, Encoding encoding) { if (bytes.getEncoding() == encoding) return newStringShared(runtime, clazz, bytes); RubyString str = new RubyString(runtime, clazz, bytes.makeShared(bytes.getBegin(), bytes.getRealSize()), encoding); str.shareLevel = SHARE_LEVEL_BUFFER; // since passing an encoding in does bytes.setEncoding(encoding) return str; }
/** * This looks deceptively like tokadd_mbchar(int, ByteList) but it differs in that it uses * the bytelists encoding and the first parameter is a full codepoint and not the first byte * of a mbc sequence. */ public void tokaddmbc(int codepoint, ByteList buffer) { Encoding encoding = buffer.getEncoding(); int length = encoding.codeToMbcLength(codepoint); buffer.ensure(buffer.getRealSize() + length); encoding.codeToMbc(codepoint, buffer.getUnsafeBytes(), buffer.begin() + buffer.getRealSize()); buffer.setRealSize(buffer.getRealSize() + length); }
@Override public ByteList gets() { IRubyObject result = io.callMethod(io.getRuntime().getCurrentContext(), "gets"); if (result.isNil()) return null; ByteList bytelist = result.convertToString().getByteList(); offset += bytelist.getRealSize(); bytelist.setEncoding(encoding); if (scriptLines != null) scriptLines.append(RubyString.newString(scriptLines.getRuntime(), bytelist)); return bytelist; }
private static int glob_helper(Ruby runtime, String cwd, ByteList path, int sub, int flags, GlobFunc<GlobArgs> func, GlobArgs arg) { final int begin = path.getBegin(); final int end = begin + path.getRealSize(); final Encoding enc = path.getEncoding(); return glob_helper(runtime, cwd, path.getUnsafeBytes(), begin, end, enc, sub, flags, func, arg); }
@JRubyMethod(name = "rest?") public RubyBoolean rest_p(ThreadContext context) { check(); return pos >= str.getByteList().getRealSize() ? context.fals : context.tru; }
public ConvertBytes(Ruby runtime, ByteList str, int base, boolean badcheck) { this.runtime = runtime; this.str = str; this.beg = str.getBegin(); this.data = str.getUnsafeBytes(); this.end = beg + str.getRealSize(); this.badcheck = badcheck; this.base = base; }
@JRubyMethod(name = {"succ", "next"}) public IRubyObject succ(ThreadContext context) { Ruby runtime = context.runtime; final RubyString str; if (value.getRealSize() > 0) { str = new RubyString(runtime, getMetaClass(), StringSupport.succCommon(runtime, value)); // TODO: rescan code range ? } else { str = newEmptyString(runtime, getType(), value.getEncoding()); } return str.infectBy(this); }
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 RubyString newStringShared(Ruby runtime, RubyClass clazz, ByteList bytes, Encoding encoding) { if (bytes.getEncoding() == encoding) return newStringShared(runtime, clazz, bytes); RubyString str = new RubyString(runtime, clazz, bytes.makeShared(bytes.getBegin(), bytes.getRealSize()), encoding); str.shareLevel = SHARE_LEVEL_BUFFER; // since passing an encoding in does bytes.setEncoding(encoding) return str; }
/** * This looks deceptively like tokadd_mbchar(int, ByteList) but it differs in that it uses * the bytelists encoding and the first parameter is a full codepoint and not the first byte * of a mbc sequence. */ public void tokaddmbc(int codepoint, ByteList buffer) { Encoding encoding = buffer.getEncoding(); int length = encoding.codeToMbcLength(codepoint); buffer.ensure(buffer.getRealSize() + length); encoding.codeToMbc(codepoint, buffer.getUnsafeBytes(), buffer.begin() + buffer.getRealSize()); buffer.setRealSize(buffer.getRealSize() + length); }
@JRubyMethod(name = {"update", "<<"}, required = 1) public IRubyObject update(IRubyObject obj) { ByteList bytes = obj.convertToString().getByteList(); algo.update(bytes.getUnsafeBytes(), bytes.getBegin(), bytes.getRealSize()); return this; }
@JRubyMethod(name = "terminate") public IRubyObject terminate() { check(); pos = str.getByteList().getRealSize(); clearMatched(); return this; }
public static ByteList addByteLists(ByteList value1, ByteList value2) { ByteList result = new ByteList(value1.getRealSize() + value2.getRealSize()); result.setRealSize(value1.getRealSize() + value2.getRealSize()); System.arraycopy(value1.getUnsafeBytes(), value1.getBegin(), result.getUnsafeBytes(), 0, value1.getRealSize()); System.arraycopy(value2.getUnsafeBytes(), value2.getBegin(), result.getUnsafeBytes(), value1.getRealSize(), value2.getRealSize()); return result; }
@JRubyMethod(name = {"succ", "next"}, compat = RUBY1_9) public IRubyObject succ19(ThreadContext context) { Ruby runtime = context.runtime; final RubyString str; if (value.getRealSize() > 0) { str = new RubyString(runtime, getMetaClass(), succCommon19(value)); // TODO: rescan code range ? } else { str = newEmptyString(runtime, getType(), value.getEncoding()); } return str.infectBy(this); }
public StrNode(ISourcePosition position, StrNode head, StrNode tail) { super(position, false); ByteList headBL = head.getValue(); ByteList tailBL = tail.getValue(); ByteList myValue = new ByteList(headBL.getRealSize() + tailBL.getRealSize()); myValue.setEncoding(headBL.getEncoding()); myValue.append(headBL); myValue.append(tailBL); frozen = head.isFrozen() && tail.isFrozen(); value = myValue; codeRange = StringSupport.codeRangeScan(value.getEncoding(), value); }