package org.avmdti.josast.util;

/*
 * Created on Jul 22, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * convert an array of char in double or integer
 *
 * @author Xtophe 
 * @version 1.0
 */
public class ParseCharArray {
    //~ Methods -----------------------------------------------------------

    /* ------------------------------------------------------------------- *
     * ---------------------------- double_value ------------------------- *
     * ------------------------------------------------------------------- */
    











	/**
	 * 
	 * @param c1 Array of char
	 * @param pos First caractere to convert
	 * @param len Lenght of the convertion
	 * @return 
	 */


public static double double_value(char c1[], int pos, int len) {
        double d = 0;
        int i;
        int j = 0;

        for (i = 0; (i < len); i++) {
            switch (c1[i + pos]) {
            case ' ' :
                break;

            case '0' :
                d *= 10;

                break;

            case '1' :
                d *= 10;
                d++;

                break;

            case '2' :
                d *= 10;
                d += 2;

                break;

            case '3' :
                d *= 10;
                d += 3;

                break;

            case '4' :
                d *= 10;
                d += 4;

                break;

            case '5' :
                d *= 10;
                d += 5;

                break;

            case '6' :
                d *= 10;
                d += 6;

                break;

            case '7' :
                d *= 10;
                d += 7;

                break;

            case '8' :
                d *= 10;
                d += 8;

                break;

            case '9' :
                d *= 10;
                d += 9;

                break;

            case '.' :
                j = len - i - 1;

                break;

            default :
                break;
            }
        }

        d /= Math.pow(10.0, j);

        return d;
    }

	/**
	 * 
	 * @param c1 Array of char
	 * @param pos First caractere to convert
	 * @param len Lenght of the convertion
	 * @return 
	 */
    public static int integer_value(char c1[], int pos, int len) {
        int d = 0;
        int i;

        for (i = 0; (i < len); i++) {
            switch (c1[i + pos]) {
            case ' ' :
                break;

            case '0' :
                d *= 10;

                break;

            case '1' :
                d *= 10;
                d++;

                break;

            case '2' :
                d *= 10;
                d += 2;

                break;

            case '3' :
                d *= 10;
                d += 3;

                break;

            case '4' :
                d *= 10;
                d += 4;

                break;

            case '5' :
                d *= 10;
                d += 5;

                break;

            case '6' :
                d *= 10;
                d += 6;

                break;

            case '7' :
                d *= 10;
                d += 7;

                break;

            case '8' :
                d *= 10;
                d += 8;

                break;

            case '9' :
                d *= 10;
                d += 9;

                break;

            default :
                break;
            }
        }

        return d;
    }
}
