Input:
    private static Buffer rubySprintfToBuffer(CharSequence charFormat, Args args) {
        byte[] format;
        Buffer buf = new Buffer();
        int offset;
        int length;
        int start;
        int mark;
        if (charFormat instanceof ByteList) {
            ByteList list = (ByteList)charFormat;
            format = list.unsafeBytes();
            int begin = list.begin();
            offset = begin;
            length = begin + list.length();
            start = begin;
            mark = begin;
        } else {
            format = stringToBytes(charFormat, false);
            offset = 0;
            length = charFormat.length();
            start = 0;
            mark = 0;
        }
        while (offset < length) {
            start = offset;
            for ( ; offset < length && format[offset] != '%'; offset++) ;
            if (offset > start) {
                buf.write(format,start,offset-start);
                start = offset;
            }
            if (offset++ >= length)
                break;
            IRubyObject arg = null;
            int flags = 0;
            int width = 0;
            int precision = 0;
            int number = 0;
            byte fchar = 0;
            boolean incomplete = true;
            for ( ; incomplete && offset < length ; ) {
                switch(fchar = format[offset]) {
                default:
                    if (fchar == '\0' && flags == FLAG_NONE) {
                        buf.write('%');
                        incomplete = false;
                        offset++;
                        break;
                    } else if (isPrintable(fchar)) {
                        raiseArgumentError(args,"malformed format string - %" + (char)fchar);
                    } else {
                        raiseArgumentError(args,ERR_MALFORMED_FORMAT);
                    }
                    break;
                case ' ':
                    flags |= FLAG_SPACE;
                    offset++;
                    break;
                case '0':
                    flags |= FLAG_ZERO;
                    offset++;
                    break;
                case '+':
                    flags |= FLAG_PLUS;
                    offset++;
                    break;
                case '-':
                    flags |= FLAG_MINUS;
                    offset++;
                    break;
                case '#':
                    flags |= FLAG_SHARP;
                    offset++;
                    break;
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                    number = 0;
                    for ( ; offset < length && isDigit(fchar = format[offset]); offset++) {
                        number = extendWidth(args, number, fchar);
                    }
                    checkOffset(args,offset,length,ERR_MALFORMED_NUM);
                    if (fchar == '$') {
                        if (arg != null) {
                            raiseArgumentError(args,"value given twice - " + number + "$");
                        }
                        arg = args.getNth(number);
                        offset++;
                    } else {
                        width = number;
                        flags |= FLAG_WIDTH;
                    }
                    break;
                case '*':
                    if ((flags & FLAG_WIDTH) != 0) {
                        raiseArgumentError(args,"width given twice");
                    }
                    flags |= FLAG_WIDTH;
                    checkOffset(args,++offset,length,ERR_MALFORMED_STAR_NUM);
                    mark = offset;
                    number = 0;
                    for ( ; offset < length && isDigit(fchar = format[offset]); offset++) {
                        number = extendWidth(args,number,fchar);
                    }
                    checkOffset(args,offset,length,ERR_MALFORMED_STAR_NUM);
                    if (fchar == '$') {
                        width = args.getNthInt(number);
                        if (width < 0) {
                            flags |= FLAG_MINUS;
                            width = -width;
                        }
                        offset++;
                    } else {
                        width = args.nextInt();
                        if (width < 0) {
                            flags |= FLAG_MINUS;
                            width = -width;
                        }
                        offset = mark;
                    }
                    break;
                case '.':
                    if ((flags & FLAG_PRECISION) != 0) {
                        raiseArgumentError(args,"precision given twice");
                    }
                    flags |= FLAG_PRECISION;
                    checkOffset(args,++offset,length,ERR_MALFORMED_DOT_NUM);
                    fchar = format[offset];
                    if (fchar == '*') {
                        checkOffset(args,++offset,length,ERR_MALFORMED_STAR_NUM);
                        mark = offset;
                        number = 0;
                        for ( ; offset < length && isDigit(fchar = format[offset]); offset++) {
                            number = extendWidth(args,number,fchar);
                        }
                        checkOffset(args,offset,length,ERR_MALFORMED_STAR_NUM);
                        if (fchar == '$') {
                            precision = args.getNthInt(number);
                            if (precision < 0) {
                                flags &= ~FLAG_PRECISION;
                            }
                            offset++;
                        } else {
                            precision = args.nextInt();
                            if (precision < 0) {
                                flags &= ~FLAG_PRECISION;
                            }
                            offset = mark;
                        }
                    } else {
                        number = 0;
                        for ( ; offset < length && isDigit(fchar = format[offset]); offset++) {
                            number = extendWidth(args,number,fchar);
                        }
                        checkOffset(args,offset,length,ERR_MALFORMED_DOT_NUM);
                        precision = number;
                    }
                    break;
                case '\n':
                    offset--;
                case '%':
                    if (flags != FLAG_NONE) {
                        raiseArgumentError(args,ERR_ILLEGAL_FORMAT_CHAR);
                    }
                    buf.write('%');
                    offset++;
                    incomplete = false;
                    break;
                case 'c': {
                    if (arg == null) arg = args.next();
                    int c = 0;
                    if (arg instanceof RubyString) {
                        ByteList bytes = ((RubyString)arg).getByteList();
                        if (bytes.length() == 1) {
                            c = bytes.unsafeBytes()[bytes.begin()];
                        } else {
                            raiseArgumentError(args,"%c requires a character");
                        }
                    } else {
                        c = args.intValue(arg);
                    }
                    if ((flags & FLAG_WIDTH) != 0 && width > 1) {
                        if ((flags & FLAG_MINUS) != 0) {
                            buf.write(c);
                            buf.fill(' ', width-1);
                        } else {
                            buf.fill(' ',width-1);
                            buf.write(c);
                        }
                    } else {
                        buf.write(c);
                    }
                    offset++;
                    incomplete = false;
                    break;
                }
                case 'p':
                case 's': {
                    if (arg == null) arg = args.next();
                    if (fchar == 'p') {
                        arg = arg.callMethod(arg.getRuntime().getCurrentContext(),"inspect");
                    }
                    ByteList bytes = arg.asString().getByteList();
                    int len = bytes.length();
                    if (arg.isTaint()) {
                        buf.tainted = true;
                    }
                    if ((flags & FLAG_PRECISION) != 0 && precision < len) {
                        len = precision;
                    }
                    if ((flags & FLAG_WIDTH) != 0 && width > len) {
                        width -= len;
                        if ((flags & FLAG_MINUS) != 0) {
                            buf.write(bytes.unsafeBytes(),bytes.begin(),len);
                            buf.fill(' ',width);
                        } else {
                            buf.fill(' ',width);
                            buf.write(bytes.unsafeBytes(),bytes.begin(),len);
                        }
                    } else {
                        buf.write(bytes.unsafeBytes(),bytes.begin(),len);
                    }
                    offset++;
                    incomplete = false;
                    break;
                }
                case 'd':
                case 'i':
                case 'o':
                case 'x':
                case 'X':
                case 'b':
                case 'B':
                case 'u': {
                    if (arg == null) arg = args.next();
                    int type = arg.getMetaClass().index;
                    if (type != ClassIndex.FIXNUM && type != ClassIndex.BIGNUM) {
                        switch(type) {
                        case ClassIndex.FLOAT:
                            arg = RubyNumeric.dbl2num(arg.getRuntime(),((RubyFloat)arg).getValue());
                            break;
                        case ClassIndex.STRING:
                            arg = RubyNumeric.str2inum(arg.getRuntime(),(RubyString)arg,0,true);
                            break;
                        default:
                            if (arg.respondsTo("to_int")) {
                                arg = TypeConverter.convertToType(arg, arg.getRuntime().getInteger(), MethodIndex.TO_INT, "to_int", true);
                            } else {
                                arg = TypeConverter.convertToType(arg, arg.getRuntime().getInteger(), MethodIndex.TO_I, "to_i", true);
                            }
                            break;
                        }
                        type = arg.getMetaClass().index;
                    }
                    byte[] bytes = null;
                    int first = 0;
                    byte[] prefix = null;
                    boolean sign;
                    boolean negative;
                    byte signChar = 0;
                    byte leadChar = 0;
                    int base;
                    if (fchar == 'i') fchar = 'd';
                    if (fchar == 'u' && (flags & (FLAG_SPACE | FLAG_PLUS)) != 0) {
                        fchar = 'd';
                    }
                    sign = (fchar == 'd' || (flags & (FLAG_SPACE | FLAG_PLUS)) != 0);
                    switch (fchar) {
                    case 'o':
                        base = 8; break;
                    case 'x':
                    case 'X':
                        base = 16; break;
                    case 'b':
                    case 'B':
                        base = 2; break;
                    case 'u':
                    case 'd':
                    default:
                        base = 10; break;
                    }
                    if ((flags & FLAG_SHARP) != 0) {
                        switch(fchar) {
                        case 'o': prefix = PREFIX_OCTAL; break;
                        case 'x': prefix = PREFIX_HEX_LC; break;
                        case 'X': prefix = PREFIX_HEX_UC; break;
                        case 'b': prefix = PREFIX_BINARY_LC; break;
                        case 'B': prefix = PREFIX_BINARY_UC; break;
                        }
                        if (prefix != null) width -= prefix.length;
                    }
                    if (type == ClassIndex.FIXNUM) {
                        negative = ((RubyFixnum)arg).getLongValue() < 0;
                        if (negative && fchar == 'u') {
                            bytes = getUnsignedNegativeBytes((RubyFixnum)arg);
                        } else {
                            bytes = getFixnumBytes((RubyFixnum)arg,base,sign,fchar=='X');
                        }
                    } else {
                        negative = ((RubyBignum)arg).getValue().signum() < 0;
                        if (negative && fchar == 'u') {
                            bytes = getUnsignedNegativeBytes((RubyBignum)arg);
                        } else {
                            bytes = getBignumBytes((RubyBignum)arg,base,sign,fchar=='X');
                        }
                    }
                    int len = 0;
                    if (sign) {
                        if (negative) {
                            signChar = '-';
                            width--;
                            first = 1;
                        } else if ((flags & FLAG_PLUS) != 0) {
                            signChar = '+';
                            width--;
                        } else if ((flags & FLAG_SPACE) != 0) {
                            signChar = ' ';
                            width--;
                        }
                    } else if (negative) {
                        if (base == 10) {
                            warning(args,"negative number for %u specifier");
                            leadChar = '.';
                            len += 2;
                        } else {
                            if ((flags & (FLAG_PRECISION | FLAG_ZERO)) == 0) len += 2;
                            first = skipSignBits(bytes,base);
                            switch(fchar) {
                            case 'b':
                            case 'B':
                                leadChar = '1';
                                break;
                            case 'o':
                                leadChar = '7';
                                break;
                            case 'x':
                                leadChar = 'f';
                                break;
                            case 'X':
                                leadChar = 'F';
                                break;
                            }
                            if (leadChar != 0) len++;
                        }
                    }
                    int numlen = bytes.length - first;
                    len += numlen;
                    if ((flags & (FLAG_ZERO|FLAG_PRECISION)) == FLAG_ZERO) {
                        precision = width;
                        width = 0;
                    } else {
                        if (precision < len) precision = len;
                        width -= precision;
                    }
                    if ((flags & FLAG_MINUS) == 0) {
                        buf.fill(' ',width);
                        width = 0;
                    }
                    if (signChar != 0) buf.write(signChar);
                    if (prefix != null) buf.write(prefix);
                    if (len < precision) {
                        if (leadChar == 0) {
                            buf.fill('0', precision - len);
                        } else if (leadChar == '.') {
                            buf.fill(leadChar,precision-len);
                            buf.write(PREFIX_NEGATIVE);
                        } else {
                            buf.fill(leadChar,precision-len+1);
                        }
                    } else if (leadChar != 0) {
                        if ((flags & (FLAG_PRECISION | FLAG_ZERO)) == 0) {
                            buf.write(PREFIX_NEGATIVE);
                        }
                        if (leadChar != '.') buf.write(leadChar);
                    }
                    buf.write(bytes,first,numlen);
                    if (width > 0) buf.fill(' ',width);
                    offset++;
                    incomplete = false;
                    break;
                }
                case 'E':
                case 'e':
                case 'f':
                case 'G':
                case 'g': {
                    if (arg == null) arg = args.next();
                    if (!(arg instanceof RubyFloat)) {
                        arg = RubyKernel.new_float(arg,arg);
                    }
                    double dval = ((RubyFloat)arg).getDoubleValue();
                    boolean nan = dval != dval;
                    boolean inf = dval == Double.POSITIVE_INFINITY || dval == Double.NEGATIVE_INFINITY;
                    boolean negative = dval < 0.0d;
                    byte[] digits;
                    int nDigits = 0;
                    int exponent = 0;
                    int len = 0;
                    byte signChar;
                    if (nan || inf) {
                        if (nan) {
                            digits = NAN_VALUE;
                            len = NAN_VALUE.length;
                        } else {
                            digits = INFINITY_VALUE;
                            len = INFINITY_VALUE.length;
                        }
                        if (negative) {
                            signChar = '-';
                            width--;
                        } else if ((flags & FLAG_PLUS) != 0) {
                            signChar = '+';
                            width--;
                        } else if ((flags & FLAG_SPACE) != 0) {
                            signChar = ' ';
                            width--;
                        } else {
                            signChar = 0;
                        }
                        width -= len;
                        if (width > 0 && (flags & (FLAG_ZERO|FLAG_MINUS)) == 0) {
                            buf.fill(' ',width);
                            width = 0;
                        }
                        if (signChar != 0) buf.write(signChar);
                        if (width > 0 && (flags & FLAG_MINUS) == 0) {
                            buf.fill('0',width);
                            width = 0;
                        }
                        buf.write(digits);
                        if (width > 0) buf.fill(' ', width);
                        offset++;
                        incomplete = false;
                        break;
                    }
                    String str = Double.toString(dval);
                    int strlen = str.length();
                    digits = new byte[strlen];
                    int nTrailingZeroes = 0;
                    int i = negative ? 1 : 0;
                    int decPos = 0;
                    byte ival;
                int_loop:
                    for ( ; i < strlen ; ) {
                        switch(ival = (byte)str.charAt(i++)) {
                        case '0':
                            if (nDigits > 0) nTrailingZeroes++;
                            break;
                        case '1': case '2': case '3': case '4':
                        case '5': case '6': case '7': case '8': case '9':
                            if (nTrailingZeroes > 0) {
                                for ( ; nTrailingZeroes > 0 ; nTrailingZeroes-- ) {
                                    digits[nDigits++] = '0';
                                }
                            }
                            digits[nDigits++] = ival;
                            break;
                        case '.':
                            break int_loop;
                        }
                    }
                    decPos = nDigits + nTrailingZeroes;
                dec_loop:
                    for ( ; i < strlen ; ) {
                        switch(ival = (byte)str.charAt(i++)) {
                        case '0':
                            if (nDigits > 0) {
                                nTrailingZeroes++;
                            } else {
                                exponent--;
                            }
                            break;
                        case '1': case '2': case '3': case '4':
                        case '5': case '6': case '7': case '8': case '9':
                            if (nTrailingZeroes > 0) {
                                for ( ; nTrailingZeroes > 0 ; nTrailingZeroes--  ) {
                                    digits[nDigits++] = '0';
                                }
                            }
                            digits[nDigits++] = ival;
                            break;
                        case 'E':
                            break dec_loop;
                        }
                    }
                    if ( i < strlen) {
                        int expSign;
                        int expVal = 0;
                        if (str.charAt(i) == '-') {
                            expSign = -1;
                            i++;
                        } else {
                            expSign = 1;
                        }
                        for ( ; i < strlen ; ) {
                            expVal = expVal * 10 + ((int)str.charAt(i++)-(int)'0');
                        }
                        exponent += expVal * expSign;
                    }
                    exponent += decPos - nDigits;
                    if (nDigits == 0) {
                        digits[0] = '0';
                        nDigits = 1;
                        exponent = 0;
                    }
                    int intDigits, intZeroes, intLength;
                    int decDigits, decZeroes, decLength;
                    byte expChar;
                    if (negative) {
                        signChar = '-';
                        width--;
                    } else if ((flags & FLAG_PLUS) != 0) {
                        signChar = '+';
                        width--;
                    } else if ((flags & FLAG_SPACE) != 0) {
                        signChar = ' ';
                        width--;
                    } else {
                        signChar = 0;
                    }
                    if ((flags & FLAG_PRECISION) == 0) {
                        precision = 6;
                    }
                    switch(fchar) {
                    case 'E':
                    case 'G':
                        expChar = 'E';
                        break;
                    case 'e':
                    case 'g':
                        expChar = 'e';
                        break;
                    default:
                        expChar = 0;
                    }
                    switch(fchar) {
                    case 'g':
                    case 'G':
                        boolean expForm = (exponent + nDigits - 1 < -4 ||
                            exponent + nDigits > (precision == 0 ? 1 : precision));
                        if (expForm) {
                            decDigits = nDigits - 1;
                            precision = Math.max(0,precision - 1);
                            if (precision < decDigits) {
                                int n = round(digits,nDigits,precision,precision!=0);
                                if (n > nDigits) {
                                    nDigits = n;
                                }
                                decDigits = Math.min(nDigits - 1,precision);
                            }
                            exponent += nDigits - 1;
                            boolean isSharp = (flags & FLAG_SHARP) != 0;
                            len++;
                            if (exponent > 99)
                            	len += 5;
                            else
                            	len += 4;
                            if (isSharp) {
                            	len++;
                            }
                            if (precision > 0) {
                            	if (!isSharp) {
                            	    int j = decDigits;
                            	    for (; j >= 1; j--) {
                            	        if (digits[j]== '0') {
                            	            decDigits--;
                            	        } else {
                            	            break;
                            	        }
                            	    }
                            	    if (decDigits > 0) {
                            	        len += 1;
                            	        len += decDigits;
                            	    }
                            	} else  {
                            	    len += precision;
                            	}
                            }
                            width -= len;
                            if (width > 0 && (flags & (FLAG_ZERO|FLAG_MINUS)) == 0) {
                                buf.fill(' ',width);
                                width = 0;
                            }
                            if (signChar != 0) {
                                buf.write(signChar);
                            }
                            if (width > 0 && (flags & FLAG_MINUS) == 0) {
                                buf.fill('0',width);
                                width = 0;
                            }
                            buf.write(digits[0]);
                            boolean dotToPrint = isSharp
                                    || (precision > 0 && decDigits > 0);
                            if (dotToPrint) {
                            	buf.write(args.getDecimalSeparator());
                            }
                            if (precision > 0 && decDigits > 0) {
                            	buf.write(digits, 1, decDigits);
                            	precision -= decDigits;
                            }
                            if (precision > 0 && isSharp) {
                            	buf.fill('0', precision);
                            }
                            writeExp(buf, exponent, expChar);
                            if (width > 0) {
                                buf.fill(' ', width);
                            }
                        } else {
                            intDigits = Math.max(0,Math.min(nDigits + exponent,nDigits));
                            intZeroes = Math.max(0,exponent);
                            intLength = intDigits + intZeroes;
                            decDigits = nDigits - intDigits;
                            decZeroes = Math.max(0,-(decDigits + exponent));
                            decLength = decZeroes + decDigits;
                            precision = Math.max(0,precision - intLength);
                            if (precision < decDigits) {
                                int n = round(digits,nDigits,intDigits+precision-1,precision!=0);
                                if (n > nDigits) {
                                    nDigits = n;
                                    intDigits = Math.max(0,Math.min(nDigits + exponent,nDigits));
                                    intLength = intDigits + intZeroes;
                                    decDigits = nDigits - intDigits;
                                    decZeroes = Math.max(0,-(decDigits + exponent));
                                    precision = Math.max(0,precision-1);
                                }
                                decDigits = precision;
                                decLength = decZeroes + decDigits;
                            }
                            len += intLength;
                            if (decLength > 0) {
                                len += decLength + 1;
                            } else {
                                if ((flags & FLAG_SHARP) != 0) {
                                    len++;
                                    if (precision > 0) {
                                        len += precision;
                                    }
                                }
                            }
                            width -= len;
                            if (width > 0 && (flags & (FLAG_ZERO|FLAG_MINUS)) == 0) {
                                buf.fill(' ',width);
                                width = 0;
                            }
                            if (signChar != 0) {
                                buf.write(signChar);
                            }
                            if (width > 0 && (flags & FLAG_MINUS) == 0) {
                                buf.fill('0',width);
                                width = 0;
                            }
                            if (intLength > 0){
                                if (intDigits > 0) {
                                    buf.write(digits,0,intDigits);
                                }
                                if (intZeroes > 0) {
                                    buf.fill('0',intZeroes);
                                }
                            } else {
                                buf.write('0');
                            }
                            if (decLength > 0 || (flags & FLAG_SHARP) != 0) {
                                buf.write(args.getDecimalSeparator());
                            }
                            if (decLength > 0) {
                                if (decZeroes > 0) {
                                    buf.fill('0',decZeroes);
                                    precision -= decZeroes;
                                }
                                if (decDigits > 0) {
                                    buf.write(digits,intDigits,decDigits);
                                    precision -= decDigits;
                                }
                                if ((flags & FLAG_SHARP) != 0 && precision > 0) {
                                    buf.fill('0',precision);
                                 }
                            }
                            if ((flags & FLAG_SHARP) != 0 && precision > 0) {
                                buf.fill('0',precision);
                            }
                            if (width > 0) {
                                buf.fill(' ', width);
                            }
                        }
                        break;
                    case 'f':
                        intDigits = Math.max(0,Math.min(nDigits + exponent,nDigits));
                        intZeroes = Math.max(0,exponent);
                        intLength = intDigits + intZeroes;
                        decDigits = nDigits - intDigits;
                        decZeroes = Math.max(0,-(decDigits + exponent));
                        decLength = decZeroes + decDigits;
                        if (precision < decLength) {
                            if (precision < decZeroes) {
                                decDigits = 0;
                                decZeroes = precision;
                            } else {
                                int n = round(digits,nDigits,intDigits+precision-decZeroes-1,precision!=0);
                                if (n > nDigits) {
                                    nDigits = n;
                                    intDigits = Math.max(0,Math.min(nDigits + exponent,nDigits));
                                    intLength = intDigits + intZeroes;
                                    decDigits = nDigits - intDigits;
                                    decZeroes = Math.max(0,-(decDigits + exponent));
                                    decLength = decZeroes + decDigits;
                                }
                                decDigits = precision - decZeroes;
                            }
                            decLength = decZeroes + decDigits;
                        }
                        if (precision > 0) {
                            len += Math.max(1,intLength) + 1 + precision;
                        } else {
                            len += Math.max(1,intLength);
                            if ((flags & FLAG_SHARP) != 0) {
                                len++;
                            }
                        }
                        width -= len;
                        if (width > 0 && (flags & (FLAG_ZERO|FLAG_MINUS)) == 0) {
                            buf.fill(' ',width);
                            width = 0;
                        }
                        if (signChar != 0) {
                            buf.write(signChar);
                        }
                        if (width > 0 && (flags & FLAG_MINUS) == 0) {
                            buf.fill('0',width);
                            width = 0;
                        }
                        if (intLength > 0){
                            if (intDigits > 0) {
                                buf.write(digits,0,intDigits);
                            }
                            if (intZeroes > 0) {
                                buf.fill('0',intZeroes);
                            }
                        } else {
                            buf.write('0');
                        }
                        if (precision > 0 || (flags & FLAG_SHARP) != 0) {
                            buf.write(args.getDecimalSeparator());
                        }
                        if (precision > 0) {
                            if (decZeroes > 0) {
                                buf.fill('0',decZeroes);
                                precision -= decZeroes;
                            }
                            if (decDigits > 0) {
                                buf.write(digits,intDigits,decDigits);
                                precision -= decDigits;
                            }
                            if (precision > 0) {
                                buf.fill('0',precision);
                            }
                        }
                        if (width > 0) {
                            buf.fill(' ', width);
                        }
                        break;
                    case 'E':
                    case 'e':
                        decDigits = nDigits - 1;
                        if (precision < decDigits) {
                            int n = round(digits,nDigits,precision,precision!=0);
                            if (n > nDigits) {
                                nDigits = n;
                            }
                            decDigits = Math.min(nDigits - 1,precision);
                        }
                        exponent += nDigits - 1;
                        boolean isSharp = (flags & FLAG_SHARP) != 0;
                        len++;
                        if (exponent > 99)
                            len += 5;
                        else
                            len += 4;
                        if (precision > 0) {
                            len += 1 + precision;
                        } else  if (isSharp) {
                            len++;
                        }
                        width -= len;
                        if (width > 0 && (flags & (FLAG_ZERO|FLAG_MINUS)) == 0) {
                            buf.fill(' ',width);
                            width = 0;
                        }
                        if (signChar != 0) {
                            buf.write(signChar);
                        }
                        if (width > 0 && (flags & FLAG_MINUS) == 0) {
                            buf.fill('0',width);
                            width = 0;
                        }
                        buf.write(digits[0]);
                        if (precision > 0) {
                            buf.write(args.getDecimalSeparator());
                            if (decDigits > 0) {
                                buf.write(digits,1,decDigits);
                                precision -= decDigits;
                            }
                            if (precision > 0) {
                                buf.fill('0',precision);
                            }
                        } else if ((flags & FLAG_SHARP) != 0) {
                            buf.write(args.getDecimalSeparator());
                        }
                        writeExp(buf, exponent, expChar);
                        if (width > 0) {
                            buf.fill(' ', width);
                        }
                        break;
                    }
                    offset++;
                    incomplete = false;
                    break;
                }
                }
            }
            if (incomplete) {
                if (flags == FLAG_NONE) {
                    buf.write('%');
                } else {
                    raiseArgumentError(args,ERR_ILLEGAL_FORMAT_CHAR);
                }
            }
        }
        return buf;
    }

