Back to index

lightning-sunbird  0.9+nobinonly
nsWildCard.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039  * shexp.h: Defines and prototypes for shell exp. match routines
00040  * 
00041  *
00042  * This routine will match a string with a shell expression. The expressions
00043  * accepted are based loosely on the expressions accepted by zsh.
00044  * 
00045  * o * matches anything
00046  * o ? matches one character
00047  * o \ will escape a special character
00048  * o $ matches the end of the string
00049  * o [abc] matches one occurence of a, b, or c. The only character that needs
00050  *         to be escaped in this is ], all others are not special.
00051  * o [a-z] matches any character between a and z
00052  * o [^az] matches any character except a or z
00053  * o ~ followed by another shell expression will remove any pattern
00054  *     matching the shell expression from the match list
00055  * o (foo|bar) will match either the substring foo, or the substring bar.
00056  *             These can be shell expressions as well.
00057  * 
00058  * The public interface to these routines is documented below.
00059  * 
00060  * Rob McCool
00061  * 
00062  */
00063  
00064 #ifndef nsWildCard_h__
00065 #define nsWildCard_h__
00066 
00067 #include "prtypes.h"
00068 #include "nscore.h"
00069 #include <ctype.h>  /* isalnum */
00070 #include <string.h> /* strlen */
00071 
00072 /* --------------------------- Public routines ---------------------------- */
00073 
00074 
00075 /*
00076  * NS_WildCardValid takes a shell expression exp as input. It returns:
00077  * 
00078  *  NON_SXP      if exp is a standard string
00079  *  INVALID_SXP  if exp is a shell expression, but invalid
00080  *  VALID_SXP    if exp is a valid shell expression
00081  */
00082 
00083 #define NON_SXP -1
00084 #define INVALID_SXP -2
00085 #define VALID_SXP 1
00086 
00087 extern int NS_WildCardValid(PRUnichar *expr);
00088 
00089 
00090 /* return values for the search routines */
00091 #define MATCH 0
00092 #define NOMATCH 1
00093 #define ABORTED -1
00094 
00095 /*
00096  * NS_WildCardMatch
00097  * 
00098  * Takes a prevalidated shell expression exp, and a string str.
00099  *
00100  * Returns 0 on match and 1 on non-match.
00101  */
00102 
00103 extern int NS_WildCardMatch(const PRUnichar *str, const PRUnichar *expr,
00104                             PRBool case_insensitive);
00105 
00106 /*
00107  * Same as above, but validates the exp first. 0 on match, 1 on non-match,
00108  * -1 on invalid exp.
00109  */
00110 
00111 extern int NS_WildCardSearch(const PRUnichar *str, const PRUnichar *expr);
00112 
00113 /*
00114  * Same as above but uses case insensitive search.
00115  */
00116 extern int NS_WildCardCaseSearch(const PRUnichar *str, const PRUnichar *expr);
00117 
00118 #endif /* nsWildCard_h__ */