/* * Copyright (C) 2006-2011 by Benedict Paten (benedictpaten@gmail.com) * * Released under the MIT license, see LICENSE.txt */ /* * sonLibString.c * * Created on: 24-May-2010 * Author: benedictpaten */ #include "sonLibGlobalsInternal.h" char *stString_copy(const char *string) { if (string == NULL) { return NULL; } else { return strcpy(st_malloc(sizeof(char)*(1+strlen(string))), string); } } char *stString_print(const char *string, ...) { int32_t arraySize = 0; static char *cA = NULL; //return; va_list ap; va_start(ap, string); int32_t i = vsnprintf(cA, arraySize, string, ap); va_end(ap); assert(i >= 0); if(i >= arraySize) { arraySize = i+1; if(cA != NULL) { free(cA); } cA = st_malloc(sizeof(char) * arraySize); va_start(ap, string); i = vsnprintf(cA, arraySize, string, ap); assert(i+1 == arraySize); va_end(ap); } //vfprintf(stdout, string, ap); return stString_copy(cA); } char *stString_getNextWord(char **string) { while(**string != '\0' && isspace(**string)) { (*string)++; } char *i = *string; while(**string != '\0' && !isspace(**string)) { (*string)++; } if((*string) - i > 0) { char *cA = memcpy(st_malloc(((*string)-i + 1)*sizeof(char)), i, ((*string)-i)*sizeof(char)); cA[(*string) - i] = '\0'; return cA; } return NULL; } static int32_t string_replaceP(char *start, const char *pattern) { uint32_t i; for(i=0; i 0); //Must be non zero length replacement string. j=0; i=(char *)originalString; while(*i != '\0') { if(string_replaceP(i, toReplace)) { j++; i += strlen(toReplace); } else { i++; } } newString = st_malloc(sizeof(char)*(strlen(originalString) + j*strlen(replacement) - j*strlen(toReplace) + 1)); k=newString; i=(char *)originalString; while(*i != '\0') { if(string_replaceP(i, toReplace)) { for(j=0; j= 0); j = strlen(pad) * (length > 0 ? length - 1 : 0) + 1; for(i=0; i