MCPcopy Create free account
hub / github.com/araddon/qlbridge / LeftRight

Function LeftRight

expr/stringutil.go:25–58  ·  view source on GitHub ↗

LeftRight Return left, right values if is of form `table.column` or `schema`.`table` also return true/false for if it even has left/right

(val string)

Source from the content-addressed store, hash-verified

23// LeftRight Return left, right values if is of form `table.column` or `schema`.`table`
24// also return true/false for if it even has left/right
25func LeftRight(val string) (string, string, bool) {
26 if len(val) < 2 {
27 return "", val, false
28 }
29 switch by := val[0]; by {
30 case '`':
31 vals := strings.Split(val, "`.`")
32 if len(vals) == 1 {
33 return "", IdentityTrim(val), false
34 } else if len(vals) == 2 {
35 return IdentityTrim(vals[0]), IdentityTrim(vals[1]), true
36 }
37 // wat, no idea what this is
38 return "", val, false
39 case '[':
40 vals := strings.Split(val, "].[")
41 if len(vals) == 1 {
42 return "", IdentityTrim(val), false
43 } else if len(vals) == 2 {
44 return IdentityTrim(vals[0]), IdentityTrim(vals[1]), true
45 }
46 // wat, no idea what this is
47 return "", val, false
48 default:
49 vals := strings.SplitN(val, ".", 2)
50 if len(vals) == 1 {
51 return "", val, false
52 } else if len(vals) == 2 {
53 return IdentityTrim(vals[0]), IdentityTrim(vals[1]), true
54 }
55 }
56
57 return "", val, false
58}
59
60// IdentityTrim trims the leading/trailing identity quote marks ` or []
61func IdentityTrim(ident string) string {

Callers 14

GetMethod · 0.92
GetMethod · 0.92
GetMethod · 0.92
TableMethod · 0.92
NewColumnFromTokenFunction · 0.92
CopyRewriteMethod · 0.92
LeftRightMethod · 0.92
SourceNameMethod · 0.92
BuildColIndexMethod · 0.92
parseColumnsFunction · 0.92
parseSourceTableMethod · 0.92
TestLeftRightFunction · 0.85

Calls 1

IdentityTrimFunction · 0.85

Tested by 1

TestLeftRightFunction · 0.68