String NetworkCacheKey::hashAsString() const { StringBuilder builder; builder.reserveCapacity(hashStringLength()); for (auto byte : m_hash) { builder.append(upperNibbleToASCIIHexDigit(byte)); builder.append(lowerNibbleToASCIIHexDigit(byte)); } return builder.toString(); }
void quotedPrintableEncode(const char* input, size_t inputLength, Vector<char>& out) { out.clear(); out.reserveCapacity(inputLength); size_t currentLineLength = 0; for (size_t i = 0; i < inputLength; ++i) { bool isLastCharacter = (i == inputLength - 1); char currentCharacter = input[i]; bool requiresEncoding = false; // All non-printable ASCII characters and = require encoding. if ((currentCharacter < ' ' || currentCharacter > '~' || currentCharacter == '=') && currentCharacter != '\t') requiresEncoding = true; // Space and tab characters have to be encoded if they appear at the end of a line. if (!requiresEncoding && (currentCharacter == '\t' || currentCharacter == ' ') && (isLastCharacter || lengthOfLineEndingAtIndex(input, inputLength, i + 1))) requiresEncoding = true; // End of line should be converted to CR-LF sequences. if (!isLastCharacter) { size_t lengthOfLineEnding = lengthOfLineEndingAtIndex(input, inputLength, i); if (lengthOfLineEnding) { out.append(crlfLineEnding, strlen(crlfLineEnding)); currentLineLength = 0; i += (lengthOfLineEnding - 1); // -1 because we'll ++ in the for() above. continue; } } size_t lengthOfEncodedCharacter = 1; if (requiresEncoding) lengthOfEncodedCharacter += 2; if (!isLastCharacter) lengthOfEncodedCharacter += 1; // + 1 for the = (soft line break). // Insert a soft line break if necessary. if (currentLineLength + lengthOfEncodedCharacter > maximumLineLength) { out.append('='); out.append(crlfLineEnding, strlen(crlfLineEnding)); currentLineLength = 0; } // Finally, insert the actual character(s). if (requiresEncoding) { out.append('='); out.append(upperNibbleToASCIIHexDigit(currentCharacter)); out.append(lowerNibbleToASCIIHexDigit(currentCharacter)); currentLineLength += 3; } else { out.append(currentCharacter); currentLineLength++; } } }
static String generateRandomBoundary() { // Trying to generate random boundaries similar to IE/UnMHT (ex: ----=_NextPart_000_001B_01CC157B.96F808A0). const size_t randomValuesLength = 10; char randomValues[randomValuesLength]; cryptographicallyRandomValues(&randomValues, randomValuesLength); StringBuilder stringBuilder; stringBuilder.append("----=_NextPart_000_"); for (size_t i = 0; i < randomValuesLength; ++i) { if (i == 2) stringBuilder.append('_'); else if (i == 6) stringBuilder.append('.'); stringBuilder.append(lowerNibbleToASCIIHexDigit(randomValues[i])); stringBuilder.append(upperNibbleToASCIIHexDigit(randomValues[i])); } return stringBuilder.toString(); }
void IndexedAbstractHeap::initialize(AbstractField& field, ptrdiff_t signedIndex) { // Build up a name of the form: // // heapName_hexIndex // // or: // // heapName_neg_hexIndex // // For example if you access an indexed heap called FooBar at index 5, you'll // get: // // FooBar_5 // // Or if you access an indexed heap called Blah at index -10, you'll get: // // Blah_neg_A // // This is important because LLVM uses the string to distinguish the types. static const char* negSplit = "_neg_"; static const char* posSplit = "_"; bool negative; size_t index; if (signedIndex < 0) { negative = true; index = -signedIndex; } else { negative = false; index = signedIndex; } for (unsigned power = 4; power <= sizeof(void*) * 8; power += 4) { if (isGreaterThanNonZeroPowerOfTwo(index, power)) continue; unsigned numHexlets = power >> 2; size_t stringLength = m_heapNameLength + (negative ? strlen(negSplit) : strlen(posSplit)) + numHexlets; char* characters; m_largeIndexNames.append(CString::newUninitialized(stringLength, characters)); memcpy(characters, m_heapForAnyIndex.heapName(), m_heapNameLength); if (negative) memcpy(characters + m_heapNameLength, negSplit, strlen(negSplit)); else memcpy(characters + m_heapNameLength, posSplit, strlen(posSplit)); size_t accumulator = index; for (unsigned i = 0; i < numHexlets; ++i) { characters[stringLength - i - 1] = lowerNibbleToASCIIHexDigit(accumulator); accumulator >>= 4; } field.initialize(&m_heapForAnyIndex, characters, m_offset + signedIndex * m_elementSize); return; } RELEASE_ASSERT_NOT_REACHED(); }