Output:
    private static Buffer rubySprintfToBuffer(CharSequence charFormat, Args args) {
        byte[] format;
        Buffer buf = new Buffer();
        int offset;
        int length;
        int start;
        int mark;
        if (charFormat instanceof ByteList) {
            ByteList list = (ByteList)charFormat;
            format = list.unsafeBytes();
            int begin = list.begin();
            offset = begin;
            length = begin + list.length();
            start = begin;
            mark = begin;
        } else {
            format = stringToBytes(charFormat, false);
            offset = 0;
            length = charFormat.length();
            start = 0;
            mark = 0;
        }
        while (offset < length) {
            start = offset;
            for ( ; offset < length && format[offset] != '%'; offset++) ;
            if (offset > start) {
                buf.write(format,start,offset-start);
                start = offset;
            }
            if (offset++ >= length)
                break;
            IRubyObject arg = null;
            int flags = 0;
            int width = 0;
            int precision = 0;
            int number = 0;
            byte fchar = 0;
            boolean incomplete = true;
            for ( ; incomplete && offset < length ; ) {
                switch(fchar = format[offset]) {
                default:
                    if (fchar == '\0' && flags == FLAG_NONE) {
                        buf.write('%');
                        buf.write(fchar);
                        incomplete = false;
                        offset++;
                        break;
                    } else if (isPrintable(fchar)) {
                        raiseArgumentError(args,"malformed format string - %" + (char)fchar);
                    } else {
                        raiseArgumentError(args,ERR_MALFORMED_FORMAT);
                    }
                    break;
                case ' ':
                    flags |= FLAG_SPACE;
                    offset++;
                    break;
                case '0':
                    flags |= FLAG_ZERO;
                    offset++;
                    break;
                case '+':
                    flags |= FLAG_PLUS;
                    offset++;
                    break;
                case '-':
                    flags |= FLAG_MINUS;
                    offset++;
                    break;
                case '#':
                    flags |= FLAG_SHARP;
                    offset++;
                    break;
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                    number = 0;
                    for ( ; offset < length && isDigit(fchar = format[offset]); offset++) {
                        number = extendWidth(args, number, fchar);
                    }
                    checkOffset(args,offset,length,ERR_MALFORMED_NUM);
                    if (fchar == '$') {
                        if (arg != null) {
                            raiseArgumentError(args,"value given twice - " + number + "$");
                        }
                        arg = args.getNth(number);
                        offset++;
                    } else {
                        width = number;
                        flags |= FLAG_WIDTH;
                    }
                    break;
                case '*':
                    if ((flags & FLAG_WIDTH) != 0) {
                        raiseArgumentError(args,"width given twice");
                    }
                    flags |= FLAG_WIDTH;
                    checkOffset(args,++offset,length,ERR_MALFORMED_STAR_NUM);
                    mark = offset;
                    number = 0;
                    for ( ; offset < length && isDigit(fchar = format[offset]); offset++) {
                        number = extendWidth(args,number,fchar);
                    }
                    checkOffset(args,offset,length,ERR_MALFORMED_STAR_NUM);
                    if (fchar == '$') {
                        width = args.getNthInt(number);
                        if (width < 0) {
                            flags |= FLAG_MINUS;
                            width = -width;
                        }
                        offset++;
                    } else {
                        width = args.nextInt();
                        if (width < 0) {
                            flags |= FLAG_MINUS;
                            width = -width;
                        }
                        offset = mark;
                    }
                    break;
                case '.':
                    if ((flags & FLAG_PRECISION) != 0) {
                        raiseArgumentError(args,"precision given twice");
                    }
                    flags |= FLAG_PRECISION;
                    checkOffset(args,++offset,length,ERR_MALFORMED_DOT_NUM);
                    fchar = format[offset];
                    if (fchar == '*') {
                        checkOffset(args,++offset,length,ERR_MALFORMED_STAR_NUM);
                        mark = offset;
                        number = 0;
                        for ( ; offset < length && isDigit(fchar = format[offset]); offset++) {
                            number = extendWidth(args,number,fchar);
                        }
                        checkOffset(args,offset,length,ERR_MALFORMED_STAR_NUM);
                        if (fchar == '$') {
                            precision = args.getNthInt(number);
                            if (precision < 0) {
                                flags &= ~FLAG_PRECISION;
                            }
                            offset++;
                        } else {
                            precision = args.nextInt();
                            if (precision < 0) {
                                flags &= ~FLAG_PRECISION;
                            }
                            offset = mark;
                        }
                    } else {
                        number = 0;
                        for ( ; offset < length && isDigit(fchar = format[offset]); offset++) {
                            number = extendWidth(args,number,fchar);
                        }
                        checkOffset(args,offset,length,ERR_MALFORMED_DOT_NUM);
                        precision = number;
                    }
                    break;
                case '\n':
                    offset--;
                case '%':
                    if (flags != FLAG_NONE) {
                        raiseArgumentError(args,ERR_ILLEGAL_FORMAT_CHAR);
                    }
                    buf.write('%');
                    offset++;
                    incomplete = false;
                    break;
                case 'c': {
                    if (arg == null) arg = args.next();
                    int c = 0;
                    if (arg instanceof RubyString) {
                        ByteList bytes = ((RubyString)arg).getByteList();
                        if (bytes.length() == 1) {
                            c = bytes.unsafeBytes()[bytes.begin()];
                        } else {
                            raiseArgumentError(args,"%c requires a character");
                        }
                    } else {
                        c = args.intValue(arg);
                    }
                    if ((flags & FLAG_WIDTH) != 0 && width > 1) {
                        if ((flags & FLAG_MINUS) != 0) {
                            buf.write(c);
                            buf.fill(' ', width-1);
                        } else {
                            buf.fill(' ',width-1);
                            buf.write(c);
                        }
                    } else {
                        buf.write(c);
                    }
                    offset++;
                    incomplete = false;
                    break;
                }
                case 'p':
                case 's': {
                    if (arg == null) arg = args.next();
                    if (fchar == 'p') {
                        arg = arg.callMethod(arg.getRuntime().getCurrentContext(),"inspect");
                    }
                    ByteList bytes = arg.asString().getByteList();
                    int len = bytes.length();
                    if (arg.isTaint()) {
                        buf.tainted = true;
                    }
                    if ((flags & FLAG_PRECISION) != 0 && precision < len) {
                        len = precision;
                    }
                    if ((flags & FLAG_WIDTH) != 0 && width > len) {
                        width -= len;
                        if ((flags & FLAG_MINUS) != 0) {
                            buf.write(bytes.unsafeBytes(),bytes.begin(),len);
                            buf.fill(' ',width);
                        } else {
                            buf.fill(' ',width);
                            buf.write(bytes.unsafeBytes(),bytes.begin(),len);
                        }
                    } else {
                        buf.write(bytes.unsafeBytes(),bytes.begin(),len);
                    }
                    offset++;
                    incomplete = false;
                    break;
                }
                case 'd':
                case 'i':
                case 'o':
                case 'x':
                case 'X':
                case 'b':
                case 'B':
                case 'u': {
                    if (arg == null) arg = args.next();
                    int type = arg.getMetaClass().index;
                    if (type != ClassIndex.FIXNUM && type != ClassIndex.BIGNUM) {
                        switch(type) {
                        case ClassIndex.FLOAT:
                            arg = RubyNumeric.dbl2num(arg.getRuntime(),((RubyFloat)arg).getValue());
                            break;
                        case ClassIndex.STRING:
                            arg = RubyNumeric.str2inum(arg.getRuntime(),(RubyString)arg,0,true);
                            break;
                        default:
                            if (arg.respondsTo("to_int")) {
                                arg = TypeConverter.convertToType(arg, arg.getRuntime().getInteger(), MethodIndex.TO_INT, "to_int", true);
                            } else {
                                arg = TypeConverter.convertToType(arg, arg.getRuntime().getInteger(), MethodIndex.TO_I, "to_i", true);
                            }
                            break;
                        }
                        type = arg.getMetaClass().index;
                    }
                    byte[] bytes = null;
                    int first = 0;
                    byte[] prefix = null;
                    boolean sign;
                    boolean negative;
                    byte signChar = 0;
                    byte leadChar = 0;
                    int base;
                    if (fchar == 'i') fchar = 'd';
                    if (fchar == 'u' && (flags & (FLAG_SPACE | FLAG_PLUS)) != 0) {
                        fchar = 'd';
                    }
                    sign = (fchar == 'd' || (flags & (FLAG_SPACE | FLAG_PLUS)) != 0);
                    switch (fchar) {
                    case 'o':
                        base = 8; break;
                    case 'x':
                    case 'X':
                        base = 16; break;
                    case 'b':
                    case 'B':
                        base = 2; break;
                    case 'u':
                    case 'd':
                    default:
                        base = 10; break;
                    }
                    if ((flags & FLAG_SHARP) != 0) {
                        switch(fchar) {
                        case 'o': prefix = PREFIX_OCTAL; break;
                        case 'x': prefix = PREFIX_HEX_LC; break;
                        case 'X': prefix = PREFIX_HEX_UC; break;
                        case 'b': prefix = PREFIX_BINARY_LC; break;
                        case 'B': prefix = PREFIX_BINARY_UC; break;
                        }
                        if (prefix != null) width -= prefix.length;
                    }
                    if (type == ClassIndex.FIXNUM) {
                        negative = ((RubyFixnum)arg).getLongValue() < 0;
                        if (negative && fchar == 'u') {
                            bytes = getUnsignedNegativeBytes((RubyFixnum)arg);
                        } else {
                            bytes = getFixnumBytes((RubyFixnum)arg,base,sign,fchar=='X');
                        }
                    } else {
                        negative = ((RubyBignum)arg).getValue().signum() < 0;
                        if (negative && fchar == 'u') {
                            bytes = getUnsignedNegativeBytes((RubyBignum)arg);
                        } else {
                            bytes = getBignumBytes((RubyBignum)arg,base,sign,fchar=='X');
                        }
                    }
                    int len = 0;
                    if (sign) {
                        if (negative) {
                            signChar = '-';
                            width--;
                            first = 1;
                        } else if ((flags & FLAG_PLUS) != 0) {
                            signChar = '+';
                            width--;
                        } else if ((flags & FLAG_SPACE) != 0) {
                            signChar = ' ';
                            width--;
                        }
                    } else if (negative) {
                        if (base == 10) {
                            warning(args,"negative number for %u specifier");
                            leadChar = '.';
                            len += 2;
                        } else {
                            if ((flags & (FLAG_PRECISION | FLAG_ZERO)) == 0) len += 2;
                            first = skipSignBits(bytes,base);
                            switch(fchar) {
                            case 'b':
                            case 'B':
                                leadChar = '1';
                                break;
                            case 'o':
                                leadChar = '7';
                                break;
                            case 'x':
                                leadChar = 'f';
                                break;
                            case 'X':
                                leadChar = 'F';
                                break;
                            }
                            if (leadChar != 0) len++;
                        }
                    }
                    int numlen = bytes.length - first;
                    len += numlen;
                    if ((flags & (FLAG_ZERO|FLAG_PRECISION)) == FLAG_ZERO) {
                        precision = width;
                        width = 0;
                    } else {
                        if (precision < len) precision = len;
                        width -= precision;
                    }
                    if ((flags & FLAG_MINUS) == 0) {
                        buf.fill(' ',width);
                        width = 0;
                    }
                    if (signChar != 0) buf.write(signChar);
                    if (prefix != null) buf.write(prefix);
                    if (len < precision) {
                        if (leadChar == 0) {
                            buf.fill('0', precision - len);
                        } else if (leadChar == '.') {
                            buf.fill(leadChar,precision-len);
                            buf.write(PREFIX_NEGATIVE);
                        } else {
                            buf.fill(leadChar,precision-len+1);
                        }
                    } else if (leadChar != 0) {
                        if ((flags & (FLAG_PRECISION | FLAG_ZERO)) == 0) {
                            buf.write(PREFIX_NEGATIVE);
                        }
                        if (leadChar != '.') buf.write(leadChar);
                    }
                    buf.write(bytes,first,numlen);
                    if (width > 0) buf.fill(' ',width);
                    offset++;
                    incomplete = false;
                    break;
                }
                case 'E':
                case 'e':
                case 'f':
                case 'G':
                case 'g': {
                    if (arg == null) arg = args.next();
                    if (!(arg instanceof RubyFloat)) {
                        arg = RubyKernel.new_float(arg,arg);
                    }
                    double dval = ((RubyFloat)arg).getDoubleValue();
                    boolean nan = dval != dval;
                    boolean inf = dval == Double.POSITIVE_INFINITY || dval == Double.NEGATIVE_INFINITY;
                    boolean negative = dval < 0.0d;
                    byte[] digits;
                    int nDigits = 0;
                    int exponent = 0;
                    int len = 0;
                    byte signChar;
                    if (nan || inf) {
                        if (nan) {
                            digits = NAN_VALUE;
                            len = NAN_VALUE.length;
                        } else {
                            digits = INFINITY_VALUE;
                            len = INFINITY_VALUE.length;
                        }
                        if (negative) {
                            signChar = '-';
                            width--;
                        } else if ((flags & FLAG_PLUS) != 0) {
                            signChar = '+';
                            width--;
                        } else if ((flags & FLAG_SPACE) != 0) {
                            signChar = ' ';
                            width--;
                        } else {
                            signChar = 0;
                        }
                        width -= len;
                        if (width > 0 && (flags & (FLAG_ZERO|FLAG_MINUS)) == 0) {
                            buf.fill(' ',width);
                            width = 0;
                        }
                        if (signChar != 0) buf.write(signChar);
                        if (width > 0 && (flags & FLAG_MINUS) == 0) {
                            buf.fill('0',width);
                            width = 0;
                        }
                        buf.write(digits);
                        if (width > 0) buf.fill(' ', width);
                        offset++;
                        incomplete = false;
                        break;
                    }
                    String str = Double.toString(dval);
                    int strlen = str.length();
                    digits = new byte[strlen];
                    int nTrailingZeroes = 0;
                    int i = negative ? 1 : 0;
                    int decPos = 0;
                    byte ival;
                int_loop:
                    for ( ; i < strlen ; ) {
                        switch(ival = (byte)str.charAt(i++)) {
                        case '0':
                            if (nDigits > 0) nTrailingZeroes++;
                            break;
                        case '1': case '2': case '3': case '4':
                        case '5': case '6': case '7': case '8': case '9':
                            if (nTrailingZeroes > 0) {
                                for ( ; nTrailingZeroes > 0 ; nTrailingZeroes-- ) {
                                    digits[nDigits++] = '0';
                                }
                            }
                            digits[nDigits++] = ival;
                            break;
                        case '.':
                            break int_loop;
                        }
                    }
                    decPos = nDigits + nTrailingZeroes;
                dec_loop:
                    for ( ; i < strlen ; ) {
                        switch(ival = (byte)str.charAt(i++)) {
                        case '0':
                            if (nDigits > 0) {
                                nTrailingZeroes++;
                            } else {
                                exponent--;
                            }
                            break;
                        case '1': case '2': case '3': case '4':
                        case '5': case '6': case '7': case '8': case '9':
                            if (nTrailingZeroes > 0) {
                                for ( ; nTrailingZeroes > 0 ; nTrailingZeroes--  ) {
                                    digits[nDigits++] = '0';
                                }
                            }
                            digits[nDigits++] = ival;
                            break;
                        case 'E':
                            break dec_loop;
                        }
                    }
                    if ( i < strlen) {
                        int expSign;
                        int expVal = 0;
                        if (str.charAt(i) == '-') {
                            expSign = -1;
                            i++;
                        } else {
                            expSign = 1;
                        }
                        for ( ; i < strlen ; ) {
                            expVal = expVal * 10 + ((int)str.charAt(i++)-(int)'0');
                        }
                        exponent += expVal * expSign;
                    }
                    exponent += decPos - nDigits;
                    if (nDigits == 0) {
                        digits[0] = '0';
                        nDigits = 1;
                        exponent = 0;
                    }
                    int intDigits, intZeroes, intLength;
                    int decDigits, decZeroes, decLength;
                    byte expChar;
                    if (negative) {
                        signChar = '-';
                        width--;
                    } else if ((flags & FLAG_PLUS) != 0) {
                        signChar = '+';
                        width--;
                    } else if ((flags & FLAG_SPACE) != 0) {
                        signChar = ' ';
                        width--;
                    } else {
                        signChar = 0;
                    }
                    if ((flags & FLAG_PRECISION) == 0) {
                        precision = 6;
                    }
                    switch(fchar) {
                    case 'E':
                    case 'G':
                        expChar = 'E';
                        break;
                    case 'e':
                    case 'g':
                        expChar = 'e';
                        break;
                    default:
                        expChar = 0;
                    }
                    switch(fchar) {
                    case 'g':
                    case 'G':
                        boolean expForm = (exponent + nDigits - 1 < -4 ||
                            exponent + nDigits > (precision == 0 ? 1 : precision));
                        if (expForm) {
                            decDigits = nDigits - 1;
                            precision = Math.max(0,precision - 1);
                            if (precision < decDigits) {
                                int n = round(digits,nDigits,precision,precision!=0);
                                if (n > nDigits) {
                                    nDigits = n;
                                }
                                decDigits = Math.min(nDigits - 1,precision);
                            }
                            exponent += nDigits - 1;
                            boolean isSharp = (flags & FLAG_SHARP) != 0;
                            len++;
                            if (exponent > 99)
                            	len += 5;
                            else
                            	len += 4;
                            if (isSharp) {
                            	len++;
                            }
                            if (precision > 0) {
                            	if (!isSharp) {
                            	    int j = decDigits;
                            	    for (; j >= 1; j--) {
                            	        if (digits[j]== '0') {
                            	            decDigits--;
                            	        } else {
                            	            break;
                            	        }
                            	    }
                            	    if (decDigits > 0) {
                            	        len += 1;
                            	        len += decDigits;
                            	    }
                            	} else  {
                            	    len += precision;
                            	}
                            }
                            width -= len;
                            if (width > 0 && (flags & (FLAG_ZERO|FLAG_MINUS)) == 0) {
                                buf.fill(' ',width);
                                width = 0;
                            }
                            if (signChar != 0) {
                                buf.write(signChar);
                            }
                            if (width > 0 && (flags & FLAG_MINUS) == 0) {
                                buf.fill('0',width);
                                width = 0;
                            }
                            buf.write(digits[0]);
                            boolean dotToPrint = isSharp
                                    || (precision > 0 && decDigits > 0);
                            if (dotToPrint) {
                            	buf.write(args.getDecimalSeparator());
                            }
                            if (precision > 0 && decDigits > 0) {
                            	buf.write(digits, 1, decDigits);
                            	precision -= decDigits;
                            }
                            if (precision > 0 && isSharp) {
                            	buf.fill('0', precision);
                            }
                            writeExp(buf, exponent, expChar);
                            if (width > 0) {
                                buf.fill(' ', width);
                            }
                        } else {
                            intDigits = Math.max(0,Math.min(nDigits + exponent,nDigits));
                            intZeroes = Math.max(0,exponent);
                            intLength = intDigits + intZeroes;
                            decDigits = nDigits - intDigits;
                            decZeroes = Math.max(0,-(decDigits + exponent));
                            decLength = decZeroes + decDigits;
                            precision = Math.max(0,precision - intLength);
                            if (precision < decDigits) {
                                int n = round(digits,nDigits,intDigits+precision-1,precision!=0);
                                if (n > nDigits) {
                                    nDigits = n;
                                    intDigits = Math.max(0,Math.min(nDigits + exponent,nDigits));
                                    intLength = intDigits + intZeroes;
                                    decDigits = nDigits - intDigits;
                                    decZeroes = Math.max(0,-(decDigits + exponent));
                                    precision = Math.max(0,precision-1);
                                }
                                decDigits = precision;
                                decLength = decZeroes + decDigits;
                            }
                            len += intLength;
                            if (decLength > 0) {
                                len += decLength + 1;
                            } else {
                                if ((flags & FLAG_SHARP) != 0) {
                                    len++;
                                    if (precision > 0) {
                                        len += precision;
                                    }
                                }
                            }
                            width -= len;
                            if (width > 0 && (flags & (FLAG_ZERO|FLAG_MINUS)) == 0) {
                                buf.fill(' ',width);
                                width = 0;
                            }
                            if (signChar != 0) {
                                buf.write(signChar);
                            }
                            if (width > 0 && (flags & FLAG_MINUS) == 0) {
                                buf.fill('0',width);
                                width = 0;
                            }
                            if (intLength > 0){
                                if (intDigits > 0) {
                                    buf.write(digits,0,intDigits);
                                }
                                if (intZeroes > 0) {
                                    buf.fill('0',intZeroes);
                                }
                            } else {
                                buf.write('0');
                            }
                            if (decLength > 0 || (flags & FLAG_SHARP) != 0) {
                                buf.write(args.getDecimalSeparator());
                            }
                            if (decLength > 0) {
                                if (decZeroes > 0) {
                                    buf.fill('0',decZeroes);
                                    precision -= decZeroes;
                                }
                                if (decDigits > 0) {
                                    buf.write(digits,intDigits,decDigits);
                                    precision -= decDigits;
                                }
                                if ((flags & FLAG_SHARP) != 0 && precision > 0) {
                                    buf.fill('0',precision);
                                 }
                            }
                            if ((flags & FLAG_SHARP) != 0 && precision > 0) {
                                buf.fill('0',precision);
                            }
                            if (width > 0) {
                                buf.fill(' ', width);
                            }
                        }
                        break;
                    case 'f':
                        intDigits = Math.max(0,Math.min(nDigits + exponent,nDigits));
                        intZeroes = Math.max(0,exponent);
                        intLength = intDigits + intZeroes;
                        decDigits = nDigits - intDigits;
                        decZeroes = Math.max(0,-(decDigits + exponent));
                        decLength = decZeroes + decDigits;
                        if (precision < decLength) {
                            if (precision < decZeroes) {
                                decDigits = 0;
                                decZeroes = precision;
                            } else {
                                int n = round(digits,nDigits,intDigits+precision-decZeroes-1,precision!=0);
                                if (n > nDigits) {
                                    nDigits = n;
                                    intDigits = Math.max(0,Math.min(nDigits + exponent,nDigits));
                                    intLength = intDigits + intZeroes;
                                    decDigits = nDigits - intDigits;
                                    decZeroes = Math.max(0,-(decDigits + exponent));
                                    decLength = decZeroes + decDigits;
                                }
                                decDigits = precision - decZeroes;
                            }
                            decLength = decZeroes + decDigits;
                        }
                        if (precision > 0) {
                            len += Math.max(1,intLength) + 1 + precision;
                        } else {
                            len += Math.max(1,intLength);
                            if ((flags & FLAG_SHARP) != 0) {
                                len++;
                            }
                        }
                        width -= len;
                        if (width > 0 && (flags & (FLAG_ZERO|FLAG_MINUS)) == 0) {
                            buf.fill(' ',width);
                            width = 0;
                        }
                        if (signChar != 0) {
                            buf.write(signChar);
                        }
                        if (width > 0 && (flags & FLAG_MINUS) == 0) {
                            buf.fill('0',width);
                            width = 0;
                        }
                        if (intLength > 0){
                            if (intDigits > 0) {
                                buf.write(digits,0,intDigits);
                            }
                            if (intZeroes > 0) {
                                buf.fill('0',intZeroes);
                            }
                        } else {
                            buf.write('0');
                        }
                        if (precision > 0 || (flags & FLAG_SHARP) != 0) {
                            buf.write(args.getDecimalSeparator());
                        }
                        if (precision > 0) {
                            if (decZeroes > 0) {
                                buf.fill('0',decZeroes);
                                precision -= decZeroes;
                            }
                            if (decDigits > 0) {
                                buf.write(digits,intDigits,decDigits);
                                precision -= decDigits;
                            }
                            if (precision > 0) {
                                buf.fill('0',precision);
                            }
                        }
                        if (width > 0) {
                            buf.fill(' ', width);
                        }
                        break;
                    case 'E':
                    case 'e':
                        decDigits = nDigits - 1;
                        if (precision < decDigits) {
                            int n = round(digits,nDigits,precision,precision!=0);
                            if (n > nDigits) {
                                nDigits = n;
                            }
                            decDigits = Math.min(nDigits - 1,precision);
                        }
                        exponent += nDigits - 1;
                        boolean isSharp = (flags & FLAG_SHARP) != 0;
                        len++;
                        if (exponent > 99)
                            len += 5;
                        else
                            len += 4;
                        if (precision > 0) {
                            len += 1 + precision;
                        } else  if (isSharp) {
                            len++;
                        }
                        width -= len;
                        if (width > 0 && (flags & (FLAG_ZERO|FLAG_MINUS)) == 0) {
                            buf.fill(' ',width);
                            width = 0;
                        }
                        if (signChar != 0) {
                            buf.write(signChar);
                        }
                        if (width > 0 && (flags & FLAG_MINUS) == 0) {
                            buf.fill('0',width);
                            width = 0;
                        }
                        buf.write(digits[0]);
                        if (precision > 0) {
                            buf.write(args.getDecimalSeparator());
                            if (decDigits > 0) {
                                buf.write(digits,1,decDigits);
                                precision -= decDigits;
                            }
                            if (precision > 0) {
                                buf.fill('0',precision);
                            }
                        } else if ((flags & FLAG_SHARP) != 0) {
                            buf.write(args.getDecimalSeparator());
                        }
                        writeExp(buf, exponent, expChar);
                        if (width > 0) {
                            buf.fill(' ', width);
                        }
                        break;
                    }
                    offset++;
                    incomplete = false;
                    break;
                }
                }
            }
            if (incomplete) {
                if (flags == FLAG_NONE) {
                    buf.write('%');
                } else {
                    raiseArgumentError(args,ERR_ILLEGAL_FORMAT_CHAR);
                }
            }
        }
        return buf;
    }


