(s: string)
| 67 | } |
| 68 | |
| 69 | function parse(s: string) { |
| 70 | let properties = new Map<string, string>(); |
| 71 | let i = 0; |
| 72 | while (i < s.length) { |
| 73 | while (i < s.length && s[i] === ' ') { |
| 74 | i++; |
| 75 | } |
| 76 | |
| 77 | let start = i; |
| 78 | readValue(); // property index |
| 79 | |
| 80 | // read conditions (up to the last segment) |
| 81 | let condition = i; |
| 82 | while (i < s.length && s[i] !== ' ') { |
| 83 | readValue(); |
| 84 | } |
| 85 | |
| 86 | let property = s.slice(start, condition); |
| 87 | properties.set(property, (properties.get(property) || '') + ' ' + s.slice(start, i)); |
| 88 | } |
| 89 | |
| 90 | function readValue() { |
| 91 | if (s[i] === '-') { |
| 92 | // the beginning and end of arbitrary values are marked with - |
| 93 | while (i < s.length && s[i] !== ' ') { |
| 94 | i++; |
| 95 | if (s[i] === '-') { |
| 96 | i++; |
| 97 | break; |
| 98 | } |
| 99 | } |
| 100 | } else { |
| 101 | while (i < s.length) { |
| 102 | if (s[i] === '_') { |
| 103 | i++; |
| 104 | } else { |
| 105 | i++; |
| 106 | break; |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | return properties; |
| 113 | } |
no test coverage detected