Function changes

pull/43/head
parent f88af8fde2
commit 5571741e0a

@ -1,7 +1,5 @@
#include "libublsettings.h" #include "libublsettings.h"
int yon_char_find_last(char *source, char find){ int yon_char_find_last(char *source, char find){
int size = strlen(source); int size = strlen(source);
int i=size; int i=size;
@ -14,10 +12,14 @@ char *yon_char_append(const char *source, const char *append)
{ {
if (source && append) if (source && append)
{ {
int size = strlen(source) + strlen(append) + 1; int source_size = strlen(source);
int append_size = strlen(append);
int size = source_size + append_size + 1;
char *final = malloc(size); char *final = malloc(size);
memset(final, 0, size); memset(final, 0, size);
sprintf(final, "%s%s", source, append); memcpy(final,source,source_size);
memcpy(final+source_size,append,append_size);
// sprintf(final, "%s%s", source, append);
return final; return final;
} }
return NULL; return NULL;
@ -155,16 +157,16 @@ char *yon_char_divide(char *source, int dividepos)
return NULL; return NULL;
} }
int yon_char_find_count(char *source, char *find){ // int yon_char_find_count(char *source, char *find){
char *working_string=yon_char_new(source); // char *working_string=yon_char_new(source);
int i=0; // int i=0;
int size=0; // int size=0;
int pos=0; // int pos=0;
config_str rtn = yon_char_parse(working_string,&size,find); // config_str rtn = yon_char_parse(working_string,&size,find);
free(working_string); // free(working_string);
yon_char_parsed_free(rtn,size); // yon_char_parsed_free(rtn,size);
return size-1; // return size-1;
} // }
int yon_char_count(char *source, char *find){ int yon_char_count(char *source, char *find){
char *working_string=yon_char_new(source); char *working_string=yon_char_new(source);
@ -246,13 +248,16 @@ char *yon_char_from_long(long int_to_convert)
char *yon_char_replace(char *source, char *find, char*replace){ char *yon_char_replace(char *source, char *find, char*replace){
if (!strstr(replace,find)){ if (!strstr(replace,find)){
int source_size = strlen(source);
int replace_size = strlen(replace);
char *final=NULL; char *final=NULL;
char *temp=NULL; char *temp=NULL;
if(!strstr(replace,find)){ if(!strstr(replace,find)){
while ((final=strstr(source,find))){ while ((final=strstr(source,find))){
temp=malloc(strlen(source)-strlen(final)+strlen(replace)); int final_size = strlen(final);
memset(temp,0,strlen(source)-strlen(final)+strlen(replace)); temp=malloc(-final_size+replace_size);
memcpy(temp,source,strlen(source)-strlen(final)); memset(temp,0,source_size-final_size+replace_size);
memcpy(temp,source,source_size-final_size);
temp=yon_char_append(temp,replace); temp=yon_char_append(temp,replace);
source=yon_char_append(temp,final+strlen(find)); source=yon_char_append(temp,final+strlen(find));
} }

Loading…
Cancel
Save