Parse a PHP array literal containing only string values. Accepts text starting with `[` and extracts bare string values (no `=>` keys). For example, `['name', 'email', 'password']` returns `["name", "email", "password"]`.
(text: &str)
| 759 | /// (no `=>` keys). For example, `['name', 'email', 'password']` |
| 760 | /// returns `["name", "email", "password"]`. |
| 761 | fn parse_string_list(text: &str) -> Vec<String> { |
| 762 | let mut results = Vec::new(); |
| 763 | let trimmed = text.trim(); |
| 764 | |
| 765 | let inner = if let Some(s) = trimmed.strip_prefix('[') { |
| 766 | s.strip_suffix(']').unwrap_or(s) |
| 767 | } else { |
| 768 | return results; |
| 769 | }; |
| 770 | |
| 771 | for segment in inner.split(',') { |
| 772 | let segment = segment.trim(); |
| 773 | if segment.is_empty() { |
| 774 | continue; |
| 775 | } |
| 776 | // Skip key-value pairs (these belong to a different kind of array). |
| 777 | if segment.contains("=>") { |
| 778 | continue; |
| 779 | } |
| 780 | if let Some(s) = extract_string_literal(segment) |
| 781 | && !s.is_empty() |
| 782 | { |
| 783 | results.push(s); |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | results |
| 788 | } |
| 789 | |
| 790 | /// Try to infer an Eloquent relationship return type from a method's body. |
| 791 | /// |
no test coverage detected