Example #1
0
IO_METHOD(IoSeq, replaceFirstSeq)
{
	/*doc Sequence replaceFirstSeq(aSequence, anotherSequence, optionalStartIndex)
	Returns a new Sequence with the first occurance of aSequence
	replaced with anotherSequence in the receiver. If optionalStartIndex is
	provided, the search for aSequence begins at that index. Returns self.
	*/

	IoSeq *subSeq   = IoMessage_locals_seqArgAt_(m, locals, 0);
	IoSeq *otherSeq = IoMessage_locals_seqArgAt_(m, locals, 1);
	size_t startIndex = 0;

	if (IoMessage_argCount(m) > 2)
	{
		startIndex = IoMessage_locals_longArgAt_(m, locals, 2);
	}

	IO_ASSERT_NOT_SYMBOL(self);

	{
		UArray *a = DATA(self);
		UArray *b = DATA(subSeq);
		UArray *c = DATA(otherSeq);
		long i = UArray_find_from_(a, b, startIndex);
		if(i != -1)
		{
			UArray_removeRange(a, i, UArray_size(b));
			UArray_at_putAll_(a, i, c);
		}
	}
	return self;
}
Example #2
0
IO_METHOD(IoSeq, replaceMap)
{
	/*doc Sequence replaceMap(aMap)
	In the receiver, the keys of aMap replaced with its values. Returns self.
	*/

	IoMap *map = IoMessage_locals_mapArgAt_(m, locals, 0);
	UArray *ba = DATA(self);

	IO_ASSERT_NOT_SYMBOL(self);

	PHASH_FOREACH(IoMap_rawHash(map), k, v,
		{
		IoSymbol *subSeq = k;
		IoSymbol *otherSeq = v;

		if (ISSEQ(otherSeq))
		{
			UArray_replace_with_(ba, DATA(subSeq), DATA(otherSeq));
		}
		else
		{
			IoState_error_(IOSTATE, m,
							"argument 0 to method '%s' must be a Map with Sequence values, not '%s'",
							CSTRING(IoMessage_name(m)), IoObject_name(otherSeq));
		}
		}
	);
Example #3
0
IoObject *IoSeq_convertToFixedSizeType(IoSeq *self, IoObject *locals, IoMessage *m)
{
	IO_ASSERT_NOT_SYMBOL(self);
	UArray_convertToFixedSizeType(DATA(self));
	IoObject_isDirty_(self, 1);
	return self;
}
Example #4
0
IO_METHOD(IoSeq, convertToFixedSizeType)
{
	IO_ASSERT_NOT_SYMBOL(self);
	UArray_convertToFixedSizeType(DATA(self));
	IoObject_isDirty_(self, 1);
	return self;
}
Example #5
0
IoObject *IoSeq_uppercase(IoSeq *self, IoObject *locals, IoMessage *m)
{
	/*doc Sequence uppercase
	Makes all characters of the receiver uppercase. 
	*/

	IO_ASSERT_NOT_SYMBOL(self);
	UArray_toupper(DATA(self));
	return self;
}
Example #6
0
IoObject *IoSeq_removeLast(IoSeq *self, IoObject *locals, IoMessage *m)
{
	/*doc Sequence removeLast
	Removes the last element from the receiver. Returns self.
	*/

	IO_ASSERT_NOT_SYMBOL(self);
	UArray_removeLast(DATA(self));
	return self;
}
Example #7
0
IoObject *IoSeq_lowercase(IoSeq *self, IoObject *locals, IoMessage *m)
{
	/*doc Sequence lowercase
	Makes all the uppercase characters in the receiver lowercase. Returns self. 
	*/

	IO_ASSERT_NOT_SYMBOL(self);
	UArray_tolower(DATA(self));
	return self;
}
Example #8
0
IO_METHOD(IoSeq, lowercase)
{
	/*doc Sequence lowercase
	Makes all the uppercase characters in the receiver lowercase. Returns self. 
	*/

	IO_ASSERT_NOT_SYMBOL(self);
	UArray_tolower(DATA(self));
	return self;
}
Example #9
0
IO_METHOD(IoSeq, removeLast)
{
	/*doc Sequence removeLast
	Removes the last element from the receiver. Returns self.
	*/

	IO_ASSERT_NOT_SYMBOL(self);
	UArray_removeLast(DATA(self));
	return self;
}
Example #10
0
IO_METHOD(IoSeq, uppercase)
{
	/*doc Sequence uppercase
	Makes all characters of the receiver uppercase. 
	*/

	IO_ASSERT_NOT_SYMBOL(self);
	UArray_toupper(DATA(self));
	return self;
}
Example #11
0
IO_METHOD(IoSeq, removeSeq)
{
	/*doc Sequence removeSeq(aSequence)
	Removes occurances of aSequence from the receiver.
	*/

	IoSeq *subSeq   = IoMessage_locals_seqArgAt_(m, locals, 0);
	IO_ASSERT_NOT_SYMBOL(self);
	UArray_remove_(DATA(self), DATA(subSeq));
	return self;
}
Example #12
0
IO_METHOD(IoSeq, setSize)
{
	/*doc Sequence setSize(aNumber)
	Sets the length in bytes of the receiver to aNumber. Return self.
	*/

	size_t len = IoMessage_locals_sizetArgAt_(m, locals, 0);
	IO_ASSERT_NOT_SYMBOL(self);
	UArray_setSize_(DATA(self), len);
	return self;
}
Example #13
0
IO_METHOD(IoSeq, clipBeforeSeq)
{
	/*doc Sequence clipBeforeSeq(aSequence)
	Clips receiver before aSequence.
	*/

	IoSeq *otherSeq = IoMessage_locals_seqArgAt_(m, locals, 0);
	IO_ASSERT_NOT_SYMBOL(self);
	UArray_clipBefore_(DATA(self), DATA(otherSeq));
	return self;
}
Example #14
0
IO_METHOD(IoSeq, copy)
{
	/*doc Sequence copy(aSequence)
	Replaces the bytes of the receiver with a copy of those in aSequence. Returns self. 
	*/

	IO_ASSERT_NOT_SYMBOL(self);

	IoSeq_rawCopy_(self, IoMessage_locals_seqArgAt_(m, locals, 0));
	return self;
}
Example #15
0
IO_METHOD(IoSeq, empty)
{
	/*doc Sequence empty
	Sets all bytes in the receiver to 0x0 and sets
	its length to 0. Returns self.
	*/

	IO_ASSERT_NOT_SYMBOL(self);
	UArray_clear(DATA(self));
	UArray_setSize_(DATA(self), 0);
	return self;
}
Example #16
0
IoObject *IoSeq_empty(IoSeq *self, IoObject *locals, IoMessage *m)
{
	/*doc Sequence empty
	Sets all bytes in the receiver to 0x0 and sets
	it's length to 0. Returns self.
	*/

	IO_ASSERT_NOT_SYMBOL(self);
	UArray_clear(DATA(self));
	UArray_setSize_(DATA(self), 0);
	return self;
}
Example #17
0
IO_METHOD(IoSeq, clipAfterStartOfSeq)
{
	/*doc Sequence clipAfterStartOfSeq(aSequence)
	Removes the contents of the receiver after the beginning of
	the first occurance of aSequence. Returns true if anything was
	removed, or false otherwise.
	*/

	IoSeq *otherSeq = IoMessage_locals_seqArgAt_(m, locals, 0);
	IO_ASSERT_NOT_SYMBOL(self);
	UArray_clipAfterStartOf_(DATA(self), DATA(otherSeq));
	return self;
}
Example #18
0
IO_METHOD(IoSeq, replaceSeq)
{
	/*doc Sequence replaceSeq(aSequence, anotherSequence)
	Returns a new Sequence with all occurances of aSequence
	replaced with anotherSequence in the receiver. Returns self.
	*/

	IoSeq *subSeq   = IoMessage_locals_seqArgAt_(m, locals, 0);
	IoSeq *otherSeq = IoMessage_locals_seqArgAt_(m, locals, 1);
	IO_ASSERT_NOT_SYMBOL(self);
	UArray_replace_with_(DATA(self), DATA(subSeq), DATA(otherSeq));
	return self;
}
Example #19
0
IoObject *IoSeq_clipBeforeEndOfSeq(IoSeq *self, IoObject *locals, IoMessage *m)
{
	/*doc Sequence clipBeforeEndOfSeq(aSequence)
	Removes the contents of the receiver before the end of
	the first occurance of aSequence. Returns true if anything was
	removed, or false otherwise.
	*/

	IoSeq *otherSeq = IoMessage_locals_seqArgAt_(m, locals, 0);
	IO_ASSERT_NOT_SYMBOL(self);
	UArray_clipBeforeEndOf_(DATA(self), DATA(otherSeq));
	return self;
}
Example #20
0
IO_METHOD(IoSeq, removeAt)
{
	/*doc Sequence removeAt(index)
	Removes the item at index. Returns self.
	*/

	long i = IoMessage_locals_longArgAt_(m, locals, 0);

	IO_ASSERT_NOT_SYMBOL(self);

	i = UArray_wrapPos_(DATA(self), i);

	UArray_removeRange(DATA(self), i, 1);
	return self;
}
Example #21
0
IO_METHOD(IoSeq, preallocateToSize)
{
	/*doc Sequence preallocateToSize(aNumber)
	If needed, resize the memory alloced for the receivers
	byte array to be large enough to fit the number of bytes specified by
	aNumber. This is useful for pio_reallocating the memory so it doesn't
	keep getting allocated as the Sequence is appended to. This operation
	will not change the Sequence's length or contents. Returns self.
	*/

	size_t newSize = IoMessage_locals_sizetArgAt_(m, locals, 0);
	IO_ASSERT_NOT_SYMBOL(self);
	UArray_sizeTo_(DATA(self), newSize);
	return self;
}
Example #22
0
IO_METHOD(IoSeq, appendSeq)
{
	/*doc Sequence appendSeq(object1, object2, ...)
	Calls asString on the arguments and appends the string to the receiver. Returns self. 
	*/

	int i;

	IO_ASSERT_NOT_SYMBOL(self);
	IOASSERT(IoMessage_argCount(m), "requires at least one argument");

	for (i = 0; i < IoMessage_argCount(m); i ++)
	{
		UArray_append_(DATA(self), DATA(IoMessage_locals_valueAsStringArgAt_(m, locals, i)));
	}
	return self;
}
Example #23
0
IO_METHOD(IoSeq, leaveThenRemove)
{
	/*doc MutableSequence IoSeq_leaveThenRemove(aNumberToLeave, aNumberToRemove)
	Leaves aNumberToLeave items then removes aNumberToRemove items.  Returns self.
	*/

	size_t itemsToLeave = IoMessage_locals_sizetArgAt_(m, locals, 0);
	size_t itemsToRemove = IoMessage_locals_sizetArgAt_(m, locals, 1);

	IO_ASSERT_NOT_SYMBOL(self);

	IOASSERT(itemsToLeave > 0 || itemsToRemove > 0, "either aNumberToLeave or aNumberToRemove must be > 0");
	
	UArray_leave_thenRemove_(DATA(self), itemsToLeave, itemsToRemove);

	return self;
}
Example #24
0
IO_METHOD(IoSeq, atInsertSeq)
{
	/*doc Sequence atInsertSeq(indexNumber, object)
	Calls asString on object and inserts the string at position indexNumber. Returns self.
	*/

	size_t n = IoMessage_locals_sizetArgAt_(m, locals, 0);
	IoSeq *otherSeq = IoMessage_locals_valueAsStringArgAt_(m, locals, 1);

	IO_ASSERT_NOT_SYMBOL(self);

	IOASSERT(n <= UArray_size(DATA(self)), "insert index out of sequence bounds");

	UArray_at_putAll_(DATA(self), n, DATA(otherSeq));

	return self;
}
Example #25
0
IO_METHOD(IoSeq, removeSlice)
{
	/*doc Sequence removeSlice(startIndex, endIndex)
	Removes the items from startIndex to endIndex.
	Returns self.
	*/

	long start = IoMessage_locals_longArgAt_(m, locals, 0);
	long end   = IoMessage_locals_longArgAt_(m, locals, 1);

	IO_ASSERT_NOT_SYMBOL(self);

	start = UArray_wrapPos_(DATA(self), start);
	end   = UArray_wrapPos_(DATA(self), end);

	UArray_removeRange(DATA(self), start, end - start + 1);
	return self;
}
Example #26
0
IO_METHOD(IoSeq, insertSeqEvery)
{
	/*doc MutableSequence IoSeq_insertSeqEvery(aSequence, aNumberOfItems)
	Inserts aSequence every aNumberOfItems.  Returns self.
	*/

	IoSeq *otherSeq = IoMessage_locals_valueAsStringArgAt_(m, locals, 0);
	size_t itemCount = IoMessage_locals_sizetArgAt_(m, locals, 1);

	IO_ASSERT_NOT_SYMBOL(self);

	IOASSERT(itemCount > 0, "aNumberOfItems must be > 0");
	IOASSERT(itemCount <= UArray_size(DATA(self)), "aNumberOfItems out of sequence bounds");
	
	UArray_insert_every_(DATA(self), DATA(otherSeq), itemCount);

	return self;
}
Example #27
0
IO_METHOD(IoSeq, sort)
{
	//doc Sequence sort Sorts the characters/numbers in the array. Returns self.
	
	UArray *a = DATA(self);
	IO_ASSERT_NOT_SYMBOL(self);

	if(UArray_itemType(a) == CTYPE_uintptr_t)
	{
		UArray_sortBy_(a, (UArraySortCallback *)IoObject_compare);
	}
	else
	{
		UArray_sort(a);
	}

	return self;
}
Example #28
0
IO_METHOD(IoSeq, append)
{
	/*doc Sequence append(aNumber)
	Appends aNumber (cast to a byte) to the receiver. Returns self. 
	*/

	int i;

	IO_ASSERT_NOT_SYMBOL(self);
	IOASSERT(IoMessage_argCount(m), "requires at least one argument");

	for (i = 0; i < IoMessage_argCount(m); i ++)
	{
		UArray_appendDouble_(DATA(self), IoMessage_locals_doubleArgAt_(m, locals, i));
	}

	return self;
}
Example #29
0
IO_METHOD(IoSeq, convertToItemType)
{
	/*doc Sequence convertToItemType(aTypeName)
	Converts the underlying machine type for the elements, expanding or contracting
	the size of the Sequence as needed. 
	Valid names are uint8, uint16, uint32, uint64, int8, int16, int32, 
	int64, float32, and float64. Note that 64 bit types are only available 
	on platforms that support such types. Returns self. 
	*/
	IoSymbol *typeName = IoMessage_locals_symbolArgAt_(m, locals, 0);
	CTYPE itemType = CTYPE_forName(CSTRING(typeName));

	IO_ASSERT_NOT_SYMBOL(self);

	IOASSERT(itemType != -1, "invalid item type name");

	UArray_convertToItemType_(DATA(self), itemType);
	IoObject_isDirty_(self, 1);
	return self;
}
Example #30
0
IO_METHOD(IoSeq, setItemType)
{
	/*doc Sequence setItemType(aTypeName)
	Sets the underlying machine type for the elements. 
	Valid names are uint8, uint16, uint32, uint64, int8, int16, int32, 
	int64, float32, and float64. Note that 64 bit types are only available 
	on platforms that support such types. Returns self. 
	*/

	CTYPE itemType;
	IoSeq *typeName;

	IO_ASSERT_NOT_SYMBOL(self);

	typeName = IoMessage_locals_symbolArgAt_(m, locals, 0);
	itemType = CTYPE_forName(CSTRING(typeName));

	IOASSERT(itemType != -1, "invalid item type name");

	UArray_setItemType_(DATA(self), itemType);
	IoObject_isDirty_(self, 1);
	return self;
}