package epson.print.ecclient;

import java.io.File;
import java.util.regex.Pattern;

public class EcClientLibUtil {
    public static final int CREATE_JOB_NAME_MAX_LENGTH = 256;

    public static String quoteForJsonString(String str) {
        if (str == null) {
            return null;
        }
        return Pattern.compile("([\"\\\\])").matcher(str).replaceAll("\\\\$1");
    }

    public static String getCreateJobFileName(int i, String str) throws IllegalArgumentException {
        if (str == null) {
            return null;
        }
        File file = new File(str);
        switch (i) {
            case 1:
                str = file.getName();
                if (str.length() > 256) {
                    throw new IllegalArgumentException();
                }
                break;
            case 2:
                str = file.getName();
                break;
            case 3:
                break;
            default:
                return null;
        }
        if (str.length() > 256) {
            str = str.substring(0, 256);
        }
        return quoteForJsonString(str);
    }
}
