Skip to content

Commit

Permalink
Fix regex sort
Browse files Browse the repository at this point in the history
  • Loading branch information
BrknRobot committed Apr 6, 2021
1 parent 094fbd5 commit c806cd8
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions lib/preprocess.c
Expand Up @@ -356,36 +356,43 @@ char *rm_pp_compile_patterns(RmSession *session, const char *sortcrit, GError **
static int rm_pp_cmp_by_regex(GRegex *regex, int idx, RmPatternBitmask *mask_a,
const char *path_a, RmPatternBitmask *mask_b,
const char *path_b) {
int result = 0;
int result_a = 0;
int result_b = 0;

if(RM_PATTERN_IS_CACHED(mask_a, idx)) {
/* Get the previous match result */
result = RM_PATTERN_GET_CACHED(mask_a, idx);
result_a = RM_PATTERN_GET_CACHED(mask_a, idx);
} else {
/* Match for the first time */
result = g_regex_match(regex, path_a, 0, NULL);
RM_PATTERN_SET_CACHED(mask_a, idx, result);
}

if(result) {
return -1;
result_a = g_regex_match(regex, path_a, 0, NULL);
RM_PATTERN_SET_CACHED(mask_a, idx, result_a);
}

if(RM_PATTERN_IS_CACHED(mask_b, idx)) {
/* Get the previous match result */
result = RM_PATTERN_GET_CACHED(mask_b, idx);
result_b = RM_PATTERN_GET_CACHED(mask_b, idx);
} else {
/* Match for the first time */
result = g_regex_match(regex, path_b, 0, NULL);
RM_PATTERN_SET_CACHED(mask_b, idx, result);
result_b = g_regex_match(regex, path_b, 0, NULL);
RM_PATTERN_SET_CACHED(mask_b, idx, result_b);
}

if(result) {
return +1;
/* Both match */
if(result_a && result_b) {
return 0;
}
/* Only a */
else if (result_a) {
return -1;
}
/* Only b */
else if (result_b) {
return 1;
}
/* Neither */
else {
return 0;
}

/* Both match or none of the both match */
return 0;
}

/*
Expand Down

0 comments on commit c806cd8

Please sign in to comment.