Convert a file path to a URI and write it to the buffer.
| 2525 | |
| 2526 | // Convert a file path to a URI and write it to the buffer. |
| 2527 | int Debugger::Buffer::WriteFileURI(const char *aPath) |
| 2528 | { |
| 2529 | int c, len = 9; // 8 for "file:///", 1 for '\0' (written by sprintf()). |
| 2530 | |
| 2531 | // Calculate required buffer size for path after encoding. |
| 2532 | for (const char *ptr = aPath; c = *ptr; ++ptr) |
| 2533 | { |
| 2534 | if (cisalnum(c) || strchr("-_.!~*'()/\\", c)) |
| 2535 | ++len; |
| 2536 | else |
| 2537 | len += 3; |
| 2538 | } |
| 2539 | |
| 2540 | // Ensure the buffer contains enough space. |
| 2541 | if (ExpandIfNecessary(mDataUsed + len) != DEBUGGER_E_OK) |
| 2542 | return DEBUGGER_E_INTERNAL_ERROR; |
| 2543 | |
| 2544 | Write("file:///", 8); |
| 2545 | |
| 2546 | // Write to the buffer, encoding as we go. |
| 2547 | for (const char *ptr = aPath; c = *ptr; ++ptr) |
| 2548 | { |
| 2549 | if (cisalnum(c) || strchr("-_.!~*()/", c)) |
| 2550 | { |
| 2551 | mData[mDataUsed++] = (char)c; |
| 2552 | } |
| 2553 | else if (c == '\\') |
| 2554 | { |
| 2555 | // This could be encoded as %5C, but it's more readable this way: |
| 2556 | mData[mDataUsed++] = '/'; |
| 2557 | } |
| 2558 | else |
| 2559 | { |
| 2560 | len = sprintf(mData + mDataUsed, "%%%02X", c & 0xff); |
| 2561 | if (len != -1) |
| 2562 | mDataUsed += len; |
| 2563 | } |
| 2564 | } |
| 2565 | |
| 2566 | return DEBUGGER_E_OK; |
| 2567 | } |
| 2568 | |
| 2569 | int Debugger::Buffer::WriteEncodeBase64(const char *aInput, size_t aInputSize, bool aSkipBufferSizeCheck/* = false*/) |
| 2570 | { |
no test coverage detected