liblunar的调用节日的bug

if (strstr(format, "%(jieri)") != NULL)
{
    gchar bufs[128];
    gchar *tmp;
    tmp = lunar_date_get_jieri(date, " ");
    if (*tmp)
    {
        g_utf8_strncpy(bufs, tmp, g_utf8_strlen(tmp, 128));
    }

    /*if (strstr(tmp, " " ) != NULL)
    {
        char** buf = g_strsplit(tmp, " ", -1);
        if (g_utf8_validate(*buf, -1, NULL))
            g_utf8_strncpy(bufs, *buf, 3);
        else
        {
            strncpy(bufs, *buf, 4);
            bufs[4]= '\0';
        }
        g_strfreev(buf);
    }
    else
    {
        if (g_utf8_validate(tmp, -1, NULL))
            g_utf8_strncpy(bufs, tmp, 3);
        else
        {
            strncpy(bufs, tmp, 4);
            bufs[4]= '\0';
        }
    }*/
    g_free(tmp);
    str = g_string_replace(str, "%(jieri)", bufs, -1);
}

好吧,本意是要拆分开然后再组在一起,却写的莫名其妙的,应该用循环也没用,就改了下。这下可以显示全了。

测试的代码为:

#include <lunar/lunar.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    //g_type_init(); 这句我扔到lunar_init函数里面去了。
    lunar_init(&argc, &argv);
    LunarDate *lunar_date = lunar_date_new();
    lunar_date_set_solar_date(lunar_date, 2011, 10, 28, 1, NULL);
    gchar *str = lunar_date_strftime(lunar_date, "%(NIAN)年%(YUE)月%(RI)日%(SHI)时 生肖:%(shengxiao) 节日:%(jieri)");

    printf("out str:%s", str);
    lunar_date_free(lunar_date);
    exit(0);
}