Fixes #52

Merged
asmeron merged 3 commits from YanTheKaller/libublsettings:master into master 4 months ago

@ -642,7 +642,7 @@ int yon_char_find_last_symbol_before_length(char *string, char target, int lengt
config_str yon_char_wrap_to_length(char *target, unsigned int length, int *size){ config_str yon_char_wrap_to_length(char *target, unsigned int length, int *size){
(*size)=0; (*size)=0;
if (!yon_char_is_empty(target)&&strlen(target)>length){ if (!yon_char_is_empty(target)&&strlen(target)>length&&strstr(target," ")){
config_str final = NULL; config_str final = NULL;
char *current = yon_char_new(target); char *current = yon_char_new(target);
for (;strlen(current)>length;){ for (;strlen(current)>length;){
@ -656,7 +656,30 @@ config_str yon_char_wrap_to_length(char *target, unsigned int length, int *size)
} }
return final; return final;
} }
return NULL; config_str ret_target = yon_char_parsed_new(size,target,NULL);
return ret_target;
}
char *yon_char_wrap_to_length_str(char *target, unsigned int length){
int size=0;
if (!yon_char_is_empty(target)&&strlen(target)>length&&strstr(target," ")){
config_str final = NULL;
char *current = yon_char_new(target);
for (;strlen(current)>length;){
int last = yon_char_find_last_symbol_before_length(target,' ',length);
if (last>-1){
char *parsed = yon_char_divide(current,last);
yon_char_parsed_add_or_create_if_exists(final,&size,parsed);
free(parsed);
}
}
yon_char_parsed_add_or_create_if_exists(final,&size,current);
char *final_string = yon_char_parsed_to_string(final,size,"\n");
yon_char_parsed_free(final,size);
return final_string;
}
return target;
} }
int yon_ubl_check_root(){ int yon_ubl_check_root(){

@ -306,6 +306,26 @@ char *yon_config_command_get_section(const char *command){
int size; int size;
config_str parsed = yon_char_parse((char*)command,&size," "); config_str parsed = yon_char_parse((char*)command,&size," ");
int section_pos = yon_config_command_get_section_pos(parsed,size); int section_pos = yon_config_command_get_section_pos(parsed,size);
if (section_pos==-1) return NULL;
char *section = yon_char_new(parsed[section_pos]);
yon_char_parsed_free(parsed,size);
return section;
}
int yon_config_command_get_path_pos(config_str parsed, int size){
for (int i=0;i<size-1;i++){
if (!strcmp(parsed[i],"--source")||!strcmp(parsed[i],"--target")){
return i+1;
}
}
return -1;
}
char *yon_config_command_get_path(const char *command){
int size;
config_str parsed = yon_char_parse((char*)command,&size," ");
int section_pos = yon_config_command_get_path_pos(parsed,size);
if (section_pos==-1) return NULL;
char *section = yon_char_new(parsed[section_pos]); char *section = yon_char_new(parsed[section_pos]);
yon_char_parsed_free(parsed,size); yon_char_parsed_free(parsed,size);
return section; return section;

@ -592,6 +592,8 @@ int yon_char_find_last_symbol_before_length(char *string, char target, int lengt
*/ */
config_str yon_char_wrap_to_length(char *target, unsigned int length, int *size); config_str yon_char_wrap_to_length(char *target, unsigned int length, int *size);
char *yon_char_wrap_to_length_str(char *target, unsigned int length);
/**yon_ubl_check_root() /**yon_ubl_check_root()
* [EN] * [EN]
* *
@ -851,6 +853,9 @@ int yon_char_remove_brackets(char *string);
int yon_config_command_get_section_pos(config_str parsed, int size); int yon_config_command_get_section_pos(config_str parsed, int size);
char *yon_config_command_get_section(const char *command); char *yon_config_command_get_section(const char *command);
int yon_config_command_get_path_pos(config_str parsed, int size);
char *yon_config_command_get_path(const char *command);
int yon_config_load_config(YON_CONFIG_TYPE config_type, ...); int yon_config_load_config(YON_CONFIG_TYPE config_type, ...);
int yon_config_change_key(char *target, char *key); int yon_config_change_key(char *target, char *key);

Loading…
Cancel
Save