forked from swaggo/swag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_other.go
47 lines (41 loc) · 1.06 KB
/
utils_other.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//go:build !go1.18
// +build !go1.18
package swag
import (
"reflect"
"unicode/utf8"
)
// AppendUtf8Rune appends the UTF-8 encoding of r to the end of p and
// returns the extended buffer. If the rune is out of range,
// it appends the encoding of RuneError.
func AppendUtf8Rune(p []byte, r rune) []byte {
length := utf8.RuneLen(rune(r))
if length > 0 {
utf8Slice := make([]byte, length)
utf8.EncodeRune(utf8Slice, rune(r))
p = append(p, utf8Slice...)
}
return p
}
// CanIntegerValue a wrapper of reflect.Value
type CanIntegerValue struct {
reflect.Value
}
// CanInt reports whether Uint can be used without panicking.
func (v CanIntegerValue) CanInt() bool {
switch v.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return true
default:
return false
}
}
// CanUint reports whether Uint can be used without panicking.
func (v CanIntegerValue) CanUint() bool {
switch v.Kind() {
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return true
default:
return false
}
}