Esempio n. 1
0
bool
SV_StringIsValid (SVString self)
{
	assert(self);

	for (size_t i = 0, ie = CD_StringLength(self); i < ie; i++) {
		bool      has = false;
		CDString* ch  = CD_CharAt(self, i);

		for (size_t h = 0, he = CD_UTF8_strlen(SVCharset); h < he; h++) {
			const char* che = &SVCharset[CD_UTF8_offset(SVCharset, h)];

			if (strncmp(CD_StringContent(ch), che, CD_StringSize(ch)) == 0) {
				has = true;
				break;
			}
		}

		if (!has && !(strncmp(CD_StringContent(ch), "§", 2) == 0 && i < ie - 2)) {
			CD_DestroyString(ch);
			return false;
		}

		CD_DestroyString(ch);
	}

	return true;
}
Esempio n. 2
0
CDString*
CD_CreateStringFromOffset (CDString* string, size_t offset, size_t limit)
{
	const char* data;

	assert(string);

	if (offset >= CD_StringLength(string)) {
		return NULL;
	}

	data = CD_StringContent(string) + CD_UTF8_offset(CD_StringContent(string), offset);

	if (limit == 0) {
		limit = strlen(data);
	}
	else {
		limit = CD_UTF8_offset(data, limit);
	}

	return CD_CreateStringFromBufferCopy(data, limit);
}
Esempio n. 3
0
CDString*
CD_InsertString (CDString* self, CDString* insert, size_t position)
{
	assert(self);
	assert(insert);

	cd_MakeStringInternal(self);

	if (binsert(self->raw, CD_UTF8_offset(CD_StringContent(self), position), insert->raw, '\0') == BSTR_OK) {
		cd_UpdateLength(self);
	}
	else {
		self = NULL;
	}

	return self;
}
Esempio n. 4
0
CDString*
CD_CharAtSet (CDString* self, size_t index, CDString* set)
{
	assert(self);

	cd_MakeStringInternal(self);

	size_t offset = CD_UTF8_offset((const char*) self->raw->data, index);

	if (breplace(self->raw, offset, cd_UTF8_nextCharLength(self->raw->data[offset]), set->raw, '\0') == BSTR_OK) {
		cd_UpdateLength(self);
	}
	else {
		self = NULL;
	}

	return self;
}
Esempio n. 5
0
SVString
SV_StringSanitize (SVString self)
{
	CDString* result = CD_CreateString();

	assert(self);

	for (size_t i = 0, ie = CD_StringLength(self); i < ie; i++) {
		bool      has = false;
		CDString* ch  = CD_CharAt(self, i);

		for (size_t h = 0, he = CD_UTF8_strlen(SVCharset); h < he; h++) {
			const char* che = &SVCharset[CD_UTF8_offset(SVCharset, h)];

			if (strncmp(CD_StringContent(ch), che, CD_StringSize(ch)) == 0) {
				has = true;
				break;
			}
		}

		if (i == ie - 2 && strncmp(CD_StringContent(ch), "§", 2) == 0){
			CD_DestroyString(ch);
			break;
		}

		if (has || strncmp(CD_StringContent(ch), "§", 2) == 0) {
			CD_AppendString(result, ch);
		}
		else {
			CD_AppendCString(result, "?");
		}

		CD_DestroyString(ch);
	}

	self->length = CD_UTF8_strnlen(CD_StringContent(self), self->raw->slen);

	return result;
}