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

Function getArrayValue

src/resolution/frameworks/cargo-workspace.ts:87–142  ·  view source on GitHub ↗
(section: string, key: string)

Source from the content-addressed store, hash-verified

85}
86
87function getArrayValue(section: string, key: string): string | null {
88 const keyRegex = new RegExp(`\\b${escapeRegExp(key)}\\b\\s*=`, 'm');
89 const keyMatch = keyRegex.exec(section);
90 if (!keyMatch) return null;
91
92 let i = keyMatch.index + keyMatch[0].length;
93 while (i < section.length && /\s/.test(section.charAt(i))) i++;
94 if (section.charAt(i) !== '[') return null;
95 i++;
96
97 let inQuote: '"' | "'" | null = null;
98 let escaped = false;
99 let depth = 1;
100 const start = i;
101
102 while (i < section.length) {
103 const ch = section.charAt(i);
104
105 if (inQuote) {
106 if (escaped) {
107 escaped = false;
108 } else if (ch === '\\') {
109 escaped = true;
110 } else if (ch === inQuote) {
111 inQuote = null;
112 }
113 i++;
114 continue;
115 }
116
117 if (ch === '"' || ch === "'") {
118 inQuote = ch;
119 i++;
120 continue;
121 }
122
123 if (ch === '[') {
124 depth++;
125 i++;
126 continue;
127 }
128
129 if (ch === ']') {
130 depth--;
131 if (depth === 0) {
132 return section.slice(start, i);
133 }
134 i++;
135 continue;
136 }
137
138 i++;
139 }
140
141 return null;
142}
143
144export function parseWorkspaceMembers(cargoToml: string): string[] {

Callers 1

parseWorkspaceMembersFunction · 0.85

Calls 2

escapeRegExpFunction · 0.70
execMethod · 0.65

Tested by

no test coverage detected