* Split input into separate trajectory blocks * Blocks are separated by blank lines (lines with only whitespace) * # comment lines before brackets are included as potential names
(input)
| 105 | * # comment lines before brackets are included as potential names |
| 106 | */ |
| 107 | static splitIntoBlocks(input) { |
| 108 | const blocks = []; |
| 109 | let currentBlock = ''; |
| 110 | let bracketDepth = 0; |
| 111 | let inBlock = false; |
| 112 | let hasSeenBracket = false; // Track if we've seen any bracket in current block |
| 113 | |
| 114 | const lines = input.split('\n'); |
| 115 | |
| 116 | for (const line of lines) { |
| 117 | const trimmedLine = line.trim(); |
| 118 | |
| 119 | // Count brackets in this line (excluding those in comments) |
| 120 | if (!trimmedLine.startsWith('#')) { |
| 121 | for (const char of trimmedLine) { |
| 122 | if (char === '[') bracketDepth++; |
| 123 | if (char === ']') bracketDepth--; |
| 124 | } |
| 125 | if (trimmedLine.includes('[')) { |
| 126 | hasSeenBracket = true; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | // Check if this is an empty line (true separator between blocks) |
| 131 | const isEmpty = trimmedLine === ''; |
| 132 | |
| 133 | // A # line at the start of a block (before any brackets) is a name, not a separator |
| 134 | const isNameComment = trimmedLine.startsWith('#') && !hasSeenBracket; |
| 135 | |
| 136 | if (isEmpty && bracketDepth === 0 && inBlock && hasSeenBracket) { |
| 137 | // End of a block (only if we've seen brackets) |
| 138 | if (currentBlock.trim()) { |
| 139 | blocks.push(currentBlock.trim()); |
| 140 | } |
| 141 | currentBlock = ''; |
| 142 | inBlock = false; |
| 143 | hasSeenBracket = false; |
| 144 | } else if (!isEmpty || bracketDepth > 0 || isNameComment) { |
| 145 | // Part of a block (including # name comments before content) |
| 146 | currentBlock += line + '\n'; |
| 147 | inBlock = true; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | // Don't forget the last block |
| 152 | if (currentBlock.trim()) { |
| 153 | blocks.push(currentBlock.trim()); |
| 154 | } |
| 155 | |
| 156 | return blocks; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Parse a Python-like list string into a JavaScript array |
no outgoing calls
no test coverage detected