// Scan a directory to collect up all entries that match
	// the specified search criteria, returning FileSystemInfo's.
	internal static Object ScanDirectoryForInfos
				(String path, String searchPattern,
				 ScanType scanType, Type arrayType)
			{
				Regex regex;
				ArrayList list;
				InternalFileInfo[] entries;
				Errno error;
				int posn;
				String filename;
				FileType type;

				// Get all files in the directory.
				error = DirMethods.GetFilesInDirectory(path, out entries);
				if(error != Errno.Success)
				{
					HandleErrorsDir(error);
				}
				if(entries == null)
				{
					return new String [0];
				}

				// Convert the search pattern into a regular expression.
				if(searchPattern == null)
				{
					regex = null;
				}
				else
				{
					regex = new Regex(searchPattern, RegexSyntax.Wildcard);
				}

				// Scan the file list and collect up matching entries.
				list = new ArrayList (entries.Length);
				for(posn = 0; posn < entries.Length; ++posn)
				{
					filename = entries[posn].fileName;
					if(filename == "." || filename == "..")
					{
						continue;
					}
					type = entries[posn].fileType;
					switch(scanType)
					{
						case ScanType.Directories:
						{
							if(type != FileType.directory)
							{
								continue;
							}
						}
						break;

						case ScanType.Files:
						{
							if(type == FileType.directory)
							{
								continue;
							}
						}
						break;

						default: break;
					}
					if(regex != null && !regex.Match(filename))
					{
						continue;
					}
					if(type == FileType.directory)
					{
						list.Add(new DirectoryInfo
									(Path.Combine(path, filename)));
					}
					else
					{
						list.Add(new FileInfo(Path.Combine(path, filename)));
					}
				}

				// Dispose of the regular expression.
				if(regex != null)
				{
					regex.Dispose();
				}

				// Return the list of strings to the caller.
				return list.ToArray(arrayType);
			}
Exemple #2
0
	static Uri()
	{
   /* RFC2396 : Appendix B
		As described in Section 4.3, the generic URI syntax is not sufficient
		to disambiguate the components of some forms of URI.  Since the
		"greedy algorithm" described in that section is identical to the
		disambiguation method used by POSIX regular expressions, it is
		natural and commonplace to use a regular expression for parsing
		^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
		12            3  4          5       6  7        8 9
		
		(Modified to support mailto: syntax as well)
	*/
      String regularexpression= 
	  	"^(([^:/?#]+):)?"+ // scheme
		"(" +
			"(//)?"+ // delim
			"(([^@]+)@)?" + // userinfo
			"([^/?#:]*)?" + // host
			"(:([^/?#]+))?"+ // port
		")"+
		"([^?#]*)"+  // path
		"(\\?([^#]*))?"+ // query
		"(#(.*))?$"; // fragment
			/*	
			Indexing
			0 --> full
			2 --> scheme
			4 --> delim
			6 --> userinfo
			7 --> host
			9 --> port
			10 --> path
			11 --> query
			13 --> fragment */
			
		/* Insert grouping symbols */
		regularexpression=regularexpression.Replace("(","\\("); 
		regularexpression=regularexpression.Replace(")","\\)");

		try
		{
			uriRegex = new Regex(regularexpression, RegexSyntax.PosixCommon);

			/* Really test this expression on each start-up, use the 
			 * backup SlowParse() if this library fails to work 
			 */
			String input=
				"https://*****:*****@www.gnu.org:443/free/software?id=for#all";
		
			RegexMatch[] matches = uriRegex.Match( input, 
												RegexMatchOptions.Default,
												16);	
			hasFastRegex = true;
			int [][] expected = new int[][] { 
							new int[]{0,56},
							new int[]{0,6},
							new int[]{0,5},
							new int[]{6,31},
							new int[]{6,8},
							new int[]{8,16},
							new int[]{8,15},
							new int[]{16,27},
							new int[]{27,31},
							new int[]{28,31},
							new int[]{31,45},
							new int[]{45,52},
							new int[]{46,52},
							new int[]{52,56},
							new int[]{53,56},
					};
			
			for(int i=0;i< matches.Length && hasFastRegex ; i++)
			{
				hasFastRegex = hasFastRegex && 
								(matches[i].start == expected[i][0]) &&
								(matches[i].end == expected[i][1]) ;
			}
		}
		catch
		{
			if(uriRegex!=null) 
			{
				uriRegex.Dispose();
				uriRegex = null;
			}
			hasFastRegex = false;
		}

		schemes.Add(UriSchemeFile,	new UriScheme(-1,	"://"));
		schemes.Add(UriSchemeFtp,		new UriScheme(23,	"://"));
		schemes.Add(UriSchemeGopher,	new UriScheme(70,	"://"));
		schemes.Add(UriSchemeHttp,	new UriScheme(80,	"://"));
		schemes.Add(UriSchemeHttps,	new UriScheme(443,	"://"));
		schemes.Add(UriSchemeNntp,	new UriScheme(119,	"://"));
		schemes.Add(UriSchemeMailto,	new UriScheme(25,	":"));
		schemes.Add(UriSchemeNews,	new UriScheme(-1,	":"));
	}