IoObject *IoTokyoCabinetPrefixCursor_key(IoObject *self, IoObject *locals, IoMessage *m)
{
	/*doc TokyoCabinetPrefixCursor key
	Returns current cursor key or nil.
	*/
	
	int size;
	char *ks;
	
	IoSeq *prefix = IoObject_getSlot_(self, IOSYMBOL("prefix"));
	IOASSERT(ISSEQ(prefix), "prefix must be a sequence");
	IOASSERT(TokyoCabinetPrefixCursor(self), "invalid TokyoCabinetPrefixCursor");
	ks = tcbdbcurkey(TokyoCabinetPrefixCursor(self), &size);

	if (ks)
	{
		UArray *k = UArray_newWithData_type_size_copy_(ks, CTYPE_uint8_t, size, 1);
	
		if (UArray_beginsWith_(k, IoSeq_rawUArray(prefix)))
		{
			//printf("prefix '%s'\n", UArray_bytes(IoSeq_rawUArray(prefix)));
			//printf("before clip '%s'\n", UArray_bytes(k));
			UArray_clipBeforeEndOf_(k, IoSeq_rawUArray(prefix));
			UArray_removeFirst(k); // remove separator
			//printf("after clip  '%s'\n", UArray_bytes(k));
			return IoSeq_newWithUArray_copy_(IOSTATE, k, 0);
		}

		UArray_free(k);
	}

	return IONIL(self);
}
Exemple #2
0
IoSymbol *IoState_symbolWithCString_length_(IoState *self, const char *s, size_t length)
{
	UArray *a = UArray_newWithData_type_size_copy_((char *)s, CTYPE_uint8_t, length, 1);
	UArray_setEncoding_(a, CENCODING_UTF8);
	UArray_convertToFixedSizeType(a);
	return IoState_symbolWithUArray_copy_(self, a, 0);
}
Exemple #3
0
UArray *IoSHA1_sha1UArray(IoSHA1 *self)
{
	if (DATA(self)->isDone == 0)
	{
		SHA1Final(DATA(self)->digest, &(DATA(self)->context));
		DATA(self)->isDone = 1;
	}

	return UArray_newWithData_type_size_copy_(DATA(self)->digest, CTYPE_uint8_t, SHA1_DIGEST_LENGTH, 1);
}
Exemple #4
0
IoObject *IoTagDB_allUniqueTagIds(IoTagDB *self, IoObject *locals, IoMessage *m)
{
	/*doc TagDB allUniqueTagIds
	Returns a list of all unique tag ids.
	*/
	
	Uint64Array *tagIds = TagDB_allUniqueTags(DATA(self)); 
	UArray *ua = UArray_newWithData_type_size_copy_(Uint64Array_data(tagIds), CTYPE_uint64_t, Uint64Array_size(tagIds), 1);
	
	Uint64Array_free(tagIds);	
	return IoSeq_newWithUArray_copy_(IOSTATE, ua, 0);
}
Exemple #5
0
IoObject *IoTagDB_keysForTags(IoTagDB *self, IoObject *locals, IoMessage *m)
{
	/*doc TagDB keysForTags(aTagNameList)
	Returns list of keys whose tags contain all of the tags in aTagNameList.
	*/
	TagDB *tdb = DATA(self);
	IoList *tagNames = IoMessage_locals_listArgAt_(m, locals, 0);
	Uint64Array *tags = IoTagDB_tagArrayForTagNames_(self, m, tagNames);
	Uint64Array *keys = TagDB_keysForTags_(tdb, tags);
	UArray *keyArray = UArray_newWithData_type_size_copy_(Uint64Array_data(keys), CTYPE_uint64_t, Uint64Array_size(keys), 1);
	IoSeq *keySeq = IoSeq_newWithUArray_copy_(IOSTATE, keyArray, 0);
	Uint64Array_free(tags);
	return keySeq;
}
Exemple #6
0
IoObject *IoRandom_bytes(IoObject *self, IoObject *locals, IoMessage *m)
{
	/*doc Random bytes(count)
	Returns a Sequence of size count containing random bytes.
	*/

	size_t i, count = IoMessage_locals_sizetArgAt_(m, locals, 0);
	UArray *a;
	uint8_t *d = malloc(count);

	for(i = 0; i < count; i ++)
	{
		d[i] = (uint8_t)(RandomGen_randomInt(DATA(self)) & 255);
	}

	a = UArray_newWithData_type_size_copy_(d, CTYPE_uint8_t, count, 0);
	UArray_setEncoding_(a, CENCODING_NUMBER);

	return IoSeq_newWithUArray_copy_(IOSTATE, a, 0);
}
Exemple #7
0
UArray *IoDirectory_CurrentWorkingDirectoryAsUArray(void)
{
#if defined(sparc) || defined(__sparc)
    char *buf = getcwd(NULL, FILENAME_MAX + 1);
#else
    char *buf = NULL;
    buf = (char *)getcwd(buf, 1024);
#endif /* sparc || _sparc */

    if (!buf)
    {
        return UArray_newWithCString_copy_(".", 1);
    }
    else
    {
        UArray *ba =  UArray_newWithData_type_size_copy_((unsigned char *)buf, CTYPE_uint8_t, strlen(buf), 1);
        UArray_setEncoding_(ba, CENCODING_UTF8);
        UArray_convertToFixedSizeType(ba);
        // io_free(buf); OSX get cwd man page says we should io_free this, but MallocDebug does not like it
        return ba;
    }
}
Exemple #8
0
void *Datum_asUArray(Datum *self)
{
	return UArray_newWithData_type_size_copy_(self->data, CENCODING_UTF8, self->size, 0);
}
Exemple #9
0
UArray *UArray_new(void)
{
	return UArray_newWithData_type_size_copy_("", CTYPE_uint8_t, 0, 1);
}
Exemple #10
0
Fichier : tools.c Projet : ADTSH/io
IoSeq *IoSeq_newWithDoubles_count_(void *state, double *doubles, int count)
{
	UArray *array = UArray_newWithData_type_size_copy_(doubles, CTYPE_float64_t, count, 1);
	return IoSeq_newWithUArray_copy_(state, array, 0);
}