云执法小微版 v1.0.0版本的 MD5 值为:dfa1ab09653b3256f84dafdbda8bb96c
以下内容为反编译后的 TextUtil.java 源代码,内容仅作参考
package com.kedacom.lego.fast.data.websocket.log;
import android.text.InputFilter;
import android.text.Spanned;
import android.text.TextUtils;
import com.google.common.base.Ascii;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.regex.Pattern;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class TextUtil {
public static final InputFilter emojiFilter = new InputFilter() {
Pattern emoji = Pattern.compile("[🀀-🏿]|[🐀-\u1f7ff]|[☀-⟿]", 66);
@Override
public CharSequence filter(CharSequence charSequence, int i, int i2, Spanned spanned, int i3, int i4) {
if (this.emoji.matcher(charSequence).find()) {
return "";
}
return null;
}
};
private TextUtil() {
throw new IllegalStateException("you can't instantiate me!");
}
public static String str2HexStr(String str) {
char[] charArray = "0123456789ABCDEF".toCharArray();
StringBuilder sb = new StringBuilder("");
byte[] bytes = str.getBytes();
for (int i = 0; i < bytes.length; i++) {
sb.append(charArray[(bytes[i] & 240) >> 4]);
sb.append(charArray[bytes[i] & Ascii.SI]);
}
return sb.toString().trim();
}
public static String jsonFormat(String str) {
if (TextUtils.isEmpty(str)) {
return "Empty/Null json content";
}
try {
str = str.trim();
if (str.startsWith("{")) {
str = new JSONObject(str).toString(4);
} else if (str.startsWith("[")) {
str = new JSONArray(str).toString(4);
}
} catch (JSONException unused) {
}
return str;
}
public static String xmlFormat(String str) {
if (TextUtils.isEmpty(str)) {
return "Empty/Null xml content";
}
try {
StreamSource streamSource = new StreamSource(new StringReader(str));
StreamResult streamResult = new StreamResult(new StringWriter());
Transformer newTransformer = TransformerFactory.newInstance().newTransformer();
newTransformer.setOutputProperty("indent", "yes");
newTransformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
newTransformer.transform(streamSource, streamResult);
return streamResult.getWriter().toString().replaceFirst(">", ">\n");
} catch (TransformerException unused) {
return str;
}
}
}