Beispiel #1
0
static status_t ExpandFilePathWildCardsAux(const String & curDir, const String & path, Queue<String> & outputPaths, bool isSimpleFormat)
{
   const char * fs = GetFilePathSeparator();
   const int32 sepIdx = path.IndexOf(fs);
   const String firstClause  = (sepIdx >= 0) ? path.Substring(0, sepIdx) : path;
   const String restOfString = (sepIdx >= 0) ? path.Substring(sepIdx+1) : GetEmptyString();

   StringMatcher sm(firstClause, isSimpleFormat);
   Directory dir(curDir());
   if (dir.IsValid())
   {
      if (CanWildcardStringMatchMultipleValues(firstClause))
      {
         while(1)
         {
            const char * fn = dir.GetCurrentFileName();
            if (fn)
            {
               if ((strcmp(fn, ".") != 0)&&(strcmp(fn, "..") != 0)&&((fn[0] != '.')||(firstClause.StartsWith(".")))&&(sm.Match(fn)))
               {
                  const String childPath = String(dir.GetPath())+fn;
                  if (restOfString.HasChars())
                  {
                     if (ExpandFilePathWildCardsAux(childPath, restOfString, outputPaths, isSimpleFormat) != B_NO_ERROR) return B_ERROR;
                  }
                  else if (outputPaths.AddTail(childPath) != B_NO_ERROR) return B_ERROR;
               } 
               dir++;
            }
            else break;
         }
      }
      else
      {
         const String childPath = String(dir.GetPath())+firstClause;
         if (FilePathInfo(childPath()).Exists())
         {
            if (restOfString.HasChars())
            {
               if (ExpandFilePathWildCardsAux(childPath, restOfString, outputPaths, isSimpleFormat) != B_NO_ERROR) return B_ERROR;
            }
            else if (outputPaths.AddTail(childPath) != B_NO_ERROR) return B_ERROR;
         }
      }
   }
   return B_NO_ERROR;
}
Beispiel #2
0
ff::String ff::CleanFileName(StringRef name)
{
	String szNewName(name);

	for (size_t i = PreviousSize(szNewName.length()); i != INVALID_SIZE; i = PreviousSize(i))
	{
		wchar_t ch = szNewName[i];

		if (ch == '.' && (i == szNewName.length() - 1 || (i > 0 && szNewName[i - 1] == '.')))
		{
			// Don't allow more than one period in a row,
			// and don't allow a period at the end
			szNewName.erase(i, 1);
		}
		else if (ch < 32 || ch > 125)
		{
			szNewName[i] = '-';
		}
		else switch (ch)
		{
		case '<':  szNewName[i] = '(';  break;
		case '>':  szNewName[i] = ')';  break;
		case ':':  szNewName[i] = '-';  break;
		case '\"': szNewName[i] = '\''; break;
		case '/':  szNewName[i] = '-';  break;
		case '\\': szNewName[i] = '-';  break;
		case '|':  szNewName[i] = '-';  break;
		case '?':  szNewName[i] = '-';  break;
		case '*':  szNewName[i] = '-';  break;
		}
	}

	String szExt = GetPathExtension(szNewName);
	ChangePathExtension(szNewName, GetEmptyString());

	if (!_wcsicmp(szNewName.c_str(), L"CON") ||
		!_wcsicmp(szNewName.c_str(), L"PRN") ||
		!_wcsicmp(szNewName.c_str(), L"AUX") ||
		!_wcsicmp(szNewName.c_str(), L"NUL") ||
		!_wcsicmp(szNewName.c_str(), L"COM1") ||
		!_wcsicmp(szNewName.c_str(), L"COM2") ||
		!_wcsicmp(szNewName.c_str(), L"COM3") ||
		!_wcsicmp(szNewName.c_str(), L"COM4") ||
		!_wcsicmp(szNewName.c_str(), L"COM5") ||
		!_wcsicmp(szNewName.c_str(), L"COM6") ||
		!_wcsicmp(szNewName.c_str(), L"COM7") ||
		!_wcsicmp(szNewName.c_str(), L"COM8") ||
		!_wcsicmp(szNewName.c_str(), L"COM9") ||
		!_wcsicmp(szNewName.c_str(), L"LPT1") ||
		!_wcsicmp(szNewName.c_str(), L"LPT2") ||
		!_wcsicmp(szNewName.c_str(), L"LPT3") ||
		!_wcsicmp(szNewName.c_str(), L"LPT4") ||
		!_wcsicmp(szNewName.c_str(), L"LPT5") ||
		!_wcsicmp(szNewName.c_str(), L"LPT6") ||
		!_wcsicmp(szNewName.c_str(), L"LPT7") ||
		!_wcsicmp(szNewName.c_str(), L"LPT8") ||
		!_wcsicmp(szNewName.c_str(), L"LPT9"))
	{
		szNewName += L"-File";
	}

	ChangePathExtension(szNewName, szExt);

	return szNewName;
}