Added a replacer class that is based on the AC trie data structure.
It replaces all occurrences of given patterns (case insensetive) in the given text in O(new_length) where new_length is a length of the text after replacement. Before all replacements (uwufying kernel name, hardware names, etc) were done in
O(patterns_count pattern_length new_length) on average, so this data structure speeds up replacement of the substrings.
Also now all patterns and replacements for them are added in one function void uwufy_all(struct info*), while before they all were used separately in the different functions. As a result it will be easier to add new patterns in the future. (all you need to add a new pattern is write actrie_t_add_pattern(&replacer, pattern, pattern_replacement); )
To test this data structure 11 tests were added to the /src/tests/tests.c
New file "actrie.h" is formatted with clang-format and changes are tested with make, make debug and make tests on Ubuntu based OS
Example of how replacer works can be found in added test functions, for example, in bool test8_long():
(all this replacements are done in O(new_length) without splitting the original string)
Settings of this class can be modified in the beginning of the actrie.h header file:
Describe your changes
Added a replacer class that is based on the AC trie data structure.
It replaces all occurrences of given patterns (case insensetive) in the given text in O(new_length) where new_length is a length of the text after replacement. Before all replacements (uwufying kernel name, hardware names, etc) were done in O(patterns_count pattern_length new_length) on average, so this data structure speeds up replacement of the substrings.
Also now all patterns and replacements for them are added in one function
void uwufy_all(struct info*)
, while before they all were used separately in the different functions. As a result it will be easier to add new patterns in the future. (all you need to add a new pattern is writeactrie_t_add_pattern(&replacer, pattern, pattern_replacement);
)To test this data structure 11 tests were added to the
/src/tests/tests.c
New file "actrie.h" is formatted with clang-format and changes are tested withmake
,make debug
andmake tests
on Ubuntu based OSExample of how replacer works can be found in added test functions, for example, in![image](https://github.com/TheDarkBug/uwufetch/assets/92759021/0600ec5a-98cb-4d80-bec0-b39a35548e67)
bool test8_long()
: (all this replacements are done in O(new_length) without splitting the original string)Settings of this class can be modified in the beginning of the![image](https://github.com/TheDarkBug/uwufetch/assets/92759021/3262657d-0282-4d05-aa70-7a9071db87c0)
actrie.h
header file: