本文整理了Java中org.jruby.Ruby.getEncodingService
方法的一些代码示例,展示了Ruby.getEncodingService
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.getEncodingService
方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:getEncodingService
暂无
代码示例来源:origin: org.jruby/jruby-complete
@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);
}
代码示例来源:origin: org.jruby/jruby-complete
@JRubyMethod
public IRubyObject source_encoding(ThreadContext context) {
if (ec.sourceEncoding == null) return context.nil;
return context.runtime.getEncodingService().convertEncodingToRubyEncoding(ec.sourceEncoding);
}
代码示例来源:origin: org.jruby/jruby-complete
@JRubyMethod
public IRubyObject destination_encoding(ThreadContext context) {
if (ec.destinationEncoding == null) return context.nil;
return context.runtime.getEncodingService().convertEncodingToRubyEncoding(ec.destinationEncoding);
}
代码示例来源:origin: org.jruby/jruby-complete
@JRubyMethod
public IRubyObject internal_encoding(ThreadContext context) {
if (openFile.encs.enc2 == null) return context.nil;
return context.runtime.getEncodingService().getEncoding(getReadEncoding());
}
代码示例来源:origin: org.jruby/jruby-complete
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);
}
}
}
代码示例来源:origin: org.jruby/jruby-complete
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);
}
代码示例来源:origin: org.jruby/jruby-complete
@JRubyMethod(name = "list", meta = true)
public static IRubyObject list(ThreadContext context, IRubyObject recv) {
Ruby runtime = context.runtime;
return RubyArray.newArrayMayCopy(runtime, runtime.getEncodingService().getEncodingList());
}
代码示例来源:origin: org.jruby/jruby-complete
@JRubyMethod
public IRubyObject encoding(ThreadContext context) {
Encoding enc = (pattern == null) ? str.getEncoding() : pattern.getEncoding();
return context.runtime.getEncodingService().getEncoding(enc);
}
代码示例来源:origin: org.jruby/jruby-complete
@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);
}
代码示例来源:origin: org.jruby/jruby-complete
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);
}
代码示例来源:origin: org.jruby/jruby-complete
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);
}
}
代码示例来源:origin: org.jruby/jruby-complete
@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);
}
代码示例来源:origin: org.jruby/jruby-complete
@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;
}
};
代码示例来源:origin: org.jruby/jruby-complete
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);
}
代码示例来源:origin: org.jruby/jruby-complete
@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);
}
代码示例来源:origin: org.jruby/jruby-complete
@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());
}
代码示例来源:origin: org.jruby/jruby-complete
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);
}
}
代码示例来源:origin: org.jruby/jruby-complete
@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));
}
代码示例来源:origin: org.jruby/jruby-complete
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);
}
代码示例来源:origin: org.jruby/jruby-complete
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);
}
内容来源于网络,如有侵权,请联系作者删除!