package jxl.biff;

import common.Logger;
import jxl.WorkbookSettings;

/* JADX INFO: loaded from: classes.dex */
public class EncodedURLHelper {
    public static /* synthetic */ Class class$jxl$biff$EncodedURLHelper;
    private static byte endOfSubdirectory;
    private static Logger logger;
    private static byte msDosDriveLetter;
    private static byte parentDirectory;
    private static byte sameDrive;
    private static byte unencodedUrl;

    static {
        Class clsClass$ = class$jxl$biff$EncodedURLHelper;
        if (clsClass$ == null) {
            clsClass$ = class$("jxl.biff.EncodedURLHelper");
            class$jxl$biff$EncodedURLHelper = clsClass$;
        }
        logger = Logger.getLogger(clsClass$);
        msDosDriveLetter = (byte) 1;
        sameDrive = (byte) 2;
        endOfSubdirectory = (byte) 3;
        parentDirectory = (byte) 4;
        unencodedUrl = (byte) 5;
    }

    public static /* synthetic */ Class class$(String str) {
        try {
            return Class.forName(str);
        } catch (ClassNotFoundException e2) {
            throw new NoClassDefFoundError(e2.getMessage());
        }
    }

    public static byte[] getEncodedURL(String str, WorkbookSettings workbookSettings) {
        return str.startsWith("http:") ? getURL(str, workbookSettings) : getFile(str, workbookSettings);
    }

    private static byte[] getFile(String str, WorkbookSettings workbookSettings) {
        int i2;
        String strSubstring;
        int length;
        ByteArray byteArray = new ByteArray();
        if (str.charAt(1) == ':') {
            byteArray.add(msDosDriveLetter);
            byteArray.add((byte) str.charAt(0));
            i2 = 2;
        } else {
            if (str.charAt(0) == '\\' || str.charAt(0) == '/') {
                byteArray.add(sameDrive);
            }
            i2 = 0;
        }
        while (true) {
            if (str.charAt(i2) != '\\' && str.charAt(i2) != '/') {
                break;
            }
            i2++;
        }
        while (i2 < str.length()) {
            int iIndexOf = str.indexOf(47, i2);
            int iIndexOf2 = str.indexOf(92, i2);
            int iMax = (iIndexOf == -1 || iIndexOf2 == -1) ? (iIndexOf == -1 || iIndexOf2 == -1) ? Math.max(iIndexOf, iIndexOf2) : 0 : Math.min(iIndexOf, iIndexOf2);
            if (iMax == -1) {
                strSubstring = str.substring(i2);
                length = str.length();
            } else {
                strSubstring = str.substring(i2, iMax);
                length = iMax + 1;
            }
            if (!strSubstring.equals(".")) {
                if (strSubstring.equals("..")) {
                    byteArray.add(parentDirectory);
                } else {
                    byteArray.add(StringHelper.getBytes(strSubstring, workbookSettings));
                }
            }
            if (length < str.length()) {
                byteArray.add(endOfSubdirectory);
            }
            i2 = length;
        }
        return byteArray.getBytes();
    }

    private static byte[] getURL(String str, WorkbookSettings workbookSettings) {
        ByteArray byteArray = new ByteArray();
        byteArray.add(unencodedUrl);
        byteArray.add((byte) str.length());
        byteArray.add(StringHelper.getBytes(str, workbookSettings));
        return byteArray.getBytes();
    }
}
