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; }
void jni_getTopicKeyExpression( v_entity entity, c_voidp args) { v_kernel vk; c_iter vtopics; c_array keyList; c_char* keyExpr; c_long nrOfKeys, totalSize, i; c_string fieldName, actualFieldName; struct jni_topicArg *arg; arg = (struct jni_topicArg *)args; vk = v_objectKernel(entity); if(vk != NULL){ vtopics = v_resolveTopics(vk, arg->topicName); if(c_iterLength(vtopics) == 0){ c_iterFree(vtopics); } else{ keyList = v_topicMessageKeyList(c_iterTakeFirst(vtopics)); c_iterFree(vtopics); nrOfKeys = c_arraySize(keyList); if (nrOfKeys>0) { totalSize = 0; for (i=0;i<nrOfKeys;i++) { fieldName = c_fieldName(keyList[i]); totalSize += (strlen(fieldName)+1-9/*skip 'userdata.'*/); } keyExpr = (c_char *)os_malloc((size_t)(totalSize+1)); keyExpr[0] = 0; for (i=0;i<nrOfKeys;i++) { fieldName = c_fieldName(keyList[i]); actualFieldName = c_skipUntil(fieldName, "."); actualFieldName++; /*skip '.' */ os_strcat(keyExpr,actualFieldName); if (i<(nrOfKeys-1)) { os_strcat(keyExpr,","); } } arg->keyExpr = keyExpr; } else{ /*No keys, do nothing.*/ } arg->result = U_RESULT_OK; } } }
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; }