【修复】修改导出lua数据未正确处理换行符之类的escape的bug
parent
c0d91dfa81
commit
aab29ed828
|
|
@ -10,9 +10,14 @@ namespace Luban.Job.Cfg.DataVisitors
|
|||
{
|
||||
public static ToLuaLiteralVisitor Ins { get; } = new();
|
||||
|
||||
public override string Accept(DString type)
|
||||
{
|
||||
return DataUtil.EscapeLuaStringWithQuote(type.Value);
|
||||
}
|
||||
|
||||
public override string Accept(DText type)
|
||||
{
|
||||
return $"{{{DText.KEY_NAME}='{type.Key}',{DText.TEXT_NAME}=\"{DataUtil.EscapeString(type.TextOfCurrentAssembly)}\"}}";
|
||||
return $"{{{DText.KEY_NAME}='{type.Key}',{DText.TEXT_NAME}={DataUtil.EscapeLuaStringWithQuote(type.TextOfCurrentAssembly)}}}";
|
||||
}
|
||||
|
||||
public override string Accept(DBean type)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Luban.Job.Cfg.Utils
|
||||
{
|
||||
|
|
@ -111,6 +112,38 @@ namespace Luban.Job.Cfg.Utils
|
|||
return s.Replace("\\", "\\\\").Replace("\"", "\\\"");
|
||||
}
|
||||
|
||||
public static string EscapeLuaStringWithQuote(string s)
|
||||
{
|
||||
if (!s.Contains('\"') && !s.Contains('\\') && !s.Contains('\n'))
|
||||
{
|
||||
return "\"" + s + "\"";
|
||||
}
|
||||
|
||||
var multiEqaulChars = new StringBuilder();
|
||||
var result = new StringBuilder();
|
||||
for(int i = 0; i < 100 ;i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
multiEqaulChars.Append('=');
|
||||
}
|
||||
var multiEqualStr = multiEqaulChars.ToString();
|
||||
if (i == 0 || s.Contains(multiEqualStr))
|
||||
{
|
||||
if (s.Contains("[" + multiEqualStr + "[") || s.Contains("]" + multiEqualStr + "]"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
result.Clear();
|
||||
result.Append('[').Append(multiEqualStr).Append('[');
|
||||
result.Append(s);
|
||||
result.Append(']').Append(multiEqualStr).Append(']');
|
||||
return result.ToString();
|
||||
}
|
||||
throw new Exception($"too complex string:'{s}'");
|
||||
}
|
||||
|
||||
//public static string EscapeStringWithQuote(string s)
|
||||
//{
|
||||
// return "\"" + s.Replace("\\", "\\\\") + "\"";
|
||||
|
|
|
|||
Loading…
Reference in New Issue