MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / parseID

Function parseID

dql/parser.go:2531–2571  ·  view source on GitHub ↗

Parses ID list. Only used for DQL variables. TODO - Maybe get rid of this by lexing individual IDs.

(val string)

Source from the content-addressed store, hash-verified

2529// Parses ID list. Only used for DQL variables.
2530// TODO - Maybe get rid of this by lexing individual IDs.
2531func parseID(val string) ([]uint64, error) {
2532 val = x.WhiteSpace.Replace(val)
2533 if val == "" {
2534 return nil, errors.Errorf("ID can't be empty")
2535 }
2536 var uids []uint64
2537 if val[0] != '[' {
2538 uid, err := strconv.ParseUint(val, 0, 64)
2539 if err != nil {
2540 return nil, err
2541 }
2542 uids = append(uids, uid)
2543 return uids, nil
2544 }
2545
2546 if val[len(val)-1] != ']' {
2547 return nil, errors.Errorf("Invalid id list at root. Got: %+v", val)
2548 }
2549 var buf bytes.Buffer
2550 for _, c := range val[1:] {
2551 if c == ',' || c == ']' {
2552 if buf.Len() == 0 {
2553 continue
2554 }
2555 uid, err := strconv.ParseUint(buf.String(), 0, 64)
2556 if err != nil {
2557 return nil, err
2558 }
2559 uids = append(uids, uid)
2560 buf.Reset()
2561 continue
2562 }
2563 if c == '[' || c == ')' {
2564 return nil, errors.Errorf("Invalid id list at root. Got: %+v", val)
2565 }
2566 if _, err := buf.WriteRune(c); err != nil {
2567 return nil, err
2568 }
2569 }
2570 return uids, nil
2571}
2572
2573func parseVarList(it *lex.ItemIterator, gq *GraphQuery) (int, error) {
2574 count := 0

Callers 2

substituteVariablesFunction · 0.85

Calls 4

LenMethod · 0.65
ErrorfMethod · 0.45
StringMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected