forked from b3log/lute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
byte_str.go
29 lines (24 loc) · 949 Bytes
/
byte_str.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Lute - A structured markdown engine.
// Copyright (c) 2019-present, b3log.org
//
// Lute is licensed under the Mulan PSL v1.
// You can use this software according to the terms and conditions of the Mulan PSL v1.
// You may obtain a copy of Mulan PSL v1 at:
// http://license.coscl.org.cn/MulanPSL
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
// PURPOSE.
// See the Mulan PSL v1 for more details.
// +build !javascript
package lute
import "unsafe"
// bytesToStr 快速转换 []byte 为 string。
func bytesToStr(bytes []byte) string {
return *(*string)(unsafe.Pointer(&bytes))
}
// strToBytes 快速转换 string 为 []byte。
func strToBytes(str string) []byte {
x := (*[2]uintptr)(unsafe.Pointer(&str))
h := [3]uintptr{x[0], x[1], x[1]}
return *(*[]byte)(unsafe.Pointer(&h))
}