Exemplo n.º 1
0
txString fxResizeString(txMachine* the, txSlot* a, txSize theSize)
{
	txString result = C_NULL;
	if (a->kind == XS_STRING_KIND)
		result = (txString)fxRenewChunk(the, a->value.string, theSize);
	if (!result) {
		txChunk* aChunk = (txChunk*)(a->value.string - sizeof(txChunk));
		txSize aSize = aChunk->size - sizeof(txChunk); 
		result = (txString)fxNewChunk(the, theSize);
		aChunk = (txChunk*)(result - sizeof(txChunk));
		theSize = aChunk->size - sizeof(txChunk);
		c_memcpy(result, a->value.string, (aSize < theSize) ? aSize : theSize);
		a->value.string = result;
		a->kind = XS_STRING_KIND;
	}
	return result;
}
Exemplo n.º 2
0
txString fxConcatStringC(txMachine* the, txSlot* a, txString b)
{
	txSize aSize = c_strlen(a->value.string);
	txSize bSize = c_strlen(b);
	txSize resultSize = aSize + bSize + 1;
	txString result = C_NULL;
	if (a->kind == XS_STRING_KIND)
		result = (txString)fxRenewChunk(the, a->value.string, resultSize);
	if (!result) {
		result = (txString)fxNewChunk(the, resultSize);
		c_memcpy(result, a->value.string, aSize);
		a->value.string = result;
		a->kind = XS_STRING_KIND;
	}
	c_memcpy(result + aSize, b, bSize + 1);
	return result;
}
Exemplo n.º 3
0
void fxSetArrayLength(txMachine* the, txSlot* array, txIndex target)
{
	txIndex length = array->value.array.length;
	txSlot* address = array->value.array.address;
	if (length != target) {
		if (address)
			address = (txSlot*)fxRenewChunk(the, address, target * sizeof(txSlot));
		if (address) {
			if (length < target)
				c_memset(address + length, 0, (target - length) * sizeof(txSlot));
		}
		else {
			address = (txSlot*)fxNewChunk(the, target * sizeof(txSlot));
			if (length < target) {
				c_memcpy(address, array->value.array.address, length * sizeof(txSlot));
				c_memset(address + length, 0, (target - length) * sizeof(txSlot));
			}
			else
				c_memcpy(address, array->value.array.address, target * sizeof(txSlot));
		}
		array->value.array.length = target;
		array->value.array.address = address;
	}
}