[Helper] Quick and dirty string replacer with optional keys block.

First (quick and dirty) version of a more advanced key replacer where
sets of text are only outputted if the contained key matches.
This commit is contained in:
Dave Davenport
2018-10-16 21:01:45 +02:00
parent 6830e5d117
commit e8edc42f9d
3 changed files with 134 additions and 0 deletions

View File

@@ -336,5 +336,21 @@ void parse_ranges ( char *input, rofi_range_pair **list, unsigned int *length );
* @param filter
*/
void rofi_output_formatted_line ( const char *format, const char *string, int selected_line, const char *filter );
/**
* @param string The string with elements to be replaced
* @param ... Set of {key}, value that will be replaced, terminated by a NULL
*
* Items {key} are replaced by the value if '{key}' is passed as key/value pair, otherwise removed from string.
* If the {key} is in between [] all the text between [] are removed if {key}
* is not found. Otherwise key is replaced and [ & ] removed.
*
* This allows for optional replacement, f.e. '{ssh-client} [-t {title}] -e
* "{cmd}"' the '-t {title}' is only there if {title} is set.
*
* @returns a new string with the keys replaced.
*/
char *helper_string_replace_if_exists ( char * string, ... );
G_END_DECLS
#endif // ROFI_HELPER_H