Input:
    public static Color getColorForSeed(int seed){
        Random r = new Random(seed);
        double h,s,b;
        h=r.nextDouble()*360;
        s=r.nextDouble()%0.2+0.8;
        b=r.nextDouble()%0.2+0.8;
        return Color.hsb(h,s,b);
    }

Output:
    public static Color getColorForSeed(int seed){
        seed=Math.abs(seed);
        double h,s,b;
        h=((seed*0.12345)%1.0)*360;
        s=(seed*0.23456)%0.2+0.8;
        b=(seed*0.34567)%0.2+0.8;
        return Color.hsb(h,s,b);
    }


Input:
	public void testDisplayPodcastItemInfo() throws Exception {
		View itemView = getItemView(0);
		assertTextFieldHasText(itemView, "podcast_item_view_number", "#5192");
		assertTextFieldHasText(itemView, "podcast_item_view_date", "11.02.2012");
	}

Output:
	public void testDisplayPodcastItemInfo() throws Exception {
		View itemView = getItemView(0);
		assertTextFieldHasText(itemView, "podcast_item_view_number", "#5192");
		assertTextFieldHasText(itemView, "podcast_item_view_date", "12.02.2012");
	}


Input:
    public static boolean isNewerVersion(String installedVersion, String newVersion) {
        final String regex = "^[1-9\\.]+$";
        if (!installedVersion.matches(regex) || !newVersion.matches(regex)) {
            return false;
        }
        String[] currentParts = installedVersion.split("\\.");
        String[] newPartsParts = newVersion.split("\\.");
        int length = Math.max(currentParts.length, newPartsParts.length);
        for (int i=0; i< length; i++) {
            int currentPart = i < currentParts.length ?
                    Integer.parseInt(currentParts[i]) : 0;
            int newPart = i < newPartsParts.length ?
                    Integer.parseInt(newPartsParts[i]) : 0;
            if (currentPart < newPart) {
                return true;
            } else if (newPart < currentPart) {
                return false;
            }
        }
        return false;
    }

