Skip to content

Commit 286a7d5

Browse files
author
杨利兵
committed
优化IOS生成器
1 parent b0b6c5d commit 286a7d5

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/main/java/com/yanglb/codegen/core/translator/impl/MsgIOSTranslatorImpl.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.yanglb.codegen.utils.Infos;
2525
import com.yanglb.codegen.utils.Resources;
2626
import com.yanglb.codegen.utils.StringUtil;
27+
import org.apache.commons.text.StringEscapeUtils;
2728

2829
public class MsgIOSTranslatorImpl extends BaseMsgTranslator {
2930
@Override
@@ -60,21 +61,23 @@ protected void onTranslate() throws CodeGenException {
6061
keys.put(id, true);
6162

6263
// 对字符串进行转换
63-
String value = this.convert2CSCode(itm.get(this.msgLang));
64+
id = escape(id);
65+
String value = this.escape(itm.get(this.msgLang));
6466
sb.append(String.format("\"%s\" = \"%s\";\r\n", id, value));
6567
}
6668
}
6769

6870
this.writableModel.setData(sb);
6971
}
7072

71-
private String convert2CSCode(String value) {
73+
private String escape(String value) {
7274
if(value == null) return null;
73-
74-
// 先替换\r\n,防止有文档只有\r或\n 后面再替换一次
75-
value = value.replaceAll("\r\n", "\\\\r\\\\n");
76-
value = value.replaceAll("\r", "\\\\r\\\\n");
77-
value = value.replaceAll("\n", "\\\\r\\\\n");
75+
76+
value = value.replaceAll("\\\\", "\\\\\\\\");
77+
value = value.replaceAll("\"", "\\\\\"");
78+
79+
value = value.replaceAll("\r", "");
80+
value = value.replaceAll("\n", "\\\\n");
7881
return value;
7982
}
8083
}

0 commit comments

Comments
 (0)