package innovimax.mixthem.operation;

import static innovimax.mixthem.MixConstants.*;
import innovimax.mixthem.MixException;
import innovimax.mixthem.arguments.RuleParam;
import innovimax.mixthem.arguments.ParamValue;

import java.util.Map;

/**
* <p>Zips two characters.</p>
* @see CharOperation
* @author Innovimax
* @version 1.0
*/
public class DefaultCharZipping extends AbstractCharOperation {

	/**
	* Constructor
 	* @param params The list of parameters (maybe empty)
	* @see innovimax.mixthem.arguments.RuleParam
	* @see innovimax.mixthem.arguments.ParamValue
	*/
	public DefaultCharZipping(Map<RuleParam, ParamValue> params) {
		super(params);
	}
	
	@Override
	public int[] process(int c1, int c2) throws MixException, ProcessException {
		if (c1 == -1 || c2 == -1) {
			throw new ProcessException();
		}
		String sep = DEFAULT_ZIP_SEPARATOR;
		if (this.params.containsKey(RuleParam._ZIP_SEP)) {
			sep = this.params.get(RuleParam._ZIP_SEP).asString();
		}		
        	int[] zip = new int[2 + sep.length()];
        	int index = 0;
        	zip[index++] = c1;
        	for (int n = 0; n < sep.length(); n++) {
			int cn = sep.codePointAt(n);
			zip[index++] = cn;
		}
        	zip[index] = c2;
		return zip;
	}

}

@@ -723,95 +723,10 @@
 tion
-, ProcessException %7B%0A%09%09if (c1 == -1 %7C%7C c2 == -1) %7B%0A%09%09%09throw new ProcessException();%0A%09%09%7D
+ %7B
 %0A%09%09S
@@ -877,110 +877,151 @@
 %0A%09%09%7D
+%0A
 %09%09
-%0A        %09int%5B%5D zip = new int%5B2 + sep.length()%5D;%0A        %09int index = 0;%0A        %09zip%5Bindex++
+int len = (c1 != -1 ? 1 : 0) + sep.length() + (c2 != -1 ? 1 : 0);%0A        %09int%5B%5D zip = new int%5Blen%5D;%0A%09%09if (c1 != -1) %7B %0A%09%09%09zip%5B0
 %5D = c1;
+ %0A%09%09%7D
 %0A   
@@ -1039,16 +1039,16 @@
 int 
-n
+i
  = 0; 
-n
+i
  %3C s
@@ -1064,73 +1064,113 @@
 (); 
-n
+i
 ++) %7B
+%09%09%09
 %0A%09%09%09
-int cn = sep.codePointAt(n
+zip%5Bi + 1%5D = (int) sep.charAt(i
 );%0A%09%09
-%09zip%5Bindex++
+%7D%09%09%0A%09%09if (c2 != -1) %7B %0A%09%09%09zip%5Bzip.length - 1
 %5D = c
-n;
+2; 
 %0A%09%09%7D
-%0A
     
@@ -1178,24 +1178,8 @@
    %09
-zip%5Bindex%5D = c2;
 %0A%09%09r

update zip operation, remove process exception