MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / findNextTableHeader

Function findNextTableHeader

src/installer/targets/toml.ts:140–167  ·  view source on GitHub ↗

* Find the byte index of the next `[...]` or `[[...]]` table header * starting from `from`, or return content length when none.

(content: string, from: number)

Source from the content-addressed store, hash-verified

138 * starting from `from`, or return content length when none.
139 */
140function findNextTableHeader(content: string, from: number): number {
141 const state: TomlLexState = { multilineString: null, arrayDepth: 0, inlineTableDepth: 0 };
142 let lineStart = from;
143 let isHeaderRemainder = true;
144
145 while (lineStart < content.length) {
146 const newlineIdx = content.indexOf('\n', lineStart);
147 const lineEnd = newlineIdx === -1 ? content.length : newlineIdx;
148 const line = content.slice(lineStart, lineEnd);
149
150 if (
151 !isHeaderRemainder &&
152 state.multilineString === null &&
153 state.arrayDepth === 0 &&
154 state.inlineTableDepth === 0 &&
155 isTomlTableHeader(line)
156 ) {
157 return lineStart;
158 }
159
160 scanTomlLine(line, state);
161 if (newlineIdx === -1) break;
162 lineStart = newlineIdx + 1;
163 isHeaderRemainder = false;
164 }
165
166 return content.length;
167}
168
169type MultilineStringDelimiter = '"""' | "'''";
170

Callers 2

upsertTomlTableFunction · 0.85
removeTomlTableFunction · 0.85

Calls 2

isTomlTableHeaderFunction · 0.85
scanTomlLineFunction · 0.85

Tested by

no test coverage detected