mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-04 09:34:20 +00:00
constant pool editing: escape strings
This commit is contained in:
@@ -914,7 +914,7 @@ public class AVM2Code implements Cloneable {
|
||||
if (info != null) {
|
||||
writer.appendNoHilight("method").newLine();
|
||||
writer.appendNoHilight("name ");
|
||||
writer.hilightSpecial(info.name_index == 0 ? "null" : "\"" + Helper.escapeString(info.getName(constants)) + "\"", HighlightSpecialType.METHOD_NAME);
|
||||
writer.hilightSpecial(info.name_index == 0 ? "null" : "\"" + Helper.escapeActionScriptString(info.getName(constants)) + "\"", HighlightSpecialType.METHOD_NAME);
|
||||
writer.newLine();
|
||||
if (info.flagExplicit()) {
|
||||
writer.appendNoHilight("flag ");
|
||||
|
||||
@@ -211,7 +211,7 @@ public class AVM2Instruction implements Cloneable, GraphSourceItem {
|
||||
s.append(" null");
|
||||
} else {
|
||||
s.append(" \"");
|
||||
s.append(Helper.escapeString(constants.getString(operands[i])));
|
||||
s.append(Helper.escapeActionScriptString(constants.getString(operands[i])));
|
||||
s.append("\"");
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.avm2.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
@@ -41,7 +42,7 @@ public class StringAVM2Item extends AVM2Item {
|
||||
|
||||
@Override
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
|
||||
return writer.append("\"" + Helper.escapeActionScriptString(value) + "\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -191,7 +191,7 @@ public class Multiname {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return constants.getNamespace(index).getKindStr() + "(" + (name == null ? "null" : "\"" + Helper.escapeString(name) + "\"") + (sub > 0 ? ",\"" + sub + "\"" : "") + ")";
|
||||
return constants.getNamespace(index).getKindStr() + "(" + (name == null ? "null" : "\"" + Helper.escapeActionScriptString(name) + "\"") + (sub > 0 ? ",\"" + sub + "\"" : "") + ")";
|
||||
}
|
||||
|
||||
private static String namespaceSetToString(AVM2ConstantPool constants, int index) {
|
||||
@@ -222,16 +222,16 @@ public class Multiname {
|
||||
switch (kind) {
|
||||
case QNAME:
|
||||
case QNAMEA:
|
||||
return getKindStr() + "(" + namespaceToString(constants, namespace_index) + "," + (name_index == 0 ? "null" : "\"" + Helper.escapeString(constants.getString(name_index)) + "\"") + ")";
|
||||
return getKindStr() + "(" + namespaceToString(constants, namespace_index) + "," + (name_index == 0 ? "null" : "\"" + Helper.escapeActionScriptString(constants.getString(name_index)) + "\"") + ")";
|
||||
case RTQNAME:
|
||||
case RTQNAMEA:
|
||||
return getKindStr() + "(" + (name_index == 0 ? "null" : "\"" + Helper.escapeString(constants.getString(name_index))) + "\"" + ")";
|
||||
return getKindStr() + "(" + (name_index == 0 ? "null" : "\"" + Helper.escapeActionScriptString(constants.getString(name_index))) + "\"" + ")";
|
||||
case RTQNAMEL:
|
||||
case RTQNAMELA:
|
||||
return getKindStr() + "()";
|
||||
case MULTINAME:
|
||||
case MULTINAMEA:
|
||||
return getKindStr() + "(" + (name_index == 0 ? "null" : "\"" + Helper.escapeString(constants.getString(name_index)) + "\"") + "," + namespaceSetToString(constants, namespace_set_index) + ")";
|
||||
return getKindStr() + "(" + (name_index == 0 ? "null" : "\"" + Helper.escapeActionScriptString(constants.getString(name_index)) + "\"") + "," + namespaceSetToString(constants, namespace_set_index) + ")";
|
||||
case MULTINAMEL:
|
||||
case MULTINAMELA:
|
||||
return getKindStr() + "(" + namespaceSetToString(constants, namespace_set_index) + ")";
|
||||
|
||||
@@ -137,7 +137,7 @@ public class ValueKind {
|
||||
ret = "" + constants.getDecimal(value_index);
|
||||
break;
|
||||
case CONSTANT_Utf8:
|
||||
ret = "\"" + Helper.escapeString(constants.getString(value_index)) + "\"";
|
||||
ret = "\"" + Helper.escapeActionScriptString(constants.getString(value_index)) + "\"";
|
||||
break;
|
||||
case CONSTANT_True:
|
||||
ret = "true";
|
||||
@@ -179,7 +179,7 @@ public class ValueKind {
|
||||
ret = "Decimal(" + constants.getDecimal(value_index) + ")";
|
||||
break;
|
||||
case CONSTANT_Utf8:
|
||||
ret = "Utf8(\"" + Helper.escapeString(constants.getString(value_index)) + "\")";
|
||||
ret = "Utf8(\"" + Helper.escapeActionScriptString(constants.getString(value_index)) + "\")";
|
||||
break;
|
||||
case CONSTANT_True:
|
||||
ret = "True";
|
||||
|
||||
@@ -603,7 +603,7 @@ public abstract class Action implements GraphSourceItem {
|
||||
for (String c : cPool.constantPool) {
|
||||
writer.appendNoHilight(constIdx);
|
||||
writer.appendNoHilight("|");
|
||||
writer.appendNoHilight(c);
|
||||
writer.appendNoHilight(Helper.escapeString(c));
|
||||
writer.newLine();
|
||||
constIdx++;
|
||||
}
|
||||
|
||||
@@ -166,10 +166,10 @@ public class DirectValueActionItem extends ActionItem {
|
||||
}
|
||||
}
|
||||
if (value instanceof String) {
|
||||
return writer.append("\"" + Helper.escapeString((String) value) + "\"");
|
||||
return writer.append("\"" + Helper.escapeActionScriptString((String) value) + "\"");
|
||||
}
|
||||
if (value instanceof ConstantIndex) {
|
||||
return writer.append("\"" + Helper.escapeString(this.constants.get(((ConstantIndex) value).index)) + "\"");
|
||||
return writer.append("\"" + Helper.escapeActionScriptString(this.constants.get(((ConstantIndex) value).index)) + "\"");
|
||||
}
|
||||
if (value instanceof RegisterNumber) {
|
||||
return writer.append(((RegisterNumber) value).translate());
|
||||
|
||||
@@ -37,7 +37,7 @@ public class GetURLActionItem extends ActionItem {
|
||||
writer.append("getUrl");
|
||||
writer.spaceBeforeCallParenthesies(2);
|
||||
writer.append("(\"");
|
||||
writer.append(Helper.escapeString(urlString) + "\", \"" + Helper.escapeString(targetString));
|
||||
writer.append(Helper.escapeActionScriptString(urlString) + "\", \"" + Helper.escapeActionScriptString(targetString));
|
||||
return writer.append("\")");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.action.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
@@ -39,7 +40,7 @@ public class GotoLabelActionItem extends ActionItem {
|
||||
writer.append("gotoAndStop");
|
||||
writer.spaceBeforeCallParenthesies(1);
|
||||
writer.append("(\"");
|
||||
writer.append("(\"");
|
||||
writer.append(Helper.escapeActionScriptString(label));
|
||||
return writer.append("\")");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.action.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
@@ -36,7 +37,7 @@ public class SetTargetActionItem extends ActionItem {
|
||||
@Override
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
|
||||
writer.append("tellTarget(\"");
|
||||
writer.append("tellTarget(\"");
|
||||
writer.append(Helper.escapeActionScriptString(target));
|
||||
return writer.append("\")");
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ public class ActionGetURL extends Action {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GetUrl \"" + Helper.escapeString(urlString) + "\" \"" + Helper.escapeString(targetString) + "\"";
|
||||
return "GetUrl \"" + Helper.escapeActionScriptString(urlString) + "\" \"" + Helper.escapeActionScriptString(targetString) + "\"";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.action.swf3;
|
||||
|
||||
import com.jpexs.decompiler.flash.SWFInputStream;
|
||||
@@ -47,7 +48,7 @@ public class ActionGoToLabel extends Action {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
public String toString() {
|
||||
return "GoToLabel \"" + Helper.escapeActionScriptString(label) + "\"";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.action.swf3;
|
||||
|
||||
import com.jpexs.decompiler.flash.SWFInputStream;
|
||||
@@ -47,7 +48,7 @@ public class ActionSetTarget extends Action {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
public String toString() {
|
||||
return "SetTarget \"" + Helper.escapeActionScriptString(targetName) + "\"";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -279,7 +279,7 @@ public class ActionPush extends Action {
|
||||
((ConstantIndex) values.get(i)).constantPool = constantPool;
|
||||
ret = ((ConstantIndex) values.get(i)).toString();
|
||||
} else if (values.get(i) instanceof String) {
|
||||
ret = "\"" + Helper.escapeString((String) values.get(i)) + "\"";
|
||||
ret = "\"" + Helper.escapeActionScriptString((String) values.get(i)) + "\"";
|
||||
} else if (values.get(i) instanceof RegisterNumber) {
|
||||
ret = ((RegisterNumber) values.get(i)).toStringNoName();
|
||||
} else {
|
||||
|
||||
@@ -55,7 +55,7 @@ public class ConstantIndex implements Serializable {
|
||||
if (Configuration.resolveConstants.get()) {
|
||||
if (constantPool != null) {
|
||||
if (index < constantPool.size()) {
|
||||
return "\"" + Helper.escapeString(constantPool.get(index)) + "\"";
|
||||
return "\"" + Helper.escapeActionScriptString(constantPool.get(index)) + "\"";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.action.swf5;
|
||||
|
||||
import com.jpexs.decompiler.flash.SWFInputStream;
|
||||
@@ -82,7 +83,7 @@ public class ActionConstantPool extends Action {
|
||||
StringBuilder ret = new StringBuilder();
|
||||
ret.append("ConstantPool");
|
||||
for (int i = 0; i < constantPool.size(); i++) {
|
||||
for (int i = 0; i < constantPool.size(); i++) {
|
||||
ret.append(" \"").append(Helper.escapeActionScriptString(constantPool.get(i))).append("\"");
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
@@ -113,10 +113,10 @@ public class ActionDefineFunction extends Action implements GraphSourceItemConta
|
||||
public String getASMSource(ActionList container, Set<Long> knownAddreses, ScriptExportMode exportMode) {
|
||||
StringBuilder paramStr = new StringBuilder();
|
||||
for (int i = 0; i < paramNames.size(); i++) {
|
||||
paramStr.append("\"").append(Helper.escapeString(paramNames.get(i))).append("\" ");
|
||||
paramStr.append("\"").append(Helper.escapeActionScriptString(paramNames.get(i))).append("\" ");
|
||||
}
|
||||
|
||||
return "DefineFunction \"" + Helper.escapeString(functionName) + "\" " + paramNames.size() + " " + paramStr + " {" + (codeSize == 0 ? "\r\n}" : "");// + "\r\n" +Action.actionsToString(getAddress() + getHeaderLength(),getItems(container) , knownAddreses, constantPool, version, hex, getFileAddress() + hdrSize) + "}";
|
||||
return "DefineFunction \"" + Helper.escapeActionScriptString(functionName) + "\" " + paramNames.size() + " " + paramStr + " {" + (codeSize == 0 ? "\r\n}" : "");// + "\r\n" +Action.actionsToString(getAddress() + getHeaderLength(),getItems(container) , knownAddreses, constantPool, version, hex, getFileAddress() + hdrSize) + "}";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -202,10 +202,10 @@ public class ActionDefineFunction2 extends Action implements GraphSourceItemCont
|
||||
public String getASMSource(ActionList container, Set<Long> knownAddreses, ScriptExportMode exportMode) {
|
||||
StringBuilder paramStr = new StringBuilder();
|
||||
for (int i = 0; i < paramNames.size(); i++) {
|
||||
paramStr.append(paramRegisters.get(i)).append(" \"").append(Helper.escapeString(paramNames.get(i))).append("\" ");
|
||||
paramStr.append(paramRegisters.get(i)).append(" \"").append(Helper.escapeActionScriptString(paramNames.get(i))).append("\" ");
|
||||
}
|
||||
|
||||
return ("DefineFunction2 \"" + Helper.escapeString(functionName) + "\" " + paramRegisters.size() + " " + registerCount
|
||||
return ("DefineFunction2 \"" + Helper.escapeActionScriptString(functionName) + "\" " + paramRegisters.size() + " " + registerCount
|
||||
+ " " + preloadParentFlag
|
||||
+ " " + preloadRootFlag
|
||||
+ " " + suppressSuperFlag
|
||||
|
||||
@@ -168,7 +168,7 @@ public class ActionTry extends Action implements GraphSourceItemContainer {
|
||||
if (catchInRegisterFlag) {
|
||||
ret.append("register").append(catchRegister);
|
||||
} else {
|
||||
ret.append("\"").append(Helper.escapeString(catchName)).append("\"");
|
||||
ret.append("\"").append(Helper.escapeActionScriptString(catchName)).append("\"");
|
||||
}
|
||||
ret.append(" ");
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class DefineText2Tag extends TextTag {
|
||||
if (fnt == null) {
|
||||
writer.append(AppResources.translate("fontNotFound").replace("%fontId%", Integer.toString(rec.fontId)));
|
||||
} else {
|
||||
writer.hilightSpecial(Helper.escapeString(rec.getText(fnt)).replace("[", "\\[").replace("]", "\\]"), HighlightSpecialType.TEXT);
|
||||
writer.hilightSpecial(Helper.escapeActionScriptString(rec.getText(fnt)).replace("[", "\\[").replace("]", "\\]"), HighlightSpecialType.TEXT);
|
||||
}
|
||||
}
|
||||
return new HighlightedText(writer);
|
||||
|
||||
@@ -189,7 +189,7 @@ public class DefineTextTag extends TextTag {
|
||||
if (fnt == null) {
|
||||
writer.append(AppResources.translate("fontNotFound").replace("%fontId%", Integer.toString(rec.fontId)));
|
||||
} else {
|
||||
writer.hilightSpecial(Helper.escapeString(rec.getText(fnt)).replace("[", "\\[").replace("]", "\\]"), HighlightSpecialType.TEXT);
|
||||
writer.hilightSpecial(Helper.escapeActionScriptString(rec.getText(fnt)).replace("[", "\\[").replace("]", "\\]"), HighlightSpecialType.TEXT);
|
||||
}
|
||||
}
|
||||
return new HighlightedText(writer);
|
||||
|
||||
@@ -181,8 +181,38 @@ public class Helper {
|
||||
ret.append("\\t");
|
||||
} else if (c == '\b') {
|
||||
ret.append("\\b");
|
||||
} else if (c == '\f') {
|
||||
ret.append("\\f");
|
||||
} else if (c == '\\') {
|
||||
ret.append("\\\\");
|
||||
} else if (c < 32) {
|
||||
ret.append("\\x").append(padZeros(Integer.toHexString((int) c), 2));
|
||||
} else {
|
||||
ret.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes string by adding backslashes
|
||||
*
|
||||
* @param s String to escape
|
||||
* @return Escaped string
|
||||
*/
|
||||
public static String escapeActionScriptString(String s) {
|
||||
StringBuilder ret = new StringBuilder(s.length());
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
if (c == '\n') {
|
||||
ret.append("\\n");
|
||||
} else if (c == '\r') {
|
||||
ret.append("\\r");
|
||||
} else if (c == '\t') {
|
||||
ret.append("\\t");
|
||||
} else if (c == '\b') {
|
||||
ret.append("\\b");
|
||||
} else if (c == '\f') {
|
||||
ret.append("\\f");
|
||||
} else if (c == '\\') {
|
||||
@@ -219,8 +249,6 @@ public class Helper {
|
||||
ret.append("\\t");
|
||||
} else if (c == '\b') {
|
||||
ret.append("\\b");
|
||||
} else if (c == '\t') {
|
||||
ret.append("\\t");
|
||||
} else if (c == '\f') {
|
||||
ret.append("\\f");
|
||||
} else if (c == '\\') {
|
||||
@@ -237,6 +265,96 @@ public class Helper {
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unescapes a string that contains standard Java escape sequences.
|
||||
* <ul>
|
||||
* <li><strong>\b \f \n \r \t \" \'</strong> :
|
||||
* BS, FF, NL, CR, TAB, double and single quote.</li>
|
||||
* <li><strong>\X \XX \XXX</strong> : Octal character
|
||||
* specification (0 - 377, 0x00 - 0xFF).</li>
|
||||
* <li><strong>\uXXXX</strong> : Hexadecimal based Unicode
|
||||
* character.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param st
|
||||
* A string optionally containing standard java escape sequences.
|
||||
* @return The translated string.
|
||||
*/
|
||||
public static String unescapeJavaString(String st) {
|
||||
|
||||
StringBuilder sb = new StringBuilder(st.length());
|
||||
|
||||
for (int i = 0; i < st.length(); i++) {
|
||||
char ch = st.charAt(i);
|
||||
if (ch == '\\') {
|
||||
char nextChar = (i == st.length() - 1) ? '\\' : st
|
||||
.charAt(i + 1);
|
||||
// Octal escape?
|
||||
if (nextChar >= '0' && nextChar <= '7') {
|
||||
String code = "" + nextChar;
|
||||
i++;
|
||||
if ((i < st.length() - 1) && st.charAt(i + 1) >= '0'
|
||||
&& st.charAt(i + 1) <= '7') {
|
||||
code += st.charAt(i + 1);
|
||||
i++;
|
||||
if ((i < st.length() - 1) && st.charAt(i + 1) >= '0'
|
||||
&& st.charAt(i + 1) <= '7') {
|
||||
code += st.charAt(i + 1);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
sb.append((char) Integer.parseInt(code, 8));
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (nextChar) {
|
||||
case '\\':
|
||||
ch = '\\';
|
||||
break;
|
||||
case 'b':
|
||||
ch = '\b';
|
||||
break;
|
||||
case 'f':
|
||||
ch = '\f';
|
||||
break;
|
||||
case 'n':
|
||||
ch = '\n';
|
||||
break;
|
||||
case 'r':
|
||||
ch = '\r';
|
||||
break;
|
||||
case 't':
|
||||
ch = '\t';
|
||||
break;
|
||||
case '\"':
|
||||
ch = '\"';
|
||||
break;
|
||||
case '\'':
|
||||
ch = '\'';
|
||||
break;
|
||||
// Hex Unicode: u????
|
||||
case 'u':
|
||||
if (i >= st.length() - 5) {
|
||||
ch = 'u';
|
||||
break;
|
||||
}
|
||||
int code = Integer.parseInt(
|
||||
"" + st.charAt(i + 2) + st.charAt(i + 3)
|
||||
+ st.charAt(i + 4) + st.charAt(i + 5), 16);
|
||||
sb.append(Character.toChars(code));
|
||||
i += 5;
|
||||
continue;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
sb.append(ch);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String getValidHtmlId(String text) {
|
||||
// ID and NAME tokens must begin with a letter ([A-Za-z]) and
|
||||
// may be followed by any number of letters, digits ([0-9]),
|
||||
@@ -863,7 +981,7 @@ public class Helper {
|
||||
|
||||
String[] parts = line.split("\\|", 2);
|
||||
if (parts.length >= 2) {
|
||||
cPool.add(parts[1]);
|
||||
cPool.add(unescapeJavaString(parts[1]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user