@JRubyMethod(name = "find", meta = true) public static IRubyObject find(ThreadContext context, IRubyObject recv, IRubyObject str) { Ruby runtime = context.runtime; // Wacky but true...return arg if it is an encoding looking for itself if (str instanceof RubyEncoding) return str; return runtime.getEncodingService().rubyEncodingFromObject(str); }
@JRubyMethod public IRubyObject source_encoding(ThreadContext context) { if (ec.sourceEncoding == null) return context.nil; return context.runtime.getEncodingService().convertEncodingToRubyEncoding(ec.sourceEncoding); }
@JRubyMethod public IRubyObject destination_encoding(ThreadContext context) { if (ec.destinationEncoding == null) return context.nil; return context.runtime.getEncodingService().convertEncodingToRubyEncoding(ec.destinationEncoding); }
@JRubyMethod public IRubyObject internal_encoding(ThreadContext context) { if (openFile.encs.enc2 == null) return context.nil; return context.runtime.getEncodingService().getEncoding(getReadEncoding()); }
public Encoding toEncoding(Ruby runtime) { switch (this) { case LOCALE: return runtime.getEncodingService().getLocaleEncoding(); case EXTERNAL: return runtime.getDefaultExternalEncoding(); case INTERNAL: return runtime.getDefaultInternalEncoding(); case FILESYSTEM: return runtime.getDefaultFilesystemEncoding(); default: throw new AssertionError("invalid SpecialEncoding: " + this); } } }
public static IRubyObject objEncoding(ThreadContext context, IRubyObject obj) { Encoding enc = encGet(context, obj); if (enc == null) { throw context.runtime.newTypeError("unknown encoding"); } return context.runtime.getEncodingService().convertEncodingToRubyEncoding(enc); }
@JRubyMethod(name = "list", meta = true) public static IRubyObject list(ThreadContext context, IRubyObject recv) { Ruby runtime = context.runtime; return RubyArray.newArrayMayCopy(runtime, runtime.getEncodingService().getEncodingList()); }
@JRubyMethod public IRubyObject encoding(ThreadContext context) { Encoding enc = (pattern == null) ? str.getEncoding() : pattern.getEncoding(); return context.runtime.getEncodingService().getEncoding(enc); }
@JRubyMethod(name = "compatible?", meta = true) public static IRubyObject compatible_p(ThreadContext context, IRubyObject self, IRubyObject first, IRubyObject second) { Ruby runtime = context.runtime; Encoding enc = areCompatible(first, second); return enc == null ? runtime.getNil() : runtime.getEncodingService().getEncoding(enc); }
public IRubyObject getDefaultExternal() { Encoding defaultEncoding = runtime.getDefaultExternalEncoding(); if (defaultEncoding == null) { // TODO: MRI seems to default blindly to US-ASCII and we were using Charset default from Java...which is right? ByteList encodingName = ByteList.create("US-ASCII"); defaultEncoding = runtime.getEncodingService().loadEncoding(encodingName); runtime.setDefaultExternalEncoding(defaultEncoding); } return getEncoding(defaultEncoding); }
private void setupSourceEncoding(ParserConfiguration parserConfig, Encoding defaultEncoding) { if (config.getSourceEncoding() != null) { if (config.isVerbose()) { config.getError().println("-K is specified; it is for 1.8 compatibility and may cause odd behavior"); } parserConfig.setDefaultEncoding(getEncodingService().getEncodingFromString(config.getSourceEncoding())); } else { parserConfig.setDefaultEncoding(defaultEncoding); } }
@JRubyMethod public static IRubyObject to_s(ThreadContext context, IRubyObject self) { final Encoding ascii8bit = context.runtime.getEncodingService().getAscii8bitEncoding(); // All bytes can be considered raw strings and forced to particular codings if not 8bitascii ByteList bytes = new ByteList((byte[]) ((ArrayJavaProxy) self).getObject(), ascii8bit); return RubyString.newStringLight(context.runtime, bytes); }
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) { yyVal = new FileNode(lexer.tokline, new ByteList(lexer.getFile().getBytes(), support.getConfiguration().getRuntime().getEncodingService().getLocaleEncoding())); return yyVal; } };
public Node parseInline(InputStream in, String file, DynamicScope scope) { addEvalParseToStats(); ParserConfiguration parserConfig = new ParserConfiguration(this, 0, false, true, false, config); setupSourceEncoding(parserConfig, getEncodingService().getLocaleEncoding()); return parser.parse(file, in, scope, parserConfig); }
@JRubyMethod(name = "locale_charmap", meta = true) public static IRubyObject locale_charmap(ThreadContext context, IRubyObject recv) { Ruby runtime = context.runtime; EncodingService service = runtime.getEncodingService(); ByteList name = new ByteList(service.getLocaleEncoding().getName()); return RubyString.newUsAsciiStringNoCopy(runtime, name); }
@JRubyMethod public IRubyObject external_encoding(ThreadContext context) { EncodingService encodingService = context.runtime.getEncodingService(); if (openFile.encs.enc2 != null) return encodingService.getEncoding(openFile.encs.enc2); if (openFile.isWritable()) { return openFile.encs.enc == null ? context.nil : encodingService.getEncoding(openFile.encs.enc); } return encodingService.getEncoding(getReadEncoding()); }
public static void ioSetEncodingByBOM(ThreadContext context, RubyIO io) { Ruby runtime = context.runtime; Encoding bomEncoding = ioStripBOM(context, io); if (bomEncoding != null) { // FIXME: Wonky that we acquire RubyEncoding to pass these encodings through IRubyObject theBom = runtime.getEncodingService().getEncoding(bomEncoding); IRubyObject theInternal = io.internal_encoding(context); io.setEncoding(runtime.getCurrentContext(), theBom, theInternal, context.nil); } else { io.setEnc2(null); } }
@JRubyMethod public IRubyObject replacement(ThreadContext context) { int ret = ec.makeReplacement(); if (ret == -1) { throw context.runtime.newUndefinedConversionError("replacement character setup failed"); } return context.runtime.newString(new ByteList( ec.replacementString, 0, ec.replacementLength, context.runtime.getEncodingService().findEncodingOrAliasEntry(ec.replacementEncoding).getEncoding(), true)); }
protected void setEncoding(ByteList name) { Encoding newEncoding = parser.getRuntime().getEncodingService().loadEncoding(name); if (newEncoding == null) { compile_error("unknown encoding name: " + name.toString()); return; } if (!newEncoding.isAsciiCompatible()) { compile_error(name.toString() + " is not ASCII compatible"); return; } setEncoding(newEncoding); }
protected void setEncoding(ByteList name) { Ruby runtime = parserSupport.getConfiguration().getRuntime(); Encoding newEncoding = runtime.getEncodingService().loadEncoding(name); if (newEncoding == null) throw runtime.newArgumentError("unknown encoding name: " + name.toString()); if (!newEncoding.isAsciiCompatible()) throw runtime.newArgumentError(name.toString() + " is not ASCII compatible"); setEncoding(newEncoding); }