33 data.
allocate (initialSize, initialiseToZero);
46 jassert (other.data !=
nullptr);
48 memcpy (data, other.data, size);
55 jassert (((ssize_t) sizeInBytes) >= 0);
59 jassert (dataToInitialiseFrom !=
nullptr);
63 if (dataToInitialiseFrom !=
nullptr)
64 memcpy (data, dataToInitialiseFrom, size);
77 memcpy (data, other.data, size);
84 : data (std::move (other.data)),
91 data = std::move (other.data);
99 return matches (other.data, other.size);
104 return ! operator== (other);
109 return size == dataSize
110 && memcmp (data, dataToCompare, size) == 0;
129 if (initialiseToZero && (newSize > size))
130 zeromem (data + size, newSize - size);
134 data.
allocate (newSize, initialiseToZero);
150 if (size < minimumSize)
151 setSize (minimumSize, initialiseToZero);
156 std::swap (size, other.size);
157 data.swapWith (other.data);
163 memset (data, (
int) value, size);
170 jassert (srcData !=
nullptr);
173 memcpy (data + oldSize, srcData, numBytes);
181 jassert (srcData !=
nullptr);
183 memcpy (data, srcData, numBytes);
191 jassert (srcData !=
nullptr);
192 insertPosition = jmin (size, insertPosition);
193 auto trailingDataSize = size - insertPosition;
194 setSize (size + numBytes,
false);
196 if (trailingDataSize > 0)
197 memmove (data + insertPosition + numBytes,
198 data + insertPosition,
201 memcpy (data + insertPosition, srcData, numBytes);
207 if (startByte + numBytesToRemove >= size)
211 else if (numBytesToRemove > 0)
213 memmove (data + startByte,
214 data + startByte + numBytesToRemove,
215 size - (startByte + numBytesToRemove));
217 setSize (size - numBytesToRemove);
223 auto* d =
static_cast<const char*
> (src);
228 num += (size_t) -offset;
232 if ((
size_t) offset + num > size)
233 num = size - (
size_t) offset;
236 memcpy (data + offset, d, num);
241 auto* d =
static_cast<char*
> (dst);
245 zeromem (d, (
size_t) -offset);
247 num -= (size_t) -offset;
251 if ((
size_t) offset + num > size)
253 auto newNum = (size_t) size - (
size_t) offset;
254 zeromem (d + newNum, num - newNum);
259 memcpy (d, data + offset, num);
272 auto byte = bitRangeStart >> 3;
273 auto offsetInByte = bitRangeStart & 7;
274 size_t bitsSoFar = 0;
276 while (numBits > 0 && (
size_t)
byte < size)
278 auto bitsThisTime = jmin (numBits, 8 - offsetInByte);
279 const int mask = (0xff >> (8 - bitsThisTime)) << offsetInByte;
281 res |= (((data[byte] & mask) >> offsetInByte) << bitsSoFar);
283 bitsSoFar += bitsThisTime;
284 numBits -= bitsThisTime;
294 auto byte = bitRangeStart >> 3;
295 auto offsetInByte = bitRangeStart & 7;
296 uint32 mask = ~((((uint32) 0xffffffff) << (32 - numBits)) >> (32 - numBits));
298 while (numBits > 0 && (
size_t)
byte < size)
300 auto bitsThisTime = jmin (numBits, 8 - offsetInByte);
302 const uint32 tempMask = (mask << offsetInByte) | ~((((uint32) 0xffffffff) >> offsetInByte) << offsetInByte);
303 const uint32 tempBits = (uint32) bitsToSet << offsetInByte;
305 data[byte] = (char) (((uint32) data[byte] & tempMask) | tempBits);
308 numBits -= bitsThisTime;
309 bitsToSet >>= bitsThisTime;
310 mask >>= bitsThisTime;
326 for (
int loop = 2; --loop >= 0;)
334 if (c >=
'0' && c <=
'9') {
byte |= c -
'0';
break; }
335 if (c >=
'a' && c <=
'z') {
byte |= c - (
'a' - 10);
break; }
336 if (c >=
'A' && c <=
'Z') {
byte |= c - (
'A' - 10);
break; }
340 setSize (
static_cast<size_t> (dest - data));
346 *dest++ = (char)
byte;
351static const char base64EncodingTable[] =
".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+";
355 auto numChars = ((size << 3) + 5) / 6;
357 String destString ((
unsigned int) size);
358 auto initialLen = destString.
length();
359 destString.
preallocateBytes (
sizeof (String::CharPointerType::CharType) * (
size_t) initialLen + 2 + numChars);
365 for (
size_t i = 0; i < numChars; ++i)
366 d.write ((juce_wchar) (uint8) base64EncodingTable[
getBitRange (i * 6, 6)]);
372static const char base64DecodingTable[] =
374 63, 0, 0, 0, 0, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 0, 0, 0, 0, 0, 0, 0,
375 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
376 0, 0, 0, 0, 0, 0, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52
388 setSize ((
size_t) numBytesNeeded,
true);
390 auto srcChars = dot + 1;
395 auto c = (int) srcChars.getAndAdvance();
402 if (isPositiveAndBelow (c, numElementsInArray (base64DecodingTable)))
404 setBitRange ((
size_t) pos, 6, base64DecodingTable[c]);
juce_wchar getAndAdvance() noexcept
Returns the character that this pointer is currently pointing to, and then advances the pointer to po...
void write(const juce_wchar charToWrite) noexcept
Writes a unicode character to this string, and advances this pointer to point to the next position.
static CharPointerType1 find(CharPointerType1 textToSearch, const CharPointerType2 substringToLookFor) noexcept
Returns a pointer to the first occurrence of a substring in a string.
void malloc(SizeType newNumElements, size_t elementSize=sizeof(ElementType))
Allocates a specified amount of memory.
void allocate(SizeType newNumElements, bool initialiseToZero)
Allocates a specified amount of memory and optionally clears it.
void realloc(SizeType newNumElements, size_t elementSize=sizeof(ElementType))
Re-allocates a specified amount of memory.
void free() noexcept
Frees any currently-allocated data.
A class to hold a resizable block of raw data.
void copyFrom(const void *srcData, int destinationOffset, size_t numBytes) noexcept
Copies data into this MemoryBlock from a memory address.
~MemoryBlock() noexcept
Destructor.
void ensureSize(const size_t minimumSize, bool initialiseNewSpaceToZero=false)
Increases the block's size only if it's smaller than a given size.
bool fromBase64Encoding(StringRef encodedString)
Takes a string created by MemoryBlock::toBase64Encoding() and extracts the original data.
String toBase64Encoding() const
Returns a string of characters in a JUCE-specific text encoding that represents the binary contents o...
bool matches(const void *data, size_t dataSize) const noexcept
Returns true if the data in this MemoryBlock matches the raw bytes passed-in.
void append(const void *data, size_t numBytes)
Adds another block of data to the end of this one.
MemoryBlock() noexcept
Create an uninitialised block with 0 size.
void setSize(const size_t newSize, bool initialiseNewSpaceToZero=false)
Resizes the memory block.
String toString() const
Attempts to parse the contents of the block as a zero-terminated UTF8 string.
void copyTo(void *destData, int sourceOffset, size_t numBytes) const noexcept
Copies data from this MemoryBlock to a memory address.
void insert(const void *dataToInsert, size_t numBytesToInsert, size_t insertPosition)
Inserts some data into the block.
void swapWith(MemoryBlock &other) noexcept
Exchanges the contents of this and another memory block.
int getBitRange(size_t bitRangeStart, size_t numBitsToRead) const noexcept
Reads a number of bits from the memory block, treating it as one long binary sequence.
void replaceWith(const void *data, size_t numBytes)
Resizes this block to the given size and fills its contents from the supplied buffer.
void loadFromHexString(StringRef sourceHexString)
Parses a string of hexadecimal numbers and writes this data into the memory block.
void removeSection(size_t startByte, size_t numBytesToRemove)
Chops out a section of the block.
MemoryBlock & operator=(const MemoryBlock &)
Copies another memory block onto this one.
void fillWith(uint8 valueToUse) noexcept
Fills the entire memory block with a repeated byte value.
bool operator!=(const MemoryBlock &other) const noexcept
Compares two memory blocks.
void setBitRange(size_t bitRangeStart, size_t numBits, int binaryNumberToApply) noexcept
Sets a number of bits in the memory block, treating it as a long binary sequence.
void reset()
Frees all the blocks data, setting its size to 0.
bool operator==(const MemoryBlock &other) const noexcept
Compares two memory blocks.
A simple class for holding temporary references to a string literal or String.
int length() const noexcept
Returns the number of characters in the string.
String::CharPointerType text
The text that is referenced.
CharPointerType getCharPointer() const noexcept
Returns the character pointer currently being used to store this string.
int length() const noexcept
Returns the number of characters in the string.
void preallocateBytes(size_t numBytesNeeded)
Increases the string's internally allocated storage.
static String fromUTF8(const char *utf8buffer, int bufferSizeBytes=-1)
Creates a String from a UTF-8 encoded buffer.
int getIntValue() const noexcept
Reads the value of the string as a decimal number (up to 32 bits in size).