-
Notifications
You must be signed in to change notification settings - Fork 4
/
string.go
54 lines (45 loc) · 960 Bytes
/
string.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
package ast
import (
"strings"
"github.com/dipdup-net/go-lib/tools/consts"
)
//
// STRING
//
// String -
type String struct {
Default
}
// NewString -
func NewString(depth int) *String {
return &String{
Default: NewDefault(consts.STRING, 0, depth),
}
}
// ToJSONSchema -
func (s *String) ToJSONSchema() (*JSONSchema, error) {
return getStringJSONSchema(s.Default), nil
}
// Compare -
func (s *String) Compare(second Comparable) (int, error) {
secondItem, ok := second.(*String)
if !ok {
return 0, consts.ErrTypeIsNotComparable
}
return strings.Compare(s.Value.(string), secondItem.Value.(string)), nil
}
// Distinguish -
func (s *String) Distinguish(x Distinguishable) (*MiguelNode, error) {
second, ok := x.(*String)
if !ok {
return nil, nil
}
return s.Default.Distinguish(&second.Default)
}
// FindByName -
func (s *String) FindByName(name string, isEntrypoint bool) Node {
if s.GetName() == name {
return s
}
return nil
}