コード例 #1
0
ファイル: test_string.c プロジェクト: myoan/minikonoha
void test_kString(KonohaContext *kctx)
{
    intptr_t i;
    kString *s;
    for (i = 0; i < 100; ++i) {
        s = KLIB new_kString(kctx, GcUnsafe, "abcd", 4, 0);
        assert(strcmp(kString_text(s), "abcd") == 0);
        assert(kString_size(s) == 4);
        assert(kString_Is(ASCII, s) == 1);
    }
    for (i = 0; i < 100; ++i) {
        s = KLIB new_kString(kctx, GcUnsafe, "abcd", 4, 0);
        assert(strcmp(kString_text(s), "abcd") == 0);
        assert(kString_size(s) == 4);
        assert(kString_text(s) == (char*)s->inline_text);
    }
    for (i = 0; i < 100; ++i) {
        static const char *text = "12345678901234567890";
        s = KLIB new_kString(kctx, GcUnsafe, text, 20, StringPolicy_TEXT | StringPolicy_UTF8);
        assert(strcmp(kString_text(s), text) == 0);
        assert(kString_size(s) == 20);
        assert(kString_text(s) == text);
        assert(kString_Is(ASCII, s) == 0);
    }
}
コード例 #2
0
ファイル: File_glue.c プロジェクト: imasahiro/konoha3
//## @Const String File.scriptPath(String path);
static KMETHOD File_scriptPath(KonohaContext *kctx, KonohaStack *sfp)
{
	char scriptPathBuf[K_PATHMAX];
	const char *scriptPath = PLATAPI formatTransparentPath(scriptPathBuf, sizeof(scriptPathBuf), KFileLine_textFileName(sfp[K_RTNIDX].calledFileLine), kString_text(sfp[1].asString));
	kStringVar *resultValue = (kStringVar *)KLIB new_kString(kctx, OnStack, scriptPath, strlen(scriptPath), 0);
	if(kString_Is(Literal, sfp[1].asString)) {
		kString_Set(Literal, resultValue, true);
	}
	KReturn(resultValue);
}
コード例 #3
0
ファイル: File_glue.c プロジェクト: imasahiro/konoha3
//## void File.print(String line);
static KMETHOD File_print(KonohaContext *kctx, KonohaStack *sfp)
{
	kFile   *file = sfp[0].asFile;
	kString *line = sfp[1].asString;
	KMakeTrace(trace, sfp);
	if(file->writerIconv == ICONV_NULL || kString_Is(ASCII, line)) {
		TRACE_fwrite(kctx, file, kString_text(line), kString_size(line), trace);
	}
	else {
		KBuffer wb;
		KLIB KBuffer_Init(&(kctx->stack->cwb), &wb);
		KLIB KBuffer_iconv(kctx, &wb, file->writerIconv, kString_text(line), kString_size(line), trace);
		TRACE_fwrite(kctx, file, KLIB KBuffer_text(kctx, &wb, NonZero), KBuffer_bytesize(&wb), trace);
		KLIB KBuffer_Free(&wb);
	}
}