Expansion: Added documentation for wildcard checking

This commit is contained in:
Jérôme Guélen 2025-03-24 13:52:42 +01:00
parent 08d883b792
commit c73884e43a
No known key found for this signature in database

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/21 13:46/14 by khais #+# #+# */ /* Created: 2025/03/21 13:46/14 by khais #+# #+# */
/* Updated: 2025/03/21 13:46:14 by khais ### ########.fr */ /* Updated: 2025/03/24 13:51:30 by jguelen ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -90,8 +90,41 @@ static void init_pattern_checker(t_worddesc *pattern, char **checker)
** This construction is only done for the current diectory so no special ** This construction is only done for the current diectory so no special
** treatment is to be considered for '/' characters which otherwise have ** treatment is to be considered for '/' characters which otherwise have
** to be matched explicitely. We do however consider the case where the '.' ** to be matched explicitely. We do however consider the case where the '.'
** character cannot be matched unless explicitely when in first position ** character cannot be matched except explicitely when in first position
** in str. ** in str.
** This function has the goal of building an array of prefix recognition
** where each and every cell i,j in the array corresponds to the matching of the
** prefix str[0 .. i - 1] with pattern[0 .. j - 1].
** the array has the form:
** empty string will be noted ε.
** pattern | | p[0] | . . . | p[pattern_len - 1]
** _s_\_(p)_|___________________|__________|_______|____________________
** i \ j | 0 | 1 | . . . | pattern_len
** _____\___|___________________|__________|_______|____________________
** 0 | ε == ε | | | pattern == ε
** _________|___________________|__________|_______|____________________
** 1 | str[0..0] == ε |str[0..0] | |
** | |== p[0..0]| | pattern == p[0..0]
** _________|___________________|__________|_______|____________________
** . | | | |
** . | | | |
** . | | | |
** _________|___________________|__________|_______|____________________
** str len|| str == ε | str == | |
** [len - 1]| | p[0..0] | | pattern == str
**
** There are several ways to preserve a match while going forward either in str,
** in pattern or both: either you are matching corresponding characters or a '?'
** wildcard in pattern with str or you are considering a '*' wildcard in
** pattern. In those cases you can inherit from a match previously reached.
** Otherwise, no match can be found.
** When considering two characters that are identical (or '?' in pattern) you
** will match exactly if amd only if you matched one character before in both
** strings.
** In the case of the consideration of the '*' wildcard in pattern, since it
** matches both ε and any arbitrary string, you will match if before seeing the
** '*' in pattern you already matched (case ε i.e. checker[i-1][j]) or if you
** englobe the character currently considered in str (checker[i][j - 1]).
*/ */
void build_pattern_checks(char *str, t_worddesc *pattern, void build_pattern_checks(char *str, t_worddesc *pattern,
char **checker) char **checker)