/** * Does this ByteList end with the supplied ByteList? * * @param other is the bytelist to compare with * @return true is this ByteList starts with other */ public boolean endsWith(ByteList other) { return startsWith(other, realSize - other.realSize); }
/** * Does this ByteList start with the supplied ByteList? * * @param other is the bytelist to compare with * @return true is this ByteList starts with other */ public boolean startsWith(ByteList other) { return startsWith(other, 0); }
/** * Does this ByteList end with the supplied ByteList? * * @param other is the bytelist to compare with * @return true is this ByteList starts with other */ public boolean endsWith(ByteList other) { return startsWith(other, realSize - other.realSize); }
/** * Does this ByteList start with the supplied ByteList? * * @param other is the bytelist to compare with * @return true is this ByteList starts with other */ public boolean startsWith(ByteList other) { return startsWith(other, 0); }
/** * Does this ByteList start with the supplied ByteList? * * @param other is the bytelist to compare with * @return true is this ByteList starts with other */ public boolean startsWith(ByteList other) { return startsWith(other, 0); }
/** * Does this ByteList end with the supplied ByteList? * * @param other is the bytelist to compare with * @return true is this ByteList starts with other */ public boolean endsWith(ByteList other) { return startsWith(other, realSize - other.realSize); }
private boolean startWith(IRubyObject arg) { RubyString otherString = arg.convertToString(); checkEncoding(otherString); int otherLength = otherString.value.getRealSize(); if (otherLength == 0) return true; // other is '', so return true if (value.getRealSize() < otherLength) return false; return value.startsWith(otherString.value); }
private boolean startWith(IRubyObject arg) { RubyString otherString = arg.convertToString(); checkEncoding(otherString); int otherLength = otherString.value.getRealSize(); if (otherLength == 0) return true; // other is '', so return true if (value.getRealSize() < otherLength) return false; return value.startsWith(otherString.value); }
private boolean start_with_pCommon(IRubyObject arg) { IRubyObject tmp = arg.checkStringType(); if (tmp.isNil()) return false; RubyString otherString = (RubyString)tmp; checkEncoding(otherString); if (value.getRealSize() < otherString.value.getRealSize()) return false; return value.startsWith(otherString.value); }
private boolean start_with_pCommon(IRubyObject arg) { IRubyObject tmp = arg.checkStringType(); if (tmp.isNil()) return false; RubyString otherString = (RubyString)tmp; checkEncoding(otherString); if (value.getRealSize() < otherString.value.getRealSize()) return false; return value.startsWith(otherString.value); }
private IRubyObject internalSepGets(ByteList sep, int limit) throws IOException { ByteList result = newReadByteList(); if (sep.getRealSize() == 0) sep = Stream.PARAGRAPH_SEPARATOR; int ce = -1; while (limit <= 0 || result.length() < limit) { int sepOffset = result.length() - sep.getRealSize(); if (sepOffset >= 0 && result.startsWith(sep, sepOffset)) break; ce = bufferedStream.read(); if (ce == -1) break; result.append(ce); } if (getRuntime().is1_9()) fixBrokenTrailingCharacter(result); // io.available() only returns 0 after EOF is encountered // so we need to differentiate between the empty string and EOF if (0 == result.length() && -1 == ce) return getRuntime().getNil(); line++; position = result.length(); return newStr(getRuntime(), result); }
private IRubyObject internalSepGets(ByteList sep, int limit) throws IOException { ByteList result = newReadByteList(); if (sep.getRealSize() == 0) sep = Stream.PARAGRAPH_SEPARATOR; int ce = -1; while (limit <= 0 || result.length() < limit) { int sepOffset = result.length() - sep.getRealSize(); if (sepOffset >= 0 && result.startsWith(sep, sepOffset)) break; ce = bufferedStream.read(); if (ce == -1) break; result.append(ce); } if (getRuntime().is1_9()) fixBrokenTrailingCharacter(result); // io.available() only returns 0 after EOF is encountered // so we need to differentiate between the empty string and EOF if (0 == result.length() && -1 == ce) return getRuntime().getNil(); line++; position = result.length(); return newStr(getRuntime(), result); }
private IRubyObject internalSepGets(ByteList sep, int limit) throws IOException { ByteList result = newReadByteList(); boolean stripNewlines = false; if (sep.getRealSize() == 0) { sep = PARAGRAPH_SEPARATOR; stripNewlines = true; } if (stripNewlines) skipNewlines(); int ce = -1; while (limit <= 0 || result.length() < limit) { int sepOffset = result.length() - sep.getRealSize(); if (sepOffset >= 0 && result.startsWith(sep, sepOffset)) break; ce = bufferedStream.read(); if (ce == -1) break; result.append(ce); } fixBrokenTrailingCharacter(result); if (stripNewlines) skipNewlines(); // io.available() only returns 0 after EOF is encountered // so we need to differentiate between the empty string and EOF if (0 == result.length() && -1 == ce) return getRuntime().getNil(); line++; position += result.length(); return newStr(getRuntime(), result); }
/** * Get the fully-qualified JRubyFile object for the path, taking into * account the runtime's current directory. */ public static FileResource fileResource(IRubyObject pathOrFile) { Ruby runtime = pathOrFile.getRuntime(); if (pathOrFile instanceof RubyFile) { return JRubyFile.createResource(runtime, ((RubyFile) pathOrFile).getPath()); } else if (pathOrFile instanceof RubyIO) { return JRubyFile.createResource(runtime, ((RubyIO) pathOrFile).openFile.getPath()); } else { RubyString pathStr = get_path(runtime.getCurrentContext(), pathOrFile); ByteList pathByteList = pathStr.getByteList(); if ((pathByteList.bytes().length > FILE_URL_START.bytes().length) && pathByteList.startsWith(FILE_URL_START)) { String path = pathStr.asJavaString(); String[] pathParts = splitURI(path); if (pathParts != null && pathParts[0].equals("file:")) { path = pathParts[1]; } return JRubyFile.createResource(runtime, path); } return JRubyFile.createResource(runtime, pathStr.toString()); } }
private IRubyObject internalSepGets(ByteList sep, int limit) throws IOException { ByteList result = newReadByteList(); boolean stripNewlines = false; if (sep.getRealSize() == 0) { sep = PARAGRAPH_SEPARATOR; stripNewlines = true; } if (stripNewlines) skipNewlines(); int ce = -1; while (limit <= 0 || result.length() < limit) { int sepOffset = result.length() - sep.getRealSize(); if (sepOffset >= 0 && result.startsWith(sep, sepOffset)) break; ce = bufferedStream.read(); if (ce == -1) break; result.append(ce); } fixBrokenTrailingCharacter(result); if (stripNewlines) skipNewlines(); // io.available() only returns 0 after EOF is encountered // so we need to differentiate between the empty string and EOF if (0 == result.length() && -1 == ce) return getRuntime().getNil(); line++; position += result.length(); return newStr(getRuntime(), result); }
/** * Get the fully-qualified JRubyFile object for the path, taking into * account the runtime's current directory. */ public static JRubyFile file(IRubyObject pathOrFile) { Ruby runtime = pathOrFile.getRuntime(); if (pathOrFile instanceof RubyFile) { return JRubyFile.create(runtime.getCurrentDirectory(), ((RubyFile) pathOrFile).getPath()); } else if (pathOrFile instanceof RubyIO) { return JRubyFile.create(runtime.getCurrentDirectory(), ((RubyIO) pathOrFile).openFile.getPath()); } else { RubyString pathStr = get_path(runtime.getCurrentContext(), pathOrFile); ByteList pathByteList = pathStr.getByteList(); if ((pathByteList.bytes().length > FILE_URL_START.bytes().length) && pathByteList.startsWith(FILE_URL_START)) { String path = pathStr.asJavaString(); String[] pathParts = splitURI(path); if (pathParts != null && pathParts[0].equals("file:")) { path = pathParts[1]; } return JRubyFile.create(runtime.getCurrentDirectory(), path); } return JRubyFile.create(runtime.getCurrentDirectory(), pathStr.toString()); } }
static RubyFloat new_float(final Ruby runtime, IRubyObject object) { if (object instanceof RubyInteger){ return new_float(runtime, (RubyInteger) object); } if (object instanceof RubyFloat) { return (RubyFloat) object; } if (object instanceof RubyString){ RubyString str = (RubyString) object; ByteList bytes = str.getByteList(); if (bytes.getRealSize() == 0){ // rb_cstr_to_dbl case throw runtime.newArgumentError("invalid value for Float(): " + object.inspect()); } if (bytes.startsWith(ZEROx)) { // startsWith("0x") return ConvertBytes.byteListToInum(runtime, bytes, 16, true).toFloat(); } return RubyNumeric.str2fnum(runtime, str, true); } if (object.isNil()){ throw runtime.newTypeError("can't convert nil into Float"); } ThreadContext context = runtime.getCurrentContext(); KernelSites sites = sites(context); return (RubyFloat) TypeConverter.convertToType(context, object, runtime.getFloat(), sites.to_f_checked); }
static RubyFloat new_float(final Ruby runtime, IRubyObject object) { if (object instanceof RubyInteger){ return new_float(runtime, (RubyInteger) object); } if (object instanceof RubyFloat) { return (RubyFloat) object; } if (object instanceof RubyString){ RubyString str = (RubyString) object; ByteList bytes = str.getByteList(); if (bytes.getRealSize() == 0){ // rb_cstr_to_dbl case throw runtime.newArgumentError("invalid value for Float(): " + object.inspect()); } if (bytes.startsWith(ZEROx)) { // startsWith("0x") return ConvertBytes.byteListToInum(runtime, bytes, 16, true).toFloat(); } return RubyNumeric.str2fnum(runtime, str, true); } if (object.isNil()){ throw runtime.newTypeError("can't convert nil into Float"); } ThreadContext context = runtime.getCurrentContext(); KernelSites sites = sites(context); return (RubyFloat) TypeConverter.convertToType(context, object, runtime.getFloat(), sites.to_f_checked); }