private Encoding getEncodingForKCodeDefault(Ruby runtime, Regex pattern, IRubyObject pat) { Encoding enc = pattern.getEncoding(); if (enc != runtime.getKCode().getEncoding() && pat instanceof RubyRegexp) { RubyRegexp regexp = (RubyRegexp) pat; if (regexp.isKCodeDefault()) { enc = runtime.getKCode().getEncoding(); } } return enc; }
private Encoding getEncodingForKCodeDefault(Ruby runtime, Regex pattern, IRubyObject pat) { Encoding enc = pattern.getEncoding(); if (enc != runtime.getKCode().getEncoding() && pat instanceof RubyRegexp) { RubyRegexp regexp = (RubyRegexp) pat; if (regexp.isKCodeDefault()) { enc = runtime.getKCode().getEncoding(); } } return enc; }
private Encoding getEncoding(Ruby runtime, ByteList str) { if (runtime.is1_9()) return str.getEncoding(); // Whatever $KCODE is we should use if (options.isKcodeDefault()) return runtime.getKCode().getEncoding(); return options.getKCode().getEncoding(); }
private Encoding getEncoding(Ruby runtime, ByteList str) { if (runtime.is1_9()) return str.getEncoding(); // Whatever $KCODE is we should use if (options.isKcodeDefault()) return runtime.getKCode().getEncoding(); return options.getKCode().getEncoding(); }
private RubyRegexp initializeCommon(ByteList bytes, RegexpOptions newOptions) { Ruby runtime = getRuntime(); // Options needs a little more set up. checkFrozen(); if (isLiteral()) throw runtime.newSecurityError("can't modify literal regexp"); options = newOptions; pattern = getRegexpFromCache(runtime, bytes, options.getKCode().getEncoding(), options); bytes.getClass(); str = bytes; return this; }
private RubyRegexp initializeCommon(ByteList bytes, RegexpOptions newOptions) { Ruby runtime = getRuntime(); // Options needs a little more set up. checkFrozen(); if (isLiteral()) throw runtime.newSecurityError("can't modify literal regexp"); options = newOptions; pattern = getRegexpFromCache(runtime, bytes, options.getKCode().getEncoding(), options); bytes.getClass(); str = bytes; return this; }
private Regex getQuotedPattern(IRubyObject obj) { if (obj instanceof RubyRegexp) return ((RubyRegexp)obj).getPattern(); Ruby runtime = getRuntime(); return RubyRegexp.getQuotedRegexpFromCache(runtime, getStringForPattern(obj).value, runtime.getKCode().getEncoding(), new RegexpOptions()); }
private Regex getQuotedPattern(IRubyObject obj) { if (obj instanceof RubyRegexp) return ((RubyRegexp)obj).getPattern(); Ruby runtime = getRuntime(); return RubyRegexp.getQuotedRegexpFromCache(runtime, getStringForPattern(obj).value, runtime.getKCode().getEncoding(), new RegexpOptions()); }
/** rb_reg_s_quote * */ @JRubyMethod(name = {"quote", "escape"}, required = 1, optional = 1, meta = true, compat = CompatVersion.RUBY1_8) public static RubyString quote(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; final KCode code; if (args.length == 1 || args[1].isNil()) { code = runtime.getKCode(); } else { code = KCode.create(runtime, args[1].toString()); } RubyString src = args[0].convertToString(); RubyString dst = RubyString.newStringShared(runtime, quote(src.getByteList(), code.getEncoding())); dst.infectBy(src); return dst; }
/** rb_reg_s_quote * */ @JRubyMethod(name = {"quote", "escape"}, required = 1, optional = 1, meta = true, compat = CompatVersion.RUBY1_8) public static RubyString quote(ThreadContext context, IRubyObject recv, IRubyObject[] args) { Ruby runtime = context.runtime; final KCode code; if (args.length == 1 || args[1].isNil()) { code = runtime.getKCode(); } else { code = KCode.create(runtime, args[1].toString()); } RubyString src = args[0].convertToString(); RubyString dst = RubyString.newStringShared(runtime, quote(src.getByteList(), code.getEncoding())); dst.infectBy(src); return dst; }
private IRubyObject each_charCommon18(ThreadContext context, Block block) { byte bytes[] = value.getUnsafeBytes(); int p = value.getBegin(); int end = p + value.getRealSize(); Ruby runtime = context.runtime; Encoding enc = runtime.getKCode().getEncoding(); ByteList val = value.shallowDup(); while (p < end) { int n = StringSupport.length(enc, bytes, p, end); block.yield(context, makeShared19(runtime, val, p-val.getBegin(), n)); p += n; } return this; }
/** rb_reg_inspect * */ @JRubyMethod(name = "inspect", compat = CompatVersion.RUBY1_8) @Override public IRubyObject inspect() { if (getRuntime().is1_9()) return inspect19(); check(); ByteList result = regexpDescription(getRuntime(), str, options.getKCode().getEncoding(), options); if (!isKCodeDefault()) result.append((byte)options.getKCodeName().charAt(0)); return RubyString.newString(getRuntime(), result); }
/** rb_reg_inspect * */ @JRubyMethod(name = "inspect", compat = CompatVersion.RUBY1_8) @Override public IRubyObject inspect() { if (getRuntime().is1_9()) return inspect19(); check(); ByteList result = regexpDescription(getRuntime(), str, options.getKCode().getEncoding(), options); if (!isKCodeDefault()) result.append((byte)options.getKCodeName().charAt(0)); return RubyString.newString(getRuntime(), result); }
private IRubyObject each_charCommon18(ThreadContext context, Block block) { byte bytes[] = value.getUnsafeBytes(); int p = value.getBegin(); int end = p + value.getRealSize(); Ruby runtime = context.runtime; Encoding enc = runtime.getKCode().getEncoding(); ByteList val = value.shallowDup(); while (p < end) { int n = StringSupport.length(enc, bytes, p, end); block.yield(context, makeShared19(runtime, val, p-val.getBegin(), n)); p += n; } return this; }
public IRubyObject each_charInternal(final ThreadContext context, final Block block) { checkReadable(); Ruby runtime = context.runtime; ByteList bytes = ptr.string.getByteList(); int len = bytes.getRealSize(); int end = bytes.getBegin() + len; Encoding enc = runtime.is1_9() ? bytes.getEncoding() : runtime.getKCode().getEncoding(); while (ptr.pos < len) { int pos = (int) ptr.pos; int n = StringSupport.length(enc, bytes.getUnsafeBytes(), pos, end); if (len < pos + n) n = len - pos; ptr.pos += n; block.yield(context, ptr.string.makeShared19(runtime, pos, n)); } return this; }
public IRubyObject each_charInternal(final ThreadContext context, final Block block) { checkReadable(); Ruby runtime = context.runtime; ByteList bytes = ptr.string.getByteList(); int len = bytes.getRealSize(); int end = bytes.getBegin() + len; Encoding enc = runtime.is1_9() ? bytes.getEncoding() : runtime.getKCode().getEncoding(); while (ptr.pos < len) { int pos = (int) ptr.pos; int n = StringSupport.length(enc, bytes.getUnsafeBytes(), pos, end); if (len < pos + n) n = len - pos; ptr.pos += n; block.yield(context, ptr.string.makeShared19(runtime, pos, n)); } return this; }
/** The parse method use an lexer stream and parse it to an AST node * structure */ public RubyParserResult parse(ParserConfiguration configuration, LexerSource source) throws IOException { support.reset(); support.setConfiguration(configuration); support.setResult(new RubyParserResult()); lexer.reset(); lexer.setSource(source); lexer.setEncoding(configuration.getKCode().getEncoding()); yyparse(lexer, configuration.isDebug() ? new YYDebug() : null); return support.getResult(); } }
/** The parse method use an lexer stream and parse it to an AST node * structure */ public RubyParserResult parse(ParserConfiguration configuration, LexerSource source) throws IOException { support.reset(); support.setConfiguration(configuration); support.setResult(new RubyParserResult()); lexer.reset(); lexer.setSource(source); lexer.setEncoding(configuration.getKCode().getEncoding()); yyparse(lexer, configuration.isDebug() ? new YYDebug() : null); return support.getResult(); } }
private IRubyObject subBangNoIter(ThreadContext context, Regex pattern, RubyString repl) { int tuFlags = repl.flags; int range = value.getBegin() + value.getRealSize(); Matcher matcher = pattern.matcher(value.getUnsafeBytes(), value.getBegin(), range); if (RubyRegexp.matcherSearch(context.runtime, matcher, value.getBegin(), range, Option.NONE) >= 0) { repl = RubyRegexp.regsub(repl, this, matcher, context.runtime.getKCode().getEncoding()); RubyMatchData match = RubyRegexp.createMatchData(context, this, matcher, pattern); context.setBackRef(match); return subBangCommon(context, pattern, matcher, repl, tuFlags); } else { return context.setBackRef(context.runtime.getNil()); } }
private IRubyObject subBangNoIter(ThreadContext context, Regex pattern, RubyString repl) { int tuFlags = repl.flags; int range = value.getBegin() + value.getRealSize(); Matcher matcher = pattern.matcher(value.getUnsafeBytes(), value.getBegin(), range); if (RubyRegexp.matcherSearch(context.runtime, matcher, value.getBegin(), range, Option.NONE) >= 0) { repl = RubyRegexp.regsub(repl, this, matcher, context.runtime.getKCode().getEncoding()); RubyMatchData match = RubyRegexp.createMatchData(context, this, matcher, pattern); context.setBackRef(match); return subBangCommon(context, pattern, matcher, repl, tuFlags); } else { return context.setBackRef(context.runtime.getNil()); } }