MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / parseValue

Function parseValue

src/utils/git/gitConfigParser.ts:114–184  ·  view source on GitHub ↗

* Parse a config value starting at position i. * Handles quoted strings, escape sequences, and inline comments.

(line: string, start: number)

Source from the content-addressed store, hash-verified

112 * Handles quoted strings, escape sequences, and inline comments.
113 */
114function parseValue(line: string, start: number): string {
115 let result = ''
116 let inQuote = false
117 let i = start
118
119 while (i < line.length) {
120 const ch = line[i]!
121
122 // Inline comments outside quotes end the value
123 if (!inQuote && (ch === '#' || ch === ';')) {
124 break
125 }
126
127 if (ch === '"') {
128 inQuote = !inQuote
129 i++
130 continue
131 }
132
133 if (ch === '\\' && i + 1 < line.length) {
134 const next = line[i + 1]!
135 if (inQuote) {
136 // Inside quotes: recognize escape sequences
137 switch (next) {
138 case 'n':
139 result += '\n'
140 break
141 case 't':
142 result += '\t'
143 break
144 case 'b':
145 result += '\b'
146 break
147 case '"':
148 result += '"'
149 break
150 case '\\':
151 result += '\\'
152 break
153 default:
154 // Git silently drops the backslash for unknown escapes
155 result += next
156 break
157 }
158 i += 2
159 continue
160 }
161 // Outside quotes: backslash at end of line = continuation (we don't
162 // handle multi-line since we split on \n, but handle \\ and others)
163 if (next === '\\') {
164 result += '\\'
165 i += 2
166 continue
167 }
168 // Fallthrough — treat backslash literally outside quotes
169 }
170
171 result += ch

Callers 1

parseKeyValueFunction · 0.85

Calls 1

trimTrailingWhitespaceFunction · 0.85

Tested by

no test coverage detected