Output:
    public static boolean isNewerVersion(String installedVersion, String newVersion) {
        final String regex = "^\\d+(\\.\\d+)*$";
        if (!installedVersion.matches(regex) || !newVersion.matches(regex)) {
            return false;
        }
        String[] currentParts = installedVersion.split("\\.");
        String[] newPartsParts = newVersion.split("\\.");
        int length = Math.max(currentParts.length, newPartsParts.length);
        for (int i=0; i< length; i++) {
            int currentPart = i < currentParts.length ?
                    Integer.parseInt(currentParts[i]) : 0;
            int newPart = i < newPartsParts.length ?
                    Integer.parseInt(newPartsParts[i]) : 0;
            if (currentPart < newPart) {
                return true;
            } else if (newPart < currentPart) {
                return false;
            }
        }
        return false;
    }


Input:
    public  void addStageInXFERNodes( SubInfo job,
                                      Collection files,
                                      int type,
                                      Map<String,PoolTransfer> stageInMap,
                                      BundleValue bundleValue,
                                      Implementation implementation ){
        String jobName    = job.getName();
        String siteHandle = job.getSiteHandle();
        String key = null;
        String par = null;
        int bundle = -1;
        Set tempSet = new HashSet();
        int staged = 0;
        Collection stagedFiles = new ArrayList();
        Collection stageInExecJobs = new ArrayList();
        for(Iterator it = files.iterator();it.hasNext();) {
            FileTransfer ft = (FileTransfer) it.next();
            String lfn = ft.getLFN();
            key = this.constructFileKey(lfn, siteHandle);
            par = (String) mFileTable.get(key);
            if (par != null) {
                it.remove();
                tempSet.add(par);
                if(ft.isTransferringExecutableFile()){
                    String xBitJobName = (String)mSetupMap.get(key);
                    if(key == null){
                        throw new RuntimeException("Internal Pegasus Error while " +
                                                   "constructing bundled stagein jobs");
                    }
                    this.addRelation(xBitJobName,jobName);
                }
            } else {
                boolean contains = stageInMap.containsKey(siteHandle);
                if(!contains){
                    bundle = bundleValue.determine( implementation, job );
                }
                PoolTransfer pt = (contains)?
                                  (PoolTransfer)stageInMap.get(siteHandle):
                                  new PoolTransfer(siteHandle,bundle);
                if(!contains){
                    stageInMap.put(siteHandle,pt);
                }
                String newJobName = pt.addTransfer( ft, type );
                if(ft.isTransferringExecutableFile()){
                    stageInExecJobs.add( newJobName );
                    stagedFiles.add( ft );
                    mLogger.log("Entered " + key + "->" +
                                implementation.getSetXBitJobName(job.getName(),staged),
                                LogManager.DEBUG_MESSAGE_LEVEL);
                    mSetupMap.put(key,
                                  implementation.getSetXBitJobName(job.getName(),staged));
                    staged++;
                }
                mFileTable.put(key, newJobName);
                tempSet.add(newJobName);
            }
        }
        int index = 0;
        Iterator jobIt= stageInExecJobs.iterator();
        for( Iterator it = stagedFiles.iterator(); it.hasNext(); index++){
            Collection execFiles = new ArrayList(1);
            execFiles.add( it.next() );
            implementation.addSetXBitJobs(job, (String)jobIt.next(),
                                                         execFiles,
                                                         SubInfo.STAGE_IN_JOB,
                                                         index);
        }
        mRelationsMap.put(jobName,tempSet);
    }

