package com.eactive.eai.transformer;

import java.util.regex.Pattern;

public class InstructionTest {
	
	static Pattern simpleInstructionPattern = Pattern.compile("[ㄱ-ㅎ가-힣a-zA-Z0-9_\\-\\.\\[\\]]+");	
//	static Pattern simpleInstructionPattern = Pattern.compile("[\\(]+\\)");
	public static void main(String[] args) {
		
		
		String inst1 = "BFE_KFK124F440_REQ1.InData.CMS코드번호1";
		
		String inst2 = "ascii2ebcdic(BFE_KFK124F440_REQ1.InData.CMS코드번호1)"; 
		
		String inst3 = "trim(ascii2ebcdic(BFE_KFK124F440_REQ1.InData.CMS코드번호1))";
		
		String functionName = null;
		
		testInstruction(inst1);
		testInstruction(inst2);
		testInstruction(inst3);
		functionName = getFunction(inst1); 
		System.out.println("functionName = " + functionName);
		functionName = getFunction(inst2);
		System.out.println("functionName = " + functionName);
		functionName = getFunction(inst3);
		System.out.println("functionName = " + functionName);
	}
	public static void testInstruction(String instruction) {
		if (simpleInstructionPattern.matcher(instruction).matches()) {
    		System.out.println("simple="+instruction);
    		
    	} else {
    		System.out.println("function="+instruction);
    		
    	}		
	}
	
	public static String getFunction(String instruction) {
		String functionName = null;
		int sPos = instruction.indexOf("(");
		int sLastPos = instruction.lastIndexOf("(");
		int ePos = instruction.indexOf(")");
		
		if(sPos > -1 && ePos > -1 && sPos == sLastPos) {
			functionName = instruction.substring(sPos+1, ePos-1);
		}
//		System.out.println("functionName = " + functionName);
		return functionName;
	}
}
