Beispiel #1
0
SVString
SV_StringColor (SVString self, SVStringColor color)
{
	assert(self);

	if (CD_StringLength(self) > 0) {
		return SV_StringColorRange(self, color, 0, CD_StringLength(self));
	}
	else {
		return self;
	}
}
Beispiel #2
0
MCString
MC_StringColor (MCString self, MCStringColor color)
{
    assert(self);

    if (CD_StringLength(self) > 0) {
        return MC_StringColorRange(self, color, 0, CD_StringLength(self));
    }
    else {
        return self;
    }
}
Beispiel #3
0
bool
MC_StringIsValid (MCString 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(MCCharset); h < he; h++) {
            const char* che = &MCCharset[cd_UTF8_offset(MCCharset, 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;
}
Beispiel #4
0
MCString
MC_StringSanitize (MCString 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(MCCharset); h < he; h++) {
            const char* che = &MCCharset[cd_UTF8_offset(MCCharset, 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);
    }

    cd_UpdateLength(self);

    return result;
}
Beispiel #5
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);
}
Beispiel #6
0
MCString
MC_StringColorRange (MCString self, MCStringColor color, size_t a, size_t b)
{
    if (self->external) {
        CDString* tmp = self;
        self          = CD_CloneString(tmp);
        CD_DestroyString(tmp);
    }

    CDString* start = CD_CreateStringFromFormat("§%x", color);
    CDString* end   = CD_CreateStringFromCString(MC_COLOR_WHITE);

    assert(self);
    assert(a < b);
    assert(a >= 0 && b <= CD_StringLength(self));

    CD_InsertString(self, end, b);
    CD_InsertString(self, start, a);

    CD_DestroyString(start);
    CD_DestroyString(end);

    return self;
}
Beispiel #7
0
inline
bool
CD_StringEmpty (CDString* self)
{
	return (self == NULL || self->raw == NULL || CD_StringLength(self) == 0);
}