Output:
    public  void addStageInXFERNodes( SubInfo job,
                                      Collection files,
                                      int type,
                                      Map<String,PoolTransfer> stageInMap,
                                      BundleValue bundleValue,
                                      Implementation implementation ){
        String jobName    = job.getName();
        String siteHandle = job.getSiteHandle();
        String key = null;
        String par = null;
        int bundle = -1;
        Set tempSet = new HashSet();
        int staged = 0;
        Collection stagedFiles = new ArrayList();
        Collection stageInExecJobs = new ArrayList();
        for(Iterator it = files.iterator();it.hasNext();) {
            FileTransfer ft = (FileTransfer) it.next();
            String lfn = ft.getLFN();
            key = this.constructFileKey(lfn, siteHandle);
            par = (String) mFileTable.get(key);
            if (par != null) {
                it.remove();
                tempSet.add(par);
                if(ft.isTransferringExecutableFile()){
                    String xBitJobName = (String)mSetupMap.get(key);
                    if(key == null){
                        throw new RuntimeException("Internal Pegasus Error while " +
                                                   "constructing bundled stagein jobs");
                    }
                    this.addRelation(xBitJobName,jobName);
                }
            } else {
                boolean contains = stageInMap.containsKey(siteHandle);
                if(!contains){
                    bundle = bundleValue.determine( implementation, job );
                }
                PoolTransfer pt = (contains)?
                                  (PoolTransfer)stageInMap.get(siteHandle):
                                  new PoolTransfer(siteHandle,bundle);
                if(!contains){
                    stageInMap.put(siteHandle,pt);
                }
                String newJobName = pt.addTransfer( ft, type );
                if(ft.isTransferringExecutableFile()){
                    stageInExecJobs.add( newJobName );
                    stagedFiles.add( ft );
                    mLogger.log("Entered " + key + "->" +
                                implementation.getSetXBitJobName(job.getName(),staged),
                                LogManager.DEBUG_MESSAGE_LEVEL);
                    mSetupMap.put(key,
                                  implementation.getSetXBitJobName(job.getName(),staged));
                    staged++;
                }
                mFileTable.put(key, newJobName);
                tempSet.add(newJobName);
            }
        }
        int index = 0;
        Iterator jobIt= stageInExecJobs.iterator();
        for( Iterator it = stagedFiles.iterator(); it.hasNext(); index++){
            Collection execFiles = new ArrayList(1);
            execFiles.add( it.next() );
            implementation.addSetXBitJobs(job, (String)jobIt.next(),
                                                         execFiles,
                                                         SubInfo.STAGE_IN_JOB,
                                                         index);
        }
        if( mRelationsMap.containsKey( jobName )){
            tempSet.addAll( (Set) mRelationsMap.get( jobName ) );
        }
        mRelationsMap.put(jobName,tempSet);
    }


