/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hirka;

import java.nio.charset.Charset;
import java.util.ArrayList;

/**
 *
 * @author dimitri
 * http://www.utf8-chartable.de/unicode-utf8-table.pl?start=12352&utf8=0x
 */
public class Chars {
    private final int[][] smallChars = {{0xe3, 0x81, 0x81},
            {0xe3, 0x81, 0x83}, {0xe3, 0x81, 0x85},
            {0xe3, 0x81, 0x87}, {0xe3, 0x81, 0x89},
            {0xe3, 0x81, 0xa3}, {0xe3, 0x82, 0x83},
            {0xe3, 0x82, 0x85}, {0xe3, 0x82, 0x87},
            {0xe3, 0x82, 0x8e}, {0xe3, 0x82, 0x95},
            {0xe3, 0x82, 0x96}, {0xe3, 0x82, 0xa1},
            {0xe3, 0x82, 0xa3}, {0xe3, 0x82, 0xa5},
            {0xe3, 0x82, 0xa7}, {0xe3, 0x82, 0xa9},
            {0xe3, 0x83, 0x83}, {0xe3, 0x83, 0xa3},
            {0xe3, 0x83, 0xa5}, {0xe3, 0x83, 0xa7},
            {0xe3, 0x83, 0xae}, {0xe3, 0x83, 0xb5},
            {0xe3, 0x83, 0xb6}};

     private final int[][] cantBeDisplayedChars = {
            {0xe3, 0x82, 0x97}, {0xe3, 0x82, 0x98},
            {0xe3, 0x82, 0x9f}, {0xe3, 0x82, 0xa0},
            {0xe3, 0x83, 0xbf}};

     private final int[][] otherChars = {
            {0xe3, 0x82, 0x99}, {0xe3, 0x82, 0x9a},
            {0xe3, 0x82, 0x9b}, {0xe3, 0x82, 0x9c},
            {0xe3, 0x83, 0xbb}, {0xe3, 0x83, 0xbc},
            {0xe3, 0x83, 0xbd}, {0xe3, 0x83, 0xbe}
        };
     
     private ArrayList<String> chars;
    
    public Chars() {
        ArrayList<Triplet> listeTriplets = this.generateTriplets();
        this.chars = this.generateStrings(listeTriplets);      
    }
    
    private ArrayList<Triplet> generateTriplets() {
        int nbDeCaracteres = 191;
        int end = 0x81;
        int mid = 0x81;

        ArrayList<Triplet> listeTriplets = new ArrayList<Triplet>();
        Triplet triplet;


        for (int i = 0; i < nbDeCaracteres; i++) {

            triplet = new Triplet(0xe3, mid, end);

            if (!triplet.estDansTableau(this.smallChars)
                    && !triplet.estDansTableau(this.cantBeDisplayedChars)
                    && !triplet.estDansTableau(this.otherChars)) {
                listeTriplets.add(triplet);
            }

            end++;

            if (end > 0xbf && mid == 0x81) {
                end = 0x80;
                mid = 0x82;
            }

            if (end > 0xbf && mid == 0x82) {
                end = 0x80;
                mid = 0x83;
            }
        }
        
        return listeTriplets;
    }
    
    private ArrayList<String> generateStrings(ArrayList<Triplet> listeTriplets) {
        
            ArrayList<String> listeChars = new ArrayList<String>();
        
            byte[] byteArray = new byte[3];
            Triplet tmp;

            for (int i = 0; i < listeTriplets.size(); i++) {
                tmp = listeTriplets.get(i);

                try {
                    byteArray[0] = new Integer(tmp.get(0)).byteValue();
                    byteArray[1] = new Integer(tmp.get(1)).byteValue();
                    byteArray[2] = new Integer(tmp.get(2)).byteValue();
                } catch (Exception e) {
                }

                listeChars.add(new String(byteArray, Charset.forName("UTF-8")));
            }
            
            return listeChars;
    }
    
    public ArrayList<String> getChars() {
        return this.chars;
    }
    
}
