getRawPathAndOptions returns the raw path and options from the value provided, the rawPath will be non-empty when returning without error here.
(value string)
| 414 | // getRawPathAndOptions returns the raw path and options from the value provided, |
| 415 | // the rawPath will be non-empty when returning without error here. |
| 416 | func getRawPathAndOptions(value string) (string, map[string]string, error) { |
| 417 | value = strings.TrimSpace(value) |
| 418 | if value == "" { |
| 419 | return "", nil, newValueEmptyError() |
| 420 | } |
| 421 | |
| 422 | switch splitValue := strings.Split(value, "#"); len(splitValue) { |
| 423 | case 1: |
| 424 | return value, nil, nil |
| 425 | case 2: |
| 426 | path := strings.TrimSpace(splitValue[0]) |
| 427 | optionsString := strings.TrimSpace(splitValue[1]) |
| 428 | if path == "" { |
| 429 | return "", nil, newValueStartsWithHashtagError(value) |
| 430 | } |
| 431 | if optionsString == "" { |
| 432 | return "", nil, newValueEndsWithHashtagError(value) |
| 433 | } |
| 434 | options := make(map[string]string) |
| 435 | for pair := range strings.SplitSeq(optionsString, ",") { |
| 436 | split := strings.Split(pair, "=") |
| 437 | if len(split) != 2 { |
| 438 | return "", nil, newOptionsInvalidError(optionsString) |
| 439 | } |
| 440 | key := strings.TrimSpace(split[0]) |
| 441 | value := strings.TrimSpace(split[1]) |
| 442 | if key == "" || value == "" { |
| 443 | return "", nil, newOptionsInvalidError(optionsString) |
| 444 | } |
| 445 | if _, ok := options[key]; ok { |
| 446 | return "", nil, newOptionsDuplicateKeyError(key) |
| 447 | } |
| 448 | options[key] = value |
| 449 | } |
| 450 | return path, options, nil |
| 451 | default: |
| 452 | return "", nil, newValueMultipleHashtagsError(value) |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | func getSingleRef( |
| 457 | rawRef *RawRef, |
searching dependent graphs…