-
Notifications
You must be signed in to change notification settings - Fork 0
/
ustr.go
59 lines (48 loc) · 1.16 KB
/
ustr.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
48
49
50
51
52
53
54
55
56
57
58
59
package dirsyn
/*
UniversalString implements the Universal Character Set.
UCS = 0x0000 through 0xFFFF
*/
type UniversalString string
/*
UniversalString returns an instance of [UniversalString] alongside an error
following an analysis of x in the context of a UniversalString.
*/
func (r RFC4517) UniversalString(x any) (UniversalString, error) {
return marshalUniversalString(x)
}
func universalString(x any) (result Boolean) {
_, err := marshalUniversalString(x)
result.Set(err == nil)
return
}
func marshalUniversalString(x any) (us UniversalString, err error) {
var raw string
switch tv := x.(type) {
case UniversalString:
raw = string(tv)
case []byte:
raw = string(tv)
case string:
raw = tv
default:
err = errorBadType("UniversalString")
return
}
if !utf8OK(raw) {
err = errorTxt("invalid UniversalString: failed UTF8 checks")
return
}
us = UniversalString(raw)
return
}
/*
String returns the string representation of the receiver instance.
*/
func (r UniversalString) String() string {
return string(r)
}
/*
IsZero returns a Boolean value indicative of a nil receiver state.
*/
func (r UniversalString) IsZero() bool { return len(r) == 0 }