Exemplo n.º 1
0
c_iter
c_splitString(
    const c_char *str,
    const c_char *delimiters)
{
    const c_char *head, *tail;
    c_char *nibble;
    c_iter iter = NULL;
    c_long length;

    if (str == NULL) return NULL;

    tail = str;
    while (*tail != '\0') {
        head = c_skipUntil(tail,delimiters);
        length = abs((c_address)head - (c_address)tail);
        if (length != 0) {
            length++;
            nibble = (c_string)os_malloc(length);
            os_strncpy(nibble,tail,length);
            nibble[length-1]=0;
            iter = c_iterAppend(iter,nibble);
        }
        tail = head;
        if (c_isOneOf(*tail,delimiters)) tail++;
    }
    return iter;
}
Exemplo n.º 2
0
c_char *
c_skipSpaces (
    const c_char *str)
{
    if (str == NULL) return NULL;
    while (c_isOneOf(*str, " \t")) str++;
    return (c_char *)str;
}
Exemplo n.º 3
0
c_char *
c_skipUntil (
    const c_char *str,
    const c_char *symbolList)
{
    c_char *ptr = (c_char *)str;

    assert(symbolList != NULL);
    if (ptr == NULL) return NULL;

    while (*ptr != '\0' && !c_isOneOf(*ptr,symbolList)) ptr++;
    return ptr;
}
Exemplo n.º 4
0
c_char *
c_skipIdentifier (
    const c_char *str,
    const c_char *puctuationList)
{
    c_char *ptr = (c_char *)str;

    if (ptr == NULL) return NULL;

    if (!c_isLetter(*ptr)) {
        return ptr;
    }
    ptr++;
    while (c_isLetter(*ptr) || c_isDigit(*ptr) || c_isOneOf(*ptr, puctuationList)) {
        ptr++;
    }
    return ptr;
}
Exemplo n.º 5
0
c_iter
v_partitionPolicySplit(
    v_partitionPolicyI p)
{
    const c_char *head, *tail;
    c_char *nibble;
    c_iter iter = NULL;
    os_size_t length;
    const c_char *delimiters = ",";

    if (p.v == NULL) return NULL;

    head = p.v;
    do {
        tail = c_skipUntil(head,delimiters);
        length = (os_size_t) (tail - head);
        if (length != 0) {
            length++;
            nibble = (c_string)os_malloc(length);
            os_strncpy(nibble, head, length);
            nibble[length-1]=0;
            iter = c_iterAppend(iter, nibble);
        } else {
            /* head points to one of the delimiters, so we add an empty string */
            length = 1;
            nibble = (c_string)os_malloc(length);
            nibble[length - 1 ] = 0;
            iter = c_iterAppend(iter, nibble);
        }
        head = tail;
        if (c_isOneOf(*head, delimiters)) {
            /* if the string ends with a delimiter, we also add an empty string */
            head++;
            if (*head == '\0') {
                length = 1;
                nibble = (c_string)os_malloc(length);
                nibble[length - 1 ] = 0;
                iter = c_iterAppend(iter, nibble);
            }
        }
    } while (*head != '\0');

    return iter;
}