Input:
    public void testFindById() throws Exception {
        when(fooDAO.findById(eq(9527L))).thenReturn(fooFactory.name("周星星").age(51).build());
        Foo zxx = fooDAO.findById(9527L);
        assertThat(zxx.getName()).isEqualTo("周星星");
        assertThat(zxx.getAge()).isEqualTo(51);
        verify(fooDAO, times(1)).findById(eq(9527L));
        verify(fooDAO, never()).findById(eq(1L));
    }

Output:
    public void testFindById() throws Exception {
        when(fooDAO.findById(eq(9527L))).thenReturn(fooFactory.name("周星星").age(51).build());
        Foo zxx = fooDAO.findById(9527L);
        assertThat(zxx.getName()).isEqualTo("周星星");
        assertThat(zxx.getAge()).isEqualTo(51);
        verify(fooDAO, times(1)).findById(9527L);
        verify(fooDAO, never()).findById(eq(1L));
    }


Input:
	public boolean generate(World var1, Random var2, int var3, int var4, int var5)
	{
		while (var1.isAirBlock(var3, var4, var5) && var4 > 2)
		{
			--var4;
		}
		int var6 = var1.getBlockId(var3, var4, var5);
		int var95 = var1.getBlockId(var3 - 1, var4, var5);
		int var96 = var1.getBlockId(var3 + 1, var4, var5);
		int var97 = var1.getBlockId(var3, var4, var5 - 1);
		int var98 = var1.getBlockId(var3, var4, var5 + 1);
		if (var6 != Block.grass.blockID || var95 != Block.grass.blockID || var96 != Block.grass.blockID || var97 != Block.grass.blockID || var98 != Block.grass.blockID )
			return false;
		else
		{
			for (int var7 = -2; var7 <= 2; ++var7)
			{
				for (int var8 = -2; var8 <= 2; ++var8)
				{
					if (var1.isAirBlock(var3 + var7, var4 - 1, var5 + var8) && var1.isAirBlock(var3 + var7, var4 - 2, var5 + var8))
						return false;
				}
			}
			int var999 = var2.nextInt(2);
			if (var999 == 0)
			{
				var1.setBlock(var3, var4, var5, Block.dirt.blockID);
				var1.setBlock(var3 - 1, var4, var5, Block.dirt.blockID);
				var1.setBlock(var3 + 1, var4, var5, Block.dirt.blockID);
				var1.setBlock(var3, var4, var5 - 1, Block.dirt.blockID);
				var1.setBlock(var3, var4, var5 + 1, Block.dirt.blockID);
				this.setBlockAndMetadata(var1, var3 + 1, var4 + 1, var5, Block.stone.blockID, 0);
				this.setBlockAndMetadata(var1, var3 - 1, var4 + 1, var5, Block.stone.blockID, 0);
				this.setBlockAndMetadata(var1, var3, var4 + 1, var5 + 1, Block.stone.blockID, 0);
				this.setBlockAndMetadata(var1, var3, var4 + 1, var5 - 1, Block.stone.blockID, 0);
				this.setBlockAndMetadata(var1, var3, var4 + 2, var5, Block.stone.blockID, 0);
				return true;
			}
			if (var999 == 1)
			{
				var1.setBlock(var3, var4, var5, Block.dirt.blockID);
				this.setBlockAndMetadata(var1, var3, var4 + 1, var5, Block.stone.blockID, 0);
				return true;
			}
			return true;
		}
	}

