/** rb_cstr_to_inum * */ public static RubyInteger byteListToInum(Ruby runtime, ByteList str, int base, boolean badcheck) { return new ConvertBytes(runtime, str, base, badcheck).byteListToInum(); }
private static byte[] getFixnumBytes(RubyFixnum arg, int base, boolean sign, boolean upper) { long val = arg.getLongValue(); // limit the length of negatives if possible (also faster) if (val >= Integer.MIN_VALUE && val <= Integer.MAX_VALUE) { if (sign) { return ConvertBytes.intToByteArray((int)val,base,upper); } else { switch(base) { case 2: return ConvertBytes.intToBinaryBytes((int)val); case 8: return ConvertBytes.intToOctalBytes((int)val); case 10: default: return ConvertBytes.intToCharBytes((int)val); case 16: return ConvertBytes.intToHexBytes((int)val,upper); } } } else { if (sign) { return ConvertBytes.longToByteArray(val,base,upper); } else { switch(base) { case 2: return ConvertBytes.longToBinaryBytes(val); case 8: return ConvertBytes.longToOctalBytes(val); case 10: default: return ConvertBytes.longToCharBytes(val); case 16: return ConvertBytes.longToHexBytes(val,upper); } } } }
public RubyInteger byteListToInum() { if (str == null) { if (badcheck) invalidString("Integer"); return RubyFixnum.zero(runtime); ignoreLeadingWhitespace(); boolean sign = getSign(); if (badcheck) invalidString("Integer"); return RubyFixnum.zero(runtime); figureOutBase(); int len = calculateLength(); squeezeZeroes(); c = convertDigit(c); if (c < 0 || c >= base) { if (badcheck) invalidString("Integer"); return RubyFixnum.zero(runtime); len *= trailingLength(); } else { len *= (end - beg); long val = stringToLong(beg, endPlace, base); if (endPlace[0] < end && data[endPlace[0]] == '_') { return bigParse(len, sign);
private RubyInteger bigParse(int len, boolean sign) { if (badcheck && beg < end && data[beg] == '_') { invalidString("Integer"); if (c == '_') { if (nondigit != -1) { if (badcheck) invalidString("Integer"); break; } else if((c = convertDigit(c)) < 0) { break; if (badcheck) { if (str.getBegin()+1 < tmpStr && data[tmpStr-1] == '_') invalidString("Integer"); while (tmpStr < end && Character.isWhitespace(data[tmpStr])) tmpStr++; if (tmpStr < end) invalidString("Integer"); BigInteger z = (base == 10) ? stringToBig(s) : new BigInteger(s, base); if (!sign) z = z.negate(); invalidString("Integer"); while(beg < end && isSpace(beg)) beg++; if (beg < end) invalidString("Integer");
private RubyInteger bigParse(int len, boolean sign) { if(badcheck && str < end && data[str] == '_') { invalidString("Integer"); if(nondigit != -1) { if(badcheck) { invalidString("Integer"); } else if((c = convertDigit(c)) < 0) { break; invalidString("Integer"); while(str < end && isSpace(str)) { str++; invalidString("Integer");
boolean overflow = false; while(isSpace(s)) { s++; c = convertDigit(data[s]); if(c == -1 || c >= base) { break;
@Deprecated public static RubyInteger byteListToInum19(Ruby runtime, ByteList str, int base, boolean badcheck) { return byteListToInum(runtime, str, base, badcheck); }
public static final ByteList intToBinaryByteList(int i) { return new ByteList(intToBinaryBytes(i)); } public static final ByteList intToOctalByteList(int i) {
public RubyInteger byteListToInum() { if (str == null) { if (badcheck) invalidString("Integer"); return RubyFixnum.zero(runtime); ignoreLeadingWhitespace(); boolean sign = getSign(); if (badcheck) invalidString("Integer"); return RubyFixnum.zero(runtime); figureOutBase(); int len = calculateLength(); squeezeZeroes(); c = convertDigit(c); if (c < 0 || c >= base) { if (badcheck) invalidString("Integer"); return RubyFixnum.zero(runtime); len *= trailingLength(); } else { len *= (end - beg); long val = stringToLong(beg, endPlace, base); if (endPlace[0] < end && data[endPlace[0]] == '_') { return bigParse(len, sign);
private RubyInteger bigParse(int len, boolean sign) { if (badcheck && beg < end && data[beg] == '_') { invalidString("Integer"); if (c == '_') { if (nondigit != -1) { if (badcheck) invalidString("Integer"); break; } else if((c = convertDigit(c)) < 0) { break; if (badcheck) { if (str.getBegin()+1 < tmpStr && data[tmpStr-1] == '_') invalidString("Integer"); while (tmpStr < end && Character.isWhitespace(data[tmpStr])) tmpStr++; if (tmpStr < end) invalidString("Integer"); BigInteger z = (base == 10) ? stringToBig(s) : new BigInteger(s, base); if (!sign) z = z.negate(); invalidString("Integer"); while(beg < end && isSpace(beg)) beg++; if (beg < end) invalidString("Integer");
private RubyInteger bigParse(int len, boolean sign) { if(badcheck && str < end && data[str] == '_') { invalidString("Integer"); if(nondigit != -1) { if(badcheck) { invalidString("Integer"); } else if((c = convertDigit(c)) < 0) { break; invalidString("Integer"); while(str < end && isSpace(str)) { str++; invalidString("Integer");
boolean overflow = false; while(isSpace(s)) { s++; c = convertDigit(data[s]); if(c == -1 || c >= base) { break;
@Deprecated public static RubyInteger byteListToInum19(Ruby runtime, ByteList str, int base, boolean badcheck) { return byteListToInum(runtime, str, base, badcheck); }
public static final ByteList intToBinaryByteList(int i) { return new ByteList(intToBinaryBytes(i)); } public static final ByteList intToOctalByteList(int i) {
public RubyInteger byteListToInum() { if(_str == null) { if(badcheck) { invalidString("Integer"); ignoreLeadingWhitespace(); boolean sign = getSign(); invalidString("Integer"); figureOutBase(); int len = calculateLength(); squeezeZeroes(); c = convertDigit(c); if(c < 0 || c >= base) { if(badcheck) { invalidString("Integer"); long val = stringToLong(str, endPlace, base); return bigParse(len, sign); invalidString("Integer"); // no number while(isSpace(endPlace[0])) { endPlace[0]++;
private static byte[] getFixnumBytes(RubyFixnum arg, int base, boolean sign, boolean upper) { long val = arg.getLongValue(); // limit the length of negatives if possible (also faster) if (val >= Integer.MIN_VALUE && val <= Integer.MAX_VALUE) { if (sign) { return ConvertBytes.intToByteArray((int)val,base,upper); } else { switch(base) { case 2: return ConvertBytes.intToBinaryBytes((int)val); case 8: return ConvertBytes.intToOctalBytes((int)val); case 10: default: return ConvertBytes.intToCharBytes((int)val); case 16: return ConvertBytes.intToHexBytes((int)val,upper); } } } else { if (sign) { return ConvertBytes.longToByteArray(val,base,upper); } else { switch(base) { case 2: return ConvertBytes.longToBinaryBytes(val); case 8: return ConvertBytes.longToOctalBytes(val); case 10: default: return ConvertBytes.longToCharBytes(val); case 16: return ConvertBytes.longToHexBytes(val,upper); } } } }
/** rb_cstr_to_inum * */ public static RubyInteger byteListToInum(Ruby runtime, ByteList str, int base, boolean badcheck) { return new ConvertBytes(runtime, str, base, badcheck).byteListToInum(); }
boolean overflow = false; while(isSpace(s)) { s++; c = convertDigit(data[s]);
/** rb_str_to_inum * */ public IRubyObject stringToInum(int base, boolean badcheck) { ByteList s = this.value; return ConvertBytes.byteListToInum(getRuntime(), s, base, badcheck); }
public static final ByteList intToBinaryByteList(int i) { return new ByteList(intToBinaryBytes(i)); } public static final ByteList intToOctalByteList(int i) {