/** * Append a single int to the ByteList * * @param b the int to be added * @return this instance */ public ByteList append(int b) { append((byte)b); return this; }
/** * Append moreBytes onto the end of the current ByteList. * * @param moreBytes to be added. */ public void append(ByteList moreBytes) { append(moreBytes.bytes, moreBytes.begin, moreBytes.realSize); }
/** * Encode an int in little endian format into a packed representation. * * @param result to be appended to * @param s the integer to encode */ private static void encodeIntLittleEndian(ByteList result, int s) { result.append((byte) (s & 0xff)).append((byte) ((s >> 8) & 0xff)); result.append((byte) ((s>>16) & 0xff)).append((byte) ((s >> 24) & 0xff)); }
/** * Encode an int in big-endian format into a packed representation. * * @param result to be appended to * @param s the integer to encode */ private static void encodeIntBigEndian(ByteList result, int s) { result.append((byte) ((s>>24) &0xff)).append((byte) ((s>>16) &0xff)); result.append((byte) ((s >> 8) & 0xff)).append((byte) (s & 0xff)); }
@JRubyMethod(name = "inspect") public IRubyObject inspect(ThreadContext context) { ByteList bytes = new ByteList(); bytes.append("#<Encoding:".getBytes()); bytes.append(name); if (isDummy) bytes.append(" (dummy)".getBytes()); bytes.append('>'); return RubyString.newUsAsciiStringNoCopy(context.runtime, bytes); }
public void encode(Ruby runtime, IRubyObject o, ByteList result){ byte c = o == runtime.getNil() ? 0 : (byte) (num2quad(o) & 0xff); result.append(c); } };
@Override public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyObject value, int index, RubyString str) { RubyString keyStr = inspect(context, key); RubyString valStr = inspect(context, value); final ByteList bytes = str.getByteList(); bytes.ensure(2 + keyStr.size() + 2 + valStr.size()); if (index > 0) bytes.append((byte) ',').append((byte) ' '); str.cat19(keyStr); bytes.append((byte) '=').append((byte) '>'); str.cat19(valStr); } };
private static ByteList regexpDescription19(Ruby runtime, byte[] s, int start, int len, RegexpOptions options, Encoding enc) { ByteList description = new ByteList(); description.setEncoding(enc); description.append((byte)'/'); Encoding resultEnc = runtime.getDefaultInternalEncoding(); if (resultEnc == null) resultEnc = runtime.getDefaultExternalEncoding(); appendRegexpString19(runtime, description, s, start, len, enc, resultEnc); description.append((byte)'/'); appendOptions(description, options); if (options.isEncodingNone()) description.append((byte) 'n'); return description; }
protected int write(CallSite write, ByteBuffer src) throws IOException { ByteList buffer; if (src.hasArray()) { buffer = new ByteList(src.array(), src.position(), src.remaining(), true); } else { buffer = new ByteList(src.remaining()); buffer.append(src, src.remaining()); } IRubyObject written = write.call(runtime.getCurrentContext(), io, io, RubyString.newStringLight(runtime, buffer)); return (int)written.convertToInteger().getLongValue(); }
private void escaped(RipperLexer lexer, LexerSource src, ByteList buffer) throws java.io.IOException { int c; switch (c = lexer.nextc()) { case '\\': parseEscapeIntoBuffer(lexer, src, buffer); break; case EOF: lexer.compile_error("Invalid escape character syntax"); default: buffer.append(c); } }
protected void flush_string_content(Encoding encoding) { if (delayed != null) { int len = lex_p - tokp; if (len > 0) { delayed.setEncoding(encoding); delayed.append(lexb.makeShared(tokp, len)); } dispatchDelayedToken(RipperParser.tSTRING_CONTENT); tokp = lex_p; } }
private void escaped(RubyLexer lexer, ByteList buffer) throws java.io.IOException { int c; switch (c = lexer.nextc()) { case '\\': parseEscapeIntoBuffer(lexer, buffer); break; case EOF: lexer.compile_error("Invalid escape character syntax"); default: buffer.append(c); } }
/** * Make an instance variable out of this symbol (e.g. :foo will generate :foo=). * @return the new symbol */ public RubySymbol asWriter() { ByteList bytes = getBytes().dup(); bytes.append((byte) '='); return newIDSymbol(getRuntime(), bytes); }
public void append(ByteList obj) { if (!internalFinished()) { flater.setInput(obj.bytes(), true); } else { input.append(obj); } run(false); }
private void convertCRLFToLF(ByteList src, ByteList dst) { for (int i = 0; i < src.length(); i++) { int b = src.get(i); if (b == CR && i + 1 < src.length() && src.get(i + 1) == LF) { continue; } dst.append(b); } }
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); } }
public LocalVariable getNewFlipStateVariable() { ByteList flip = FLIP.dup(); flip.append(allocateNextPrefixedName("%flip")); return getLocalVariable(getManager().getRuntime().newSymbol(flip) , 0); }
@Override public void setName(RubySymbol name) { ByteList newName = getLexicalParent().getName().getBytes().dup(); newName.append(name.getBytes()); super.setName(getManager().getRuntime().newSymbol(newName)); }