1 Star 0 Fork 0

jackytse / tabtoy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
strwrapper.go 733 Bytes
一键复制 编辑 原始数据 按行查看 历史
黑色灵猫 提交于 2018-05-31 14:26 . 升级器
package util
import (
"fmt"
)
func StringEscape(s string) string {
b := make([]byte, 0)
var index int
// 表中直接使用换行会干扰最终合并文件格式, 所以转成\n,由pbt文本解析层转回去
for index < len(s) {
c := s[index]
switch c {
case '"':
b = append(b, '\\')
b = append(b, '"')
case '\n':
b = append(b, '\\')
b = append(b, 'n')
case '\r':
b = append(b, '\\')
b = append(b, 'r')
case '\\':
var nextChar byte
if index+1 < len(s) {
nextChar = s[index+1]
}
b = append(b, '\\')
switch nextChar {
case 'n', 'r':
default:
b = append(b, c)
}
default:
b = append(b, c)
}
index++
}
return fmt.Sprintf("\"%s\"", string(b))
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/jackytse/tabtoy.git
git@gitee.com:jackytse/tabtoy.git
jackytse
tabtoy
tabtoy
v0.0.8

搜索帮助

344bd9b3 5694891 D2dac590 5694891