Output:
	public boolean generate(World var1, Random var2, int var3, int var4, int var5)
	{
		while (var1.isAirBlock(var3, var4, var5) && var4 > 2)
		{
			--var4;
		}
		int var6 = var1.getBlockId(var3, var4, var5);
		int var95 = var1.getBlockId(var3 - 1, var4, var5);
		int var96 = var1.getBlockId(var3 + 1, var4, var5);
		int var97 = var1.getBlockId(var3, var4, var5 - 1);
		int var98 = var1.getBlockId(var3, var4, var5 + 1);
		if (var6 != Block.grass.blockID || var95 != Block.grass.blockID || var96 != Block.grass.blockID || var97 != Block.grass.blockID || var98 != Block.grass.blockID )
			return false;
		else
		{
			for (int var7 = -2; var7 <= 2; ++var7)
			{
				for (int var8 = -2; var8 <= 2; ++var8)
				{
					if (var1.isAirBlock(var3 + var7, var4 - 1, var5 + var8) && var1.isAirBlock(var3 + var7, var4 - 2, var5 + var8))
						return false;
				}
			}
			int var999 = var2.nextInt(2);
			if (var999 == 0)
			{
				var1.setBlock(var3, var4, var5, Block.dirt.blockID);
				var1.setBlock(var3 - 1, var4, var5, Block.dirt.blockID);
				var1.setBlock(var3 + 1, var4, var5, Block.dirt.blockID);
				var1.setBlock(var3, var4, var5 - 1, Block.dirt.blockID);
				var1.setBlock(var3, var4, var5 + 1, Block.dirt.blockID);
				this.setBlockAndMetadata(var1, var3, var4 + 1, var5, Block.stone.blockID, 0);
				this.setBlockAndMetadata(var1, var3 + 1, var4 + 1, var5, Block.stone.blockID, 0);
				this.setBlockAndMetadata(var1, var3 - 1, var4 + 1, var5, Block.stone.blockID, 0);
				this.setBlockAndMetadata(var1, var3, var4 + 1, var5 + 1, Block.stone.blockID, 0);
				this.setBlockAndMetadata(var1, var3, var4 + 1, var5 - 1, Block.stone.blockID, 0);
				this.setBlockAndMetadata(var1, var3, var4 + 2, var5, Block.stone.blockID, 0);
				return true;
			}
			if (var999 == 1)
			{
				var1.setBlock(var3, var4, var5, Block.dirt.blockID);
				this.setBlockAndMetadata(var1, var3, var4 + 1, var5, Block.stone.blockID, 0);
				return true;
			}
			return true;
		}
	}


