Merge pull request 'Fixes' (#74) from YanTheKaller/libublsettings:master into master

Reviewed-on: #74
pull/77/head^2 v1.69
Dmitry Razumov 3 months ago
commit d41d276258

@ -250,7 +250,7 @@ char *yon_char_from_int(int int_to_convert)
{ {
int i = snprintf( NULL, 0, "%d", int_to_convert ); int i = snprintf( NULL, 0, "%d", int_to_convert );
char *ch = malloc(i * sizeof(char) + 1); char *ch = malloc(i * sizeof(char) + 1+ int_to_convert<0?1:0);
memset(ch,0,i * sizeof(char) + 1); memset(ch,0,i * sizeof(char) + 1);
sprintf(ch, "%d", int_to_convert); sprintf(ch, "%d", int_to_convert);
return ch; return ch;
@ -264,7 +264,7 @@ char *yon_char_from_float(float int_to_convert)
{ {
convert_check = convert_check / 10; convert_check = convert_check / 10;
} }
char *ch = malloc((i + 9)* sizeof(char)); char *ch = malloc((i + 9)* sizeof(char)+ int_to_convert<0?1:0);
memset(ch,0,(i + 9)* sizeof(char)); memset(ch,0,(i + 9)* sizeof(char));
sprintf(ch, "%.2f", int_to_convert); sprintf(ch, "%.2f", int_to_convert);
return ch; return ch;
@ -278,7 +278,7 @@ char *yon_char_from_double(double int_to_convert)
{ {
convert_check = convert_check / 10; convert_check = convert_check / 10;
} }
char *ch = malloc((i + 9)* sizeof(char)); char *ch = malloc((i + 9)* sizeof(char)+ int_to_convert<0?1:0);
memset(ch,0,(i + 9)* sizeof(char)); memset(ch,0,(i + 9)* sizeof(char));
sprintf(ch, "%.2f", int_to_convert); sprintf(ch, "%.2f", int_to_convert);
return ch; return ch;
@ -286,14 +286,9 @@ char *yon_char_from_double(double int_to_convert)
char *yon_char_from_long(long int_to_convert) char *yon_char_from_long(long int_to_convert)
{ {
int i = 1; size_t size = 20 * sizeof(char) + 1 + int_to_convert<0?1:0;
double convert_check = (double)int_to_convert; char *ch = malloc(size);
for (i = 1; convert_check >= 10; i++) memset(ch,0,size);
{
convert_check = convert_check / 10;
}
char *ch = malloc(i * sizeof(char) + 1);
memset(ch,0,i * sizeof(char) + 1);
sprintf(ch, "%ld", int_to_convert); sprintf(ch, "%ld", int_to_convert);
return ch; return ch;
} }
@ -481,7 +476,9 @@ config_str yon_char_parsed_new (int *size, ...){
void yon_char_parsed_free(config_str source, int size){ void yon_char_parsed_free(config_str source, int size){
if (source&&size>0){ if (source&&size>0){
for (int i=0;i<size;i++){ for (int i=0;i<size;i++){
free(source[i]); if (source[i]){
free(source[i]);
}
} }
free(source); free(source);
} }
@ -555,6 +552,13 @@ config_str yon_char_parsed_merge(config_str array1, int size1, config_str array2
} }
} }
int yon_char_parsed_compare(const config_str a, const config_str b){
const config_str str_a = (const config_str)a;
const config_str str_b = (const config_str)b;
return strcmp(*str_a,*str_b);
}
config_str yon_char_parsed_merge_no_repeats(config_str array1, int size1, config_str array2, int size2, int *final_size){ config_str yon_char_parsed_merge_no_repeats(config_str array1, int size1, config_str array2, int size2, int *final_size){
if (array1&&array2&&size1>0&&size2>0){ if (array1&&array2&&size1>0&&size2>0){
*final_size=0; *final_size=0;

@ -30,7 +30,7 @@ config_str yon_file_open(char *file_path, int *size){
char str_loaded[4098]; char str_loaded[4098];
config_str final_string = NULL; config_str final_string = NULL;
while (fgets(str_loaded,4098,file)){ while (fgets(str_loaded,4098,file)){
final_string = final_string ? yon_char_parsed_append(final_string,size,str_loaded) : yon_char_parsed_new(size,str_loaded,NULL); yon_char_parsed_add_or_create_if_exists(final_string,size,str_loaded);
} }
fclose(file); fclose(file);
return final_string; return final_string;

@ -998,6 +998,12 @@ config_str yon_char_parsed_cut(config_str parsed, int size, int pos);
int yon_char_parsed_find_element(config_str parsed, int size, char *target); int yon_char_parsed_find_element(config_str parsed, int size, char *target);
/// @brief Checks if two config_str elements are equal or not for sort functions
/// @param a pinter for first compared element;
/// @param b pointer for second compared element;
/// @return -1 if a<b; 0 if a=b; 1 if a>b
int yon_char_parsed_compare(const config_str a, const config_str b);
int yon_char_find_last_symbol_before_length(char *string, char target, int length); int yon_char_find_last_symbol_before_length(char *string, char target, int length);
/**yon_char_wrap_to_length(char *target, unsigned int length, int *size) /**yon_char_wrap_to_length(char *target, unsigned int length, int *size)
@ -1513,7 +1519,8 @@ enum YON_LOCALE_PARAMETER{
YON_LOCALE_TERRITORY, YON_LOCALE_TERRITORY,
YON_LOCALE_LANG_AB, YON_LOCALE_LANG_AB,
YON_LOCALE_TITLE, YON_LOCALE_TITLE,
YON_LOCALE_CODE YON_LOCALE_CODE,
YON_LOCALE_CODESET
}; };
typedef struct yon_hash_element{ typedef struct yon_hash_element{

Loading…
Cancel
Save