Exemple #1
0
END_TEST

START_TEST(test_str_add_printf)
{
	str_t *str = str_from_cstr("123");
	str_add_printf(&str, "%d", 456);
	CHECK_STR(str, >= 6, == 6, "123456");
	str_free(str);

	str = str_new(0);
	str_add_printf(&str, "%d", 31337);
	str_add_printf(&str, "%s", "31337");
	CHECK_STR(str, >= 10, == 10, "3133731337");
	str_free(str);
}
Exemple #2
0
static int make_ac_proposal(struct make_ac_ctx *ctx, struct ac_proposal *p,
			    CXCompletionResult *r, str_t *fmt)
{
	unsigned int chunks_n;

	chunks_n = clang_getNumCompletionChunks(r->CompletionString);
	str_clear(ctx->word);
	str_clear(ctx->abbr);
	str_clear(ctx->type);
	str_clear(ctx->text);

	for (unsigned int i = 0; i < chunks_n; ++i) {
		enum CXCompletionChunkKind kind;
		CXString s;

		kind = clang_getCompletionChunkKind(r->CompletionString, i);
		s = clang_getCompletionChunkText(r->CompletionString, i);
		switch (kind) {
		case CXCompletionChunk_ResultType:
			str_add_printf(&ctx->type, "%s", clang_getCString(s));
			break;
		case CXCompletionChunk_TypedText:
			str_add_cstr(&ctx->word, clang_getCString(s));
		default:
			str_add_cstr(&ctx->text, clang_getCString(s));
			break;
		}
		clang_disposeString(s);
	}

	if (ctx->type->len > MAX_TYPE_CHARS) {
		ctx->type->len = MAX_TYPE_CHARS-1;
		str_add_cstr(&ctx->type, "…");
	}
	str_add_printf(&ctx->abbr, fmt->data,
		       ctx->type->data, ctx->text->data);

	p->abbr = strdup(ctx->abbr->data);
	p->word = strdup(ctx->word->data);
	return 1;
}