Commit bc6cdf65 bc6cdf65cf26b9c2bdedbbe39e1ea79ae4e23742 by Sergey Poznyakoff

(util_wcard_match): from list.c

1 parent bfc095f2
...@@ -891,3 +891,52 @@ util_localname () ...@@ -891,3 +891,52 @@ util_localname ()
891 } 891 }
892 return localname; 892 return localname;
893 } 893 }
894
895 /* Match STRING against the IMAP4 wildard pattern PATTERN */
896
897 int
898 util_wcard_match (const char *string, const char *pattern, const char *delim)
899 {
900 const char *p = pattern, *n = string;
901 char c;
902
903 for (;(c = *p++) != '\0' && *n; n++)
904 {
905 switch (c)
906 {
907 case '%':
908 if (*p == '\0')
909 {
910 /* Matches everything except '/' */
911 for (; *n && *n != delim[0]; n++)
912 ;
913 return (*n == delim[0]) ? WCARD_RECURSE_MATCH : WCARD_MATCH;
914 }
915 else
916 for (; *n != '\0'; ++n)
917 if (util_wcard_match (n, p, delim) == WCARD_MATCH)
918 return WCARD_MATCH;
919 break;
920
921 case '*':
922 if (*p == '\0')
923 return WCARD_RECURSE_MATCH;
924 for (; *n != '\0'; ++n)
925 {
926 int status = util_wcard_match (n, p, delim);
927 if (status == WCARD_MATCH || status == WCARD_RECURSE_MATCH)
928 return status;
929 }
930 break;
931
932 default:
933 if (c != *n)
934 return WCARD_NOMATCH;
935 }
936 }
937
938 if (!c && !*n)
939 return WCARD_MATCH;
940
941 return WCARD_NOMATCH;
942 }
......