Glib字符串实用程序函数(strcspn的echivalent)

时间:2015-04-03 13:12:16

标签: glib

我想提取首次出现" /"

后存在的字符串

例如,有一个char *卡,其形式为:

    hw:0/Line

    default/Master

我需要char *频道(Line,Master,...)

在标准C中可以使用" strcspn"和" strlen"

    char *card, *channel;
    int i;

    i = strcspn(card, "/");
    if (i == strlen(card)) {
        channel = "Master";
    } else {
        card[i] = 0;
        channel = card + i + 1;
    }

如何使用glib字符串实用程序函数执行此操作?

1 个答案:

答案 0 :(得分:2)

strcspnstrlen出了什么问题?

GLib重新实现了很多东西C99和POSIX,因为它针对的是C89编译器。它不会重新实现strlenstrcspn之类的内容,因为它们不需要 - 它们位于C89中。

GLib也倾向于实现许多函数的UTF-8版本,虽然有g_utf8_strlen我不知道g_utf8_strcspn我认为这不是真的有必要案件。如果是,那么您可能必须通过使用g_utf8_next_char遍历字符串并检查g_utf8_get_charg_utf8_get_char_validated的结果来自行实现。

相关问题