1 Star 0 Fork 0

sqos/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
strings.go 829 Bytes
一键复制 编辑 原始数据 按行查看 历史
package eventlogging
import (
"fmt"
"strings"
"unicode/utf16"
)
// UTF16BytesToString returns the Unicode code point sequence represented
// by the UTF-16 buffer b.
func UTF16BytesToString(b []byte) (string, int, error) {
if len(b)%2 != 0 {
return "", 0, fmt.Errorf("Slice must have an even length (length=%d)",
len(b))
}
offset := len(b)/2 + 2
s := make([]uint16, len(b)/2)
for i := range s {
s[i] = uint16(b[i*2]) + uint16(b[(i*2)+1])<<8
if s[i] == 0 {
s = s[0:i]
offset = i*2 + 2
break
}
}
return string(utf16.Decode(s)), offset, nil
}
// RemoveWindowsLineEndings replaces CRLF with LF and trims any newline
// character that may exist at the end of the string.
func RemoveWindowsLineEndings(s string) string {
s = strings.Replace(s, "\r\n", "\n", -1)
return strings.TrimRight(s, "\n")
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqos/beats.git
git@gitee.com:sqos/beats.git
sqos
beats
beats
v1.1.1

搜索帮助