-
Notifications
You must be signed in to change notification settings - Fork 6
/
id.go
48 lines (41 loc) · 1.1 KB
/
id.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
package winres
import (
"errors"
"strings"
)
// ID is the type of a resource id, or resource type id.
type ID uint16
// Name is the type of a resource name, or a resource type name.
type Name string
// Identifier is either an ID or a Name.
//
// When you are asked for an Identifier, you can pass an int cast to an ID or a string cast to a Name.
type Identifier interface {
// This method serves both to seal the interface and help order identifiers the standard way
// https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#resource-directory-entries
lessThan(ident Identifier) bool
}
func (id ID) lessThan(ident Identifier) bool {
right, ok := ident.(ID)
return ok && id < right
}
func (n Name) lessThan(ident Identifier) bool {
right, ok := ident.(Name)
return !ok || n < right
}
func checkIdentifier(ident Identifier) error {
switch ident := ident.(type) {
case ID:
if ident == 0 {
return errors.New(errZeroID)
}
case Name:
if ident == "" {
return errors.New(errEmptyName)
}
if strings.ContainsRune(string(ident), 0) {
return errors.New(errNameContainsNUL)
}
}
return nil
}