@Override public int length(Object parameter) { return ((RubyString) parameter).getByteList().length(); } }
public void init(ByteList list, boolean isStrict) { bytes = list.getUnsafeBytes(); index = list.begin(); endIndex = index + list.length(); this.isStrict = isStrict; // +2 for added exponent: E... // The algorithm trades digits for inc/dec exponent. // Worse case is adding E-1 when no exponent, // it trades one digit for 3 chars. chars = new char[Math.min(list.length()+2, MAX_LENGTH)]; charsIndex = 0; significantDigitsProcessed = 0; adjustExponent = 0; wroteExponent = false; result = -1.0; // -1.0 is "parse String" }
@Deprecated public static Object coerceStringToType(RubyString string, Class target) { try { ByteList bytes = string.getByteList(); // 1.9 support for encodings // TODO: Fix charset use for JRUBY-4553 return new String(bytes.getUnsafeBytes(), bytes.begin(), bytes.length(), string.getEncoding().toString()); } catch (UnsupportedEncodingException uee) { return string.toString(); } }
@JRubyMethod(name = "from_string", meta = true) public static IRubyObject from_string(ThreadContext context, IRubyObject klass, IRubyObject s) { org.jruby.util.ByteList bl = s.convertToString().getByteList(); MemoryPointer ptr = (MemoryPointer) ((RubyClass) klass).newInstance(context, context.runtime.newFixnum(bl.length() + 1), Block.NULL_BLOCK); ptr.getMemoryIO().putZeroTerminatedByteArray(0, bl.unsafeBytes(), bl.begin(), bl.length()); return ptr; }
@Override public InputStream getRemainingAsStream() { ByteList buf = new ByteList(128); int c; while ((c = read()) != RubyYaccLexer.EOF) { buf.append(c); } return new ByteArrayInputStream(buf.getUnsafeBytes(), 0, buf.length()); }
public static IRubyObject checkPipeCommand(ThreadContext context, IRubyObject filenameOrCommand) { RubyString filenameStr = filenameOrCommand.convertToString(); ByteList filenameByteList = filenameStr.getByteList(); final int[] chlen = {0}; if (EncodingUtils.encAscget( filenameByteList.getUnsafeBytes(), filenameByteList.getBegin(), filenameByteList.getBegin() + filenameByteList.getRealSize(), chlen, filenameByteList.getEncoding()) == '|') { return filenameStr.makeShared(context.runtime, chlen[0], filenameByteList.length() - 1).infectBy(filenameOrCommand); } return context.nil; }
@Deprecated public static Object coerceStringToType(RubyString string, Class target) { try { ByteList bytes = string.getByteList(); // 1.9 support for encodings // TODO: Fix charset use for JRUBY-4553 return new String(bytes.getUnsafeBytes(), bytes.begin(), bytes.length(), string.getEncoding().toString()); } catch (UnsupportedEncodingException uee) { return string.toString(); } }
public void init(ByteList list, boolean isStrict) { bytes = list.getUnsafeBytes(); index = list.begin(); endIndex = index + list.length(); this.isStrict = isStrict; // +2 for added exponent: E... // The algorithm trades digits for inc/dec exponent. // Worse case is adding E-1 when no exponent, // it trades one digit for 3 chars. chars = new char[Math.min(list.length()+2, MAX_LENGTH)]; charsIndex = 0; significantDigitsProcessed = 0; adjustExponent = 0; wroteExponent = false; result = -1.0; // -1.0 is "parse String" }
@Override public int length(Object parameter) { return ((RubyString) parameter).getByteList().length(); } }
public long fwrite(ThreadContext context, IRubyObject str, boolean nosync) { // The System.console null check is our poor-man's isatty for Windows. See jruby/jruby#3292 if (Platform.IS_WINDOWS && isStdio() && System.console() != null) { return rbW32WriteConsole((RubyString)str); } str = doWriteconv(context, str); ByteList strByteList = ((RubyString)str).getByteList(); return binwrite(context, str, strByteList.unsafeBytes(), strByteList.begin(), strByteList.length(), nosync); }
@Override public InputStream getRemainingAsStream() { ByteList buf = new ByteList(128); int c; while ((c = read()) != RubyYaccLexer.EOF) { buf.append(c); } return new ByteArrayInputStream(buf.getUnsafeBytes(), 0, buf.length()); }
/** * Check whether input object's string value contains a null byte, and if so * throw SecurityError. * @param runtime * @param value */ public static final void checkStringSafety(Ruby runtime, IRubyObject value) { RubyString s = value.asString(); ByteList bl = s.getByteList(); final byte[] array = bl.getUnsafeBytes(); final int end = bl.length(); for (int i = bl.begin(); i < end; ++i) { if (array[i] == (byte) 0) { throw runtime.newSecurityError("string contains null byte"); } } }
private static int javaStringHashCode(ByteList iso8859) { int h = 0; int length = iso8859.length(); if (length > 0) { byte val[] = iso8859.getUnsafeBytes(); int begin = iso8859.begin(); h = new String(val, begin, length, RubyEncoding.ISO).hashCode(); } return h; }
@Override public int length(Object parameter) { return ((RubyString) parameter).getByteList().length(); } }
public long fwrite(ThreadContext context, IRubyObject str, boolean nosync) { // The System.console null check is our poor-man's isatty for Windows. See jruby/jruby#3292 if (Platform.IS_WINDOWS && isStdio() && System.console() != null) { return rbW32WriteConsole((RubyString)str); } str = doWriteconv(context, str); ByteList strByteList = ((RubyString)str).getByteList(); return binwrite(context, str, strByteList.unsafeBytes(), strByteList.begin(), strByteList.length(), nosync); }
private void fixBrokenTrailingCharacter(ByteList result) throws IOException { // fix broken trailing character int extraBytes = StringSupport.bytesToFixBrokenTrailingCharacter(result.getUnsafeBytes(), result.getBegin(), result.getRealSize(), getReadEncoding(), result.length()); for (int i = 0; i < extraBytes; i++) { int read = bufferedStream.read(); if (read == -1) break; result.append(read); } }
/** * Check whether input object's string value contains a null byte, and if so * throw SecurityError. * @param runtime * @param value */ public static final void checkStringSafety(Ruby runtime, IRubyObject value) { RubyString s = value.asString(); ByteList bl = s.getByteList(); final byte[] array = bl.getUnsafeBytes(); final int end = bl.length(); for (int i = bl.begin(); i < end; ++i) { if (array[i] == (byte) 0) { throw runtime.newSecurityError("string contains null byte"); } } }