MCPcopy Create free account
hub / github.com/cogentcore/core / Path

Method Path

shell/paths.go:26–100  ·  view source on GitHub ↗

Path extracts a standard path or URL expression from the current list of tokens (starting at index 0), returning the path string and the number of tokens included in the path. Restricts processing to contiguous elements with no spaces! If it is not a path, returns nil string, 0

(idx0 bool)

Source from the content-addressed store, hash-verified

24// Restricts processing to contiguous elements with no spaces!
25// If it is not a path, returns nil string, 0
26func (tk Tokens) Path(idx0 bool) (string, int) {
27 n := len(tk)
28 if n == 0 {
29 return "", 0
30 }
31 t0 := tk[0]
32 ispath := (t0.IsPathDelim() || t0.Tok == token.TILDE)
33 if n == 1 {
34 if ispath {
35 return t0.String(), 1
36 }
37 return "", 0
38 }
39 str := tk[0].String()
40 lastEnd := int(tk[0].Pos) + len(str)
41 ci := 1
42 if !ispath {
43 lastEnd = int(tk[0].Pos)
44 ci = 0
45 if t0.Tok != token.IDENT {
46 return "", 0
47 }
48 tin := 1
49 tid := t0.Str
50 tindelim := tk[tin].IsPathDelim()
51 if idx0 {
52 tindelim = tk[tin].Tok == token.QUO
53 }
54 if (int(tk[tin].Pos) > lastEnd+len(tid)) || !(tk[tin].Tok == token.COLON || tindelim) {
55 return "", 0
56 }
57 ci += tin + 1
58 str = tid + tk[tin].String()
59 lastEnd += len(str)
60 }
61 prevWasDelim := true
62 for {
63 if ci >= n || int(tk[ci].Pos) > lastEnd {
64 return str, ci
65 }
66 ct := tk[ci]
67 if ct.IsPathDelim() || ct.IsPathExtraDelim() {
68 prevWasDelim = true
69 str += ct.String()
70 lastEnd += len(ct.String())
71 ci++
72 continue
73 }
74 if ct.Tok == token.STRING {
75 prevWasDelim = true
76 str += EscapeQuotes(ct.String())
77 lastEnd += len(ct.String())
78 ci++
79 continue
80 }
81 if !prevWasDelim {
82 if ct.Tok == token.ILLEGAL && ct.Str == `\` && ci+1 < n && int(tk[ci+1].Pos) == lastEnd+2 {
83 prevWasDelim = true

Callers 15

InitMethod · 0.45
TranspileLineTokensMethod · 0.45
TestPathsFunction · 0.45
duplicateSyncMethod · 0.45
PushBoundsMethod · 0.45
TestWidgetPrevFunction · 0.45
TestWidgetNextFunction · 0.45
InferSymbolTypeMethod · 0.45
SetRuleMapMethod · 0.45
DoRulesMethod · 0.45
DoActMethod · 0.45

Calls 5

EscapeQuotesFunction · 0.85
IsPathDelimMethod · 0.80
IsPathExtraDelimMethod · 0.80
IsWordMethod · 0.80
StringMethod · 0.65

Tested by 3

TestPathsFunction · 0.36
TestWidgetPrevFunction · 0.36
TestWidgetNextFunction · 0.36