MCPcopy Index your code
hub / github.com/callstack/agent-device / tokenize

Function tokenize

src/utils/selectors-parse.ts:210–233  ·  view source on GitHub ↗
(segment: string)

Source from the content-addressed store, hash-verified

208}
209
210function tokenize(segment: string): string[] {
211 const tokens: string[] = [];
212 let current = '';
213 let quote: '"' | "'" | null = null;
214 for (let i = 0; i < segment.length; i += 1) {
215 const ch = segment.charAt(i);
216 if ((ch === '"' || ch === "'") && !isEscapedQuote(segment, i)) {
217 quote = updateQuoteState(quote, ch);
218 current += ch;
219 continue;
220 }
221 if (!quote && /\s/.test(ch)) {
222 if (current.trim()) tokens.push(current.trim());
223 current = '';
224 continue;
225 }
226 current += ch;
227 }
228 if (quote) {
229 throw new AppError('INVALID_ARGS', `Unclosed quote in selector: ${segment}`);
230 }
231 if (current.trim()) tokens.push(current.trim());
232 return tokens;
233}
234
235function updateQuoteState(currentQuote: '"' | "'" | null, ch: '"' | "'"): '"' | "'" | null {
236 if (!currentQuote) return ch;

Callers 1

parseSelectorFunction · 0.85

Calls 3

isEscapedQuoteFunction · 0.85
updateQuoteStateFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…