int flatten_string(const SpaceText *st, FlattenString *fs, const char *in)
{
	int r, i, total = 0;

	memset(fs, 0, sizeof(FlattenString));
	fs->buf = fs->fixedbuf;
	fs->accum = fs->fixedaccum;
	fs->len = sizeof(fs->fixedbuf);

	for (r = 0, i = 0; *in; r++) {
		if (*in == '\t') {
			i = st->tabnumber - (total % st->tabnumber);
			total += i;

			while (i--)
				flatten_string_append(fs, " ", r, 1);

			in++;
		}
		else {
			size_t len = BLI_str_utf8_size_safe(in);
			flatten_string_append(fs, in, r, len);
			in += len;
			total++;
		}
	}

	flatten_string_append(fs, "\0", r, 1);

	return total;
}
Exemple #2
0
int flatten_string(SpaceText *st, FlattenString *fs, const char *in)
{
	int r = 0, i = 0;

	memset(fs, 0, sizeof(FlattenString));
	fs->buf= fs->fixedbuf;
	fs->accum= fs->fixedaccum;
	
	for(r=0, i=0; *in; r++, in++) {
		if(*in=='\t') {
			if(fs->pos && *(in-1)=='\t')
				i= st->tabnumber;
			else if(st->tabnumber > 0)
				i= st->tabnumber - (fs->pos%st->tabnumber);

			while(i--)
				flatten_string_append(fs, ' ', r);
		}
		else
			flatten_string_append(fs, *in, r);
	}

	return fs->pos;
}