/** * Since Java 1.6, class {@link java.io.Console} is available. * But the encoding or codepage of the underlying connected * console is currently private. Had to use Reflection to get it. * * @return console codepage */ public Encoding getConsoleEncoding() { if (!Platform.IS_WINDOWS) return null; Encoding consoleEncoding = null; try { Console console = System.console(); if (console != null) { final String CONSOLE_CHARSET = "cs"; Field fcs = Console.class.getDeclaredField(CONSOLE_CHARSET); fcs.setAccessible(true); Charset cs = (Charset) fcs.get(console); consoleEncoding = loadEncoding(ByteList.create(cs.name())); } } catch (Throwable e) { // to cover both Exceptions and Errors // just fall back on local encoding above } return consoleEncoding; }
public Encoding getDefaultEncoding() { if (defaultEncoding == null) { if (runtime.is2_0()) { defaultEncoding = UTF8Encoding.INSTANCE; } else { defaultEncoding = getEncodingService().loadEncoding(USASCII); } } return defaultEncoding; }
public final Encoding getEncoding() { // TODO: make threadsafe if (encoding == null) encoding = getRuntime().getEncodingService().loadEncoding(name); return encoding; }
public final Encoding getEncoding() { // TODO: make threadsafe if (encoding == null) encoding = getRuntime().getEncodingService().loadEncoding(name); return encoding; }
public Encoding getDefaultEncoding() { if (defaultEncoding == null) { if (runtime.is2_0()) { defaultEncoding = UTF8Encoding.INSTANCE; } else { defaultEncoding = getEncodingService().loadEncoding(USASCII); } } return defaultEncoding; }
public final Encoding getEncoding() { if (encoding == null) encoding = getRuntime().getEncodingService().loadEncoding(name); return encoding; }
public final Encoding getEncoding() { if (encoding == null) encoding = getRuntime().getEncodingService().loadEncoding(name); return encoding; }
public RubyEncoding getEncoding(Encoding enc) { int index = enc.getIndex(); RubyEncoding rubyEncoding; if (index < encodingIndex.length && (rubyEncoding = encodingIndex[index]) != null) { return rubyEncoding; } enc = loadEncoding(new ByteList(enc.getName(), false)); return encodingIndex[enc.getIndex()]; }
public RubyEncoding getEncoding(Encoding enc) { int index = enc.getIndex(); RubyEncoding rubyEncoding; if (index < encodingIndex.length && (rubyEncoding = encodingIndex[index]) != null) { return rubyEncoding; } enc = loadEncoding(new ByteList(enc.getName(), false)); return encodingIndex[enc.getIndex()]; }
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); }
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); }
public IRubyObject getDefaultExternal() { IRubyObject defaultExternal = convertEncodingToRubyEncoding(runtime.getDefaultExternalEncoding()); if (defaultExternal.isNil()) { // 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"); Encoding encoding = runtime.getEncodingService().loadEncoding(encodingName); runtime.setDefaultExternalEncoding(encoding); defaultExternal = convertEncodingToRubyEncoding(encoding); } return defaultExternal; }
public IRubyObject getDefaultExternal() { IRubyObject defaultExternal = convertEncodingToRubyEncoding(runtime.getDefaultExternalEncoding()); if (defaultExternal.isNil()) { // 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"); Encoding encoding = runtime.getEncodingService().loadEncoding(encodingName); runtime.setDefaultExternalEncoding(encoding); defaultExternal = convertEncodingToRubyEncoding(encoding); } return defaultExternal; }
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) { 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); }
/** * Calculate the encoding based on kcode option set via 'nesu'. Also as * side-effects: * 1.set whether this marks the soon to be made regexp as 'fixed'. * 2.kcode.none will set 'none' option * @return null if no explicit encoding is specified. */ public Encoding setup19(Ruby runtime) { KCode explicitKCode = getExplicitKCode(); // None will not set fixed if (explicitKCode == KCode.NONE) { setEncodingNone(true); return ASCIIEncoding.INSTANCE; } if (explicitKCode == KCode.EUC) { setFixed(true); return EUCJPEncoding.INSTANCE; } else if (explicitKCode == KCode.SJIS) { setFixed(true); return runtime.getEncodingService().loadEncoding(WINDOWS31J); } else if (explicitKCode == KCode.UTF8) { setFixed(true); return UTF8Encoding.INSTANCE; } return null; }
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); }
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); }
private void setEncoding(ByteList name) { Encoding newEncoding = parserSupport.getConfiguration().getEncodingService().loadEncoding(name); if (newEncoding == null) { throw new SyntaxException(PID.UNKNOWN_ENCODING, getPosition(), null, "unknown encoding name: " + name.toString()); } if (!newEncoding.isAsciiCompatible()) { throw new SyntaxException(PID.NOT_ASCII_COMPATIBLE, getPosition(), null, name.toString() + " is not ASCII compatible"); } setEncoding(newEncoding); }
private void setEncoding(ByteList name) { Encoding newEncoding = parserSupport.getConfiguration().getEncodingService().loadEncoding(name); if (newEncoding == null) { throw new SyntaxException(PID.UNKNOWN_ENCODING, getPosition(), null, "unknown encoding name: " + name.toString()); } if (!newEncoding.isAsciiCompatible()) { throw new SyntaxException(PID.NOT_ASCII_COMPATIBLE, getPosition(), null, name.toString() + " is not ASCII compatible"); } setEncoding(newEncoding); }