split splits "int, float" into ["int", "float"] and splits "" into [].
(s string)
| 628 | |
| 629 | // split splits "int, float" into ["int", "float"] and splits "" into []. |
| 630 | func split(s string) []string { |
| 631 | out := []string{} |
| 632 | i := 0 // current type being scanned is s[i:j]. |
| 633 | nparen := 0 |
| 634 | for j := 0; j < len(s); j++ { |
| 635 | switch s[j] { |
| 636 | case ' ': |
| 637 | if i == j { |
| 638 | i++ |
| 639 | } |
| 640 | case '(': |
| 641 | nparen++ |
| 642 | case ')': |
| 643 | nparen-- |
| 644 | if nparen < 0 { |
| 645 | // probably can't happen |
| 646 | return nil |
| 647 | } |
| 648 | case ',': |
| 649 | if nparen == 0 { |
| 650 | if i < j { |
| 651 | out = append(out, s[i:j]) |
| 652 | } |
| 653 | i = j + 1 |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | if nparen != 0 { |
| 658 | // probably can't happen |
| 659 | return nil |
| 660 | } |
| 661 | if i < len(s) { |
| 662 | out = append(out, s[i:]) |
| 663 | } |
| 664 | return out |
| 665 | } |
| 666 | |
| 667 | // join is the inverse of split. |
| 668 | func join(x []string) string { |
no outgoing calls
no test coverage detected