* @param {string} input * @param {{ position: number }} position * @param {boolean} [extractValue=false]
(input, position, extractValue = false)
| 395 | * @param {boolean} [extractValue=false] |
| 396 | */ |
| 397 | function collectAnHTTPQuotedString (input, position, extractValue = false) { |
| 398 | // 1. Let positionStart be position. |
| 399 | const positionStart = position.position |
| 400 | |
| 401 | // 2. Let value be the empty string. |
| 402 | let value = '' |
| 403 | |
| 404 | // 3. Assert: the code point at position within input |
| 405 | // is U+0022 ("). |
| 406 | assert(input[position.position] === '"') |
| 407 | |
| 408 | // 4. Advance position by 1. |
| 409 | position.position++ |
| 410 | |
| 411 | // 5. While true: |
| 412 | while (true) { |
| 413 | // 1. Append the result of collecting a sequence of code points |
| 414 | // that are not U+0022 (") or U+005C (\) from input, given |
| 415 | // position, to value. |
| 416 | value += collectASequenceOfCodePoints( |
| 417 | (char) => char !== '"' && char !== '\\', |
| 418 | input, |
| 419 | position |
| 420 | ) |
| 421 | |
| 422 | // 2. If position is past the end of input, then break. |
| 423 | if (position.position >= input.length) { |
| 424 | break |
| 425 | } |
| 426 | |
| 427 | // 3. Let quoteOrBackslash be the code point at position within |
| 428 | // input. |
| 429 | const quoteOrBackslash = input[position.position] |
| 430 | |
| 431 | // 4. Advance position by 1. |
| 432 | position.position++ |
| 433 | |
| 434 | // 5. If quoteOrBackslash is U+005C (\), then: |
| 435 | if (quoteOrBackslash === '\\') { |
| 436 | // 1. If position is past the end of input, then append |
| 437 | // U+005C (\) to value and break. |
| 438 | if (position.position >= input.length) { |
| 439 | value += '\\' |
| 440 | break |
| 441 | } |
| 442 | |
| 443 | // 2. Append the code point at position within input to value. |
| 444 | value += input[position.position] |
| 445 | |
| 446 | // 3. Advance position by 1. |
| 447 | position.position++ |
| 448 | |
| 449 | // 6. Otherwise: |
| 450 | } else { |
| 451 | // 1. Assert: quoteOrBackslash is U+0022 ("). |
| 452 | assert(quoteOrBackslash === '"') |
| 453 | |
| 454 | // 2. Break. |
no test coverage detected