Input:
  public void testParsingAndSearching() throws Exception {
    String field = "content";
    QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, field, new MockAnalyzer());
    qp.setAllowLeadingWildcard(true);
    String docs[] = {
        "\\ abcdefg1",
        "\\79 hijklmn1",
        "\\\\ opqrstu1",
    };
    String matchAll[] = {
        "*", "*1", "**1", "*?", "*?1", "?*1", "**", "***", "\\\\*"
    };
    String matchNone[] = {
        "a*h", "a?h", "*a*h", "?a", "a?",
    };
    String matchOneDocPrefix[][] = {
        {"a*", "ab*", "abc*", },
        {"h*", "hi*", "hij*", "\\\\7*"},
        {"o*", "op*", "opq*", "\\\\\\\\*"},
    };
    String matchOneDocWild[][] = {
        {"*a*", "*ab*", "*abc**", "ab*e*", "*g?", "*f?1", "abc**"},
        {"*h*", "*hi*", "*hij**", "hi*k*", "*n?", "*m?1", "hij**"},
        {"*o*", "*op*", "*opq**", "op*q*", "*u?", "*t?1", "opq**"},
    };
    Directory dir = newDirectory();
    RandomIndexWriter iw = new RandomIndexWriter(random, dir);
    for (int i = 0; i < docs.length; i++) {
      Document doc = new Document();
      doc.add(newField(field,docs[i],Store.NO,Index.ANALYZED));
      iw.addDocument(doc);
    }
    iw.close();
    IndexSearcher searcher = new IndexSearcher(dir, true);
    for (int i = 0; i < matchAll.length; i++) {
      String qtxt = matchAll[i];
      Query q = qp.parse(qtxt);
      if (VERBOSE) System.out.println("matchAll: qtxt="+qtxt+" q="+q+" "+q.getClass().getName());
      ScoreDoc[] hits = searcher.search(q, null, 1000).scoreDocs;
      assertEquals(docs.length,hits.length);
    }
    for (int i = 0; i < matchNone.length; i++) {
      String qtxt = matchNone[i];
      Query q = qp.parse(qtxt);
      if (VERBOSE) System.out.println("matchNone: qtxt="+qtxt+" q="+q+" "+q.getClass().getName());
      ScoreDoc[] hits = searcher.search(q, null, 1000).scoreDocs;
      assertEquals(0,hits.length);
    }
    for (int i = 0; i < matchOneDocPrefix.length; i++) {
      for (int j = 0; j < matchOneDocPrefix[i].length; j++) {
        String qtxt = matchOneDocPrefix[i][j];
        Query q = qp.parse(qtxt);
        if (VERBOSE) System.out.println("match 1 prefix: doc="+docs[i]+" qtxt="+qtxt+" q="+q+" "+q.getClass().getName());
        assertEquals(PrefixQuery.class, q.getClass());
        ScoreDoc[] hits = searcher.search(q, null, 1000).scoreDocs;
        assertEquals(1,hits.length);
        assertEquals(i,hits[0].doc);
      }
    }
    for (int i = 0; i < matchOneDocPrefix.length; i++) {
      for (int j = 0; j < matchOneDocWild[i].length; j++) {
        String qtxt = matchOneDocWild[i][j];
        Query q = qp.parse(qtxt);
        if (VERBOSE) System.out.println("match 1 wild: doc="+docs[i]+" qtxt="+qtxt+" q="+q+" "+q.getClass().getName());
        assertEquals(WildcardQuery.class, q.getClass());
        ScoreDoc[] hits = searcher.search(q, null, 1000).scoreDocs;
        assertEquals(1,hits.length);
        assertEquals(i,hits[0].doc);
      }
    }
    searcher.close();
    dir.close();
  }

Output:
  public void testParsingAndSearching() throws Exception {
    String field = "content";
    QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, field, new MockAnalyzer());
    qp.setAllowLeadingWildcard(true);
    String docs[] = {
        "\\ abcdefg1",
        "\\79 hijklmn1",
        "\\\\ opqrstu1",
    };
    String matchAll[] = {
        "*", "*1", "**1", "*?", "*?1", "?*1", "**", "***", "\\\\*"
    };
    String matchNone[] = {
        "a*h", "a?h", "*a*h", "?a", "a?",
    };
    String matchOneDocPrefix[][] = {
        {"a*", "ab*", "abc*", },
        {"h*", "hi*", "hij*", "\\\\7*"},
        {"o*", "op*", "opq*", "\\\\\\\\*"},
    };
    String matchOneDocWild[][] = {
        {"*a*", "*ab*", "*abc**", "ab*e*", "*g?", "*f?1", "abc**"},
        {"*h*", "*hi*", "*hij**", "hi*k*", "*n?", "*m?1", "hij**"},
        {"*o*", "*op*", "*opq**", "op*q*", "*u?", "*t?1", "opq**"},
    };
    Directory dir = newDirectory();
    RandomIndexWriter iw = new RandomIndexWriter(random, dir,
        newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())
        .setMergePolicy(newInOrderLogMergePolicy()));
    for (int i = 0; i < docs.length; i++) {
      Document doc = new Document();
      doc.add(newField(field,docs[i],Store.NO,Index.ANALYZED));
      iw.addDocument(doc);
    }
    iw.close();
    IndexSearcher searcher = new IndexSearcher(dir, true);
    for (int i = 0; i < matchAll.length; i++) {
      String qtxt = matchAll[i];
      Query q = qp.parse(qtxt);
      if (VERBOSE) System.out.println("matchAll: qtxt="+qtxt+" q="+q+" "+q.getClass().getName());
      ScoreDoc[] hits = searcher.search(q, null, 1000).scoreDocs;
      assertEquals(docs.length,hits.length);
    }
    for (int i = 0; i < matchNone.length; i++) {
      String qtxt = matchNone[i];
      Query q = qp.parse(qtxt);
      if (VERBOSE) System.out.println("matchNone: qtxt="+qtxt+" q="+q+" "+q.getClass().getName());
      ScoreDoc[] hits = searcher.search(q, null, 1000).scoreDocs;
      assertEquals(0,hits.length);
    }
    for (int i = 0; i < matchOneDocPrefix.length; i++) {
      for (int j = 0; j < matchOneDocPrefix[i].length; j++) {
        String qtxt = matchOneDocPrefix[i][j];
        Query q = qp.parse(qtxt);
        if (VERBOSE) System.out.println("match 1 prefix: doc="+docs[i]+" qtxt="+qtxt+" q="+q+" "+q.getClass().getName());
        assertEquals(PrefixQuery.class, q.getClass());
        ScoreDoc[] hits = searcher.search(q, null, 1000).scoreDocs;
        assertEquals(1,hits.length);
        assertEquals(i,hits[0].doc);
      }
    }
    for (int i = 0; i < matchOneDocPrefix.length; i++) {
      for (int j = 0; j < matchOneDocWild[i].length; j++) {
        String qtxt = matchOneDocWild[i][j];
        Query q = qp.parse(qtxt);
        if (VERBOSE) System.out.println("match 1 wild: doc="+docs[i]+" qtxt="+qtxt+" q="+q+" "+q.getClass().getName());
        assertEquals(WildcardQuery.class, q.getClass());
        ScoreDoc[] hits = searcher.search(q, null, 1000).scoreDocs;
        assertEquals(1,hits.length);
        assertEquals(i,hits[0].doc);
      }
    }
    searcher.close();
    dir.close();
  }


Input:
  public void encodeChildren(FacesContext context, UIComponent component)
    throws IOException
  {
    if (!component.isRendered())
    {
      return;
    }
    String clientId = null;
    if (component.getId() != null &&
      !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
    {
      clientId = component.getClientId(context);
    }
    ResponseWriter writer = context.getResponseWriter();
    if (clientId != null)
    {
      writer.startElement("div", component);
    }
    List children = component.getChildren();
    String separator = (String) RendererUtil.getAttribute(context, component, "separator");
    if (separator==null) separator="";
    boolean first = true;
    for (Iterator iter = children.iterator(); iter.hasNext();)
    {
      UIComponent child = (UIComponent)iter.next();
      if (child.isRendered()) {
         if (!first) writer.write(separator);
         RendererUtil.encodeRecursive(context, child);
         first = false;
      }
    }
      if (clientId != null)
        {
        writer.endElement("div");
      }
  }

Output:
  public void encodeChildren(FacesContext context, UIComponent component)
    throws IOException
  {
    if (!component.isRendered())
    {
      return;
    }
    String clientId = null;
    if (component.getId() != null &&
      !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
    {
      clientId = component.getClientId(context);
    }
    ResponseWriter writer = context.getResponseWriter();
    if (clientId != null)
    {
      writer.startElement("div", component);
    }
    List children = component.getChildren();
    String separator = (String) RendererUtil.getAttribute(context, component, "separator");
    if (separator==null) separator="";
    boolean first = true;
    for (Iterator iter = children.iterator(); iter.hasNext();)
    {
      UIComponent child = (UIComponent)iter.next();
      if (child.isRendered()) {
         if (!first && separator !=null && separator != "") writer.write("<span class=\"separator\">" + separator + "</span>");
         RendererUtil.encodeRecursive(context, child);
         first = false;
      }
    }
      if (clientId != null)
        {
        writer.endElement("div");
      }
  }