package com.cooleshow.base.utils;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import kotlin.jvm.internal.Intrinsics;

public class JsonUtil {

    @NotNull
    public static String formatJson(@Nullable String jsonStr) {
        if (jsonStr != null && !Intrinsics.areEqual("", jsonStr)) {
            StringBuilder sb = new StringBuilder();
            boolean last = false;
            char current = 0;
            int indent = 0;
            int i = 0;

            for(int var7 = jsonStr.length(); i < var7; ++i) {
                char lastcur = current;
                current = jsonStr.charAt(i);
                switch(current) {
                    case ',':
                        sb.append(current);
                        if (lastcur != '\\') {
                            sb.append('\n');
                            addIndentBlank(sb, indent);
                        }
                        break;
                    case '[':
                    case '{':
                        sb.append(current);
                        sb.append('\n');
                        ++indent;
                        addIndentBlank(sb, indent);
                        break;
                    case ']':
                    case '}':
                        sb.append('\n');
                        --indent;
                        addIndentBlank(sb, indent);
                        Intrinsics.checkNotNullExpressionValue(sb.append(current), "sb.append(current)");
                        break;
                    default:
                        Intrinsics.checkNotNullExpressionValue(sb.append(current), "sb.append(current)");
                }
            }

            String var10000 = sb.toString();
            Intrinsics.checkNotNullExpressionValue(var10000, "sb.toString()");
            return var10000;
        } else {
            return "";
        }
    }

    private static void addIndentBlank(StringBuilder sb, int indent) {
        int var3 = 0;

        for(int var4 = indent; var3 < var4; ++var3) {
            sb.append('\t');
        }

    }

    @NotNull
    public static String decodeUnicode(@NotNull String theString) {
        Intrinsics.checkNotNullParameter(theString, "theString");
        boolean aChar = false;
        int len = theString.length();
        StringBuffer outBuffer = new StringBuffer(len);
        int x = 0;

        while(true) {
            while(true) {
                while(x < len) {
                    char deChar = theString.charAt(x++);
                    if (deChar == '\\') {
                        deChar = theString.charAt(x++);
                        if (deChar == 'u') {
                            int value = 0;
                            int var7 = 0;

                            for(byte var8 = 3; var7 <= var8; ++var7) {
                                deChar = theString.charAt(x++);
                                switch(deChar) {
                                    case '0':
                                    case '1':
                                    case '2':
                                    case '3':
                                    case '4':
                                    case '5':
                                    case '6':
                                    case '7':
                                    case '8':
                                    case '9':
                                        value = (value << 4) + deChar - 48;
                                        break;
                                    case 'A':
                                    case 'B':
                                    case 'C':
                                    case 'D':
                                    case 'E':
                                    case 'F':
                                        value = (value << 4) + 10 + deChar - 65;
                                        break;
                                    case 'a':
                                    case 'b':
                                    case 'c':
                                    case 'd':
                                    case 'e':
                                    case 'f':
                                        value = (value << 4) + 10 + deChar - 97;
                                        break;
                                    default:

                                }
                            }

                            outBuffer.append((char)value);
                        } else {
                            if (deChar == 't') {
                                deChar = '\t';
                            } else if (deChar == 'r') {
                                deChar = '\r';
                            } else if (deChar == 'n') {
                                deChar = '\n';
                            } else if (deChar == 'f') {
                                deChar = '\f';
                            }

                            outBuffer.append(deChar);
                        }
                    } else {
                        outBuffer.append(deChar);
                    }
                }

                String var10000 = outBuffer.toString();
                Intrinsics.checkNotNullExpressionValue(var10000, "outBuffer.toString()");
                return var10000;
            }
        }
    }

    private JsonUtil() {
    }

}
