Bug 487192: Move both copies of nsWildCard into xpcom. r/sr=bsmedberg

- Sync up filepicker's nsWildCard to fixes made to libjar's version.
This commit is contained in:
Peter Annema 2009-05-13 20:22:53 -07:00
parent 8256d0bd8d
commit ed77e28f6c
3 changed files with 29 additions and 45 deletions

View File

@ -51,7 +51,7 @@
#include "plstr.h"
#include "prmem.h"
/* ----------------------------- _valid_subexp ------------------------------ */
/* ----------------------------- _valid_subexp ---------------------------- */
static int

View File

@ -22,8 +22,8 @@
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
@ -38,9 +38,10 @@
/* *
*
*
* shexp.c: shell-like wildcard match routines
* nsWildCard.cpp: shell-like wildcard match routines
*
* See shexp.h for public documentation.
* See nsIZipReader.findEntries documentation in nsIZipReader.idl for
* a description of the syntax supported by the routines in this file.
*
* Rob McCool
*
@ -51,7 +52,7 @@
#include "plstr.h"
#include "prmem.h"
/* ----------------------------- shexp_valid ------------------------------ */
/* ----------------------------- _valid_subexp ---------------------------- */
static int
@ -77,7 +78,7 @@ _valid_subexp(PRUnichar *expr, PRUnichar stop)
++nsc;
if((!expr[++x]) || (expr[x] == ']'))
return INVALID_SXP;
for(++x;expr[x] && (expr[x] != ']');++x)
for(;expr[x] && (expr[x] != ']');++x)
if(expr[x] == '\\')
if(!expr[++x])
return INVALID_SXP;
@ -134,7 +135,7 @@ NS_WildCardValid(PRUnichar *expr)
}
/* ----------------------------- shexp_match ----------------------------- */
/* ----------------------------- _shexp_match ----------------------------- */
#define MATCH 0
@ -235,8 +236,16 @@ _shexp_match(const PRUnichar *str, const PRUnichar *expr,
else {
int matched;
for (matched=0;expr[y] != ']';y++)
for (matched=0;expr[y] != ']';y++) {
/* match an escaped ']' character */
if('\\' == expr[y] && ']' == expr[y+1]) {
if(']' == str[x])
matched |= 1;
y++; /* move an extra char to compensate for '\\' */
continue;
}
matched |= (str[x] == expr[y]);
}
if (neg ^ (!matched))
ret = NOMATCH;
}

View File

@ -22,8 +22,8 @@
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
@ -36,36 +36,23 @@
* ***** END LICENSE BLOCK ***** */
/*
* shexp.h: Defines and prototypes for shell exp. match routines
* nsWildCard.h: Defines and prototypes for shell exp. match routines
*
* See nsIZipReader.findEntries docs in nsIZipReader.idl for a description of
* the supported expression syntax.
*
* Note that the syntax documentation explicitly says the results of certain
* expressions are undefined. This is intentional to require less robustness
* in the code. Regular expression parsing is hard; the smaller the set of
* features and interactions this code must support, the easier it is to
* ensure it works.
*
* This routine will match a string with a shell expression. The expressions
* accepted are based loosely on the expressions accepted by zsh.
*
* o * matches anything
* o ? matches one character
* o \ will escape a special character
* o $ matches the end of the string
* o [abc] matches one occurence of a, b, or c. The only character that needs
* to be escaped in this is ], all others are not special.
* o [a-z] matches any character between a and z
* o [^az] matches any character except a or z
* o ~ followed by another shell expression will remove any pattern
* matching the shell expression from the match list
* o (foo|bar) will match either the substring foo, or the substring bar.
* These can be shell expressions as well.
*
* The public interface to these routines is documented below.
*
* Rob McCool
*
*/
#ifndef nsWildCard_h__
#define nsWildCard_h__
#include "prtypes.h"
#include "nscore.h"
#include <ctype.h> /* isalnum */
#include <string.h> /* strlen */
@ -103,16 +90,4 @@ extern int NS_WildCardValid(PRUnichar *expr);
extern int NS_WildCardMatch(const PRUnichar *str, const PRUnichar *expr,
PRBool case_insensitive);
/*
* Same as above, but validates the exp first. 0 on match, 1 on non-match,
* -1 on invalid exp.
*/
extern int NS_WildCardSearch(const PRUnichar *str, const PRUnichar *expr);
/*
* Same as above but uses case insensitive search.
*/
extern int NS_WildCardCaseSearch(const PRUnichar *str, const PRUnichar *expr);
#endif /* nsWildCard_h__ */