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

import java.util.LinkedList;

/**
 *
 * @author chislim
 */
public class Utils
{

    public static char negacia = '¬';
    public static char velky = '∀';
    public static char maly = '∃';
    public static char implikacia = '⇒';
    public static char or = '∨';
    public static char or2 = '⋁';
    public static char and = '∧';
    public static LinkedList<String> vars = new LinkedList<String>();
    public static LinkedList<Integer> aktual = new LinkedList<Integer>();
    public static LinkedList<Integer> max = new LinkedList<Integer>();
    public static String finalPredikat = "";
    public static String answer = "";
    public static int bezOperacie = 1;

    
     
    public static String texToString(String s)
    {
        s=s.replace("\\forall","∀");
        s=s.replace("\\exists","∃");
        s=s.replace("\\_","_");
        s=s.replace("\\wedge","∧");
        s=s.replace("\\vee","∨");
        s=s.replace("\\Rightarrow","⇒");
        s=s.replace("\\neg","¬");
        return s;
    }
    
    
     
    public static String stringToTex(String s)
    {
        s=s.replace("∀","\\forall ");
        s=s.replace("∃","\\exists ");
        s=s.replace("_","\\_");
        s=s.replace("∧","\\wedge ");
        s=s.replace("∨","\\vee ");
        s=s.replace("⇒","\\Rightarrow ");
        s=s.replace("¬","\\neg ");
        return s;
    }
    
    public static void setAnswer(String s)
    {
        answer = s;
    }

    public static void setBezOperacie(int i)
    {
        bezOperacie = i;
    }

    public static void setFinalPredikat(String s)
    {
        finalPredikat = s;
    }

    public static String zmazanieMedzier(String s)
    {
        return s.replaceAll(" ", "");
    }

    public static String upravaZatvoriek(String s)
    {
        String t = s;
        t = t.replaceAll("[", "(");
        t = t.replaceAll("]", ")");
        t = t.replaceAll("{", "(");
        t = t.replaceAll("}", ")");
        return t;
    }

    public static String getWord(String s, int a)
    {

        String r = "";
        int i = a;
        
        while ((s.charAt(i) != Utils.velky) && (s.charAt(i) != Utils.negacia) && (s.charAt(i) != Utils.maly) && (s.charAt(i) != '(')) 
        {
            r = r + s.charAt(i);
            i++;
        }
        //    f.vypis("tu "+r);
        return r;
    }

    
    public static String substr(String s, int a, int b)
    {
    
        String r = "";
        
        for (int i = a; i <= b; i++)
        {
            r += s.charAt(i);
        }
        
        return r;
    }
    
    public static Boolean spravneUzatvorkovanie(String s) 
    {
        
        int otv = 0;
        
        for (int i = 0; i < s.length(); i++) 
        {
            if (s.charAt(i) == '(') 
            {
                otv++;
            }
            if (s.charAt(i) == ')') 
            {
                otv--;
            }
        }
        return otv == 0;
    }
}


