int main()
{
    printf("%d\n", strSearch("SoftUni", "Soft"));
    printf("%d\n", strSearch("Hard Rock", "Rock"));
    printf("%d\n", strSearch("Ananas", "nasa"));
    printf("%d\n", strSearch("Coolness", "cool"));
    
    return 0;
}
Пример #2
0
        ZLFileEnum(LPCTSTR lpDirName, LPCTSTR lpPost=_T("*.*"))
        {
            CString strSearch(lpDirName);
            ZLPath::PathAddBackslash(strSearch);
            m_strDir = strSearch;
            strSearch.Append(lpPost);

            WIN32_FIND_DATA wfd = {0};
            HANDLE hFind = ::FindFirstFile(strSearch, &wfd);

            if (hFind != INVALID_HANDLE_VALUE)
            {
                do 
                {
                    CString strFileName = wfd.cFileName;
                    if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                    {
                        if (strFileName.Compare(_T("."))==0||
                            strFileName.Compare(_T(".."))==0)
                            continue;
                        m_listDirs.push_back(strFileName);
                    }
                    else
                    {
                        ZLFileEnumInfo fi;
                        fi.m_strFileName = strFileName;
                        fi.m_nSize  = wfd.nFileSizeLow;	
                        m_listFiles.push_back(fi);
                    }
                }while (::FindNextFile(hFind, &wfd));
                ::FindClose( hFind );
            }
        }
Пример #3
0
int main(int argc, char **argv)
{
  int decimal, number, len;
  char *result;

  if(argc != 3)
    {
      usage(argv[0]);
      return -1;
    }

  if(strSearch(argv[1]) == -1)
    {
      usage(argv[0]);
      return -1;
    }

  if(strSearch(argv[2]) == -1)
    {
      usage(argv[0]);
      return -1;
    }

  if(atoi(argv[1]) <= 1)
    {
      usage(argv[0]);
      return -1;
    }

  if(atoi(argv[1]) < 2 || atoi(argv[1]) > 36)
    {
      usage(argv[0]);
      return -1;
    }
     
  decimal = atoi(argv[1]);
  number = atoi(argv[2]);
  len = (int)(log(number) / log(decimal)) + 1;
  result = (char *)malloc(sizeof(char) * len);
  memset(result, '\0', len + 1);
  toDecimal(decimal, number, result, len);
  printf("%s\n", result);
  free(result);
  return 0;
}
Пример #4
0
// CFileOpenDlg::EnumDirs
//
//		Enumerates all subdirectories. Recurses depth-first 
//
int CFileOpenDlg::EnumDirs(LPCTSTR pszPath, LPCTSTR pszFilter, HTREEITEM hItemParent)
{
	WIN32_FIND_DATA	fd;
	HANDLE			hFind;
	BOOL			bFind;
	HTREEITEM		hItem = TVI_LAST;
	CString			strSearch(pszPath),
					strBase(pszPath);
	int				nCount	= 0;

	strSearch += pszFilter;

	hFind = FindFirstFile(strSearch, &fd);
	bFind = (hFind != INVALID_HANDLE_VALUE);

	while(bFind)
	{
		if((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
		   !(fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
		{
			TVINSERTSTRUCT	tvi;
			CString			strSub(strBase);
			int				iIcon;

			strSub += fd.cFileName;
			iIcon = GetIconIndex(strSub);

			tvi.hParent				= hItemParent;
			tvi.hInsertAfter		= TVI_LAST;
			tvi.item.mask			= TVIF_CHILDREN | TVIF_IMAGE | TVIF_SELECTEDIMAGE |
									  TVIF_TEXT | TVIF_PARAM;
			tvi.item.pszText		= fd.cFileName;
			tvi.item.iImage			= iIcon;
			tvi.item.iSelectedImage	= iIcon;
			tvi.item.cChildren		= I_CHILDRENCALLBACK;
			tvi.item.lParam			= -1;

			hItem = m_treeFolder.InsertItem(&tvi);

			++nCount;
/*
			strSub += _T("\\");
			if(hItem)
			{
				m_treeFolder.SetItemData(hItem, 1);

				EnumDirs(strSub, pszFilter, hItem);
			}*/
		}

		bFind = FindNextFile(hFind, &fd);
	}
	return nCount;
}
bool FreeImageLoader::canLoad(const core::string& fileName){
	if(m_isDummy)
		return false;

	core::string str=core::StringUtil::ToLower(fileName);
	return strSearch(str.c_str(),m_ext.c_str())!=0;
	/*

	FREE_IMAGE_FORMAT fif=FreeImage_GetFileType(fileName.c_str(),0);
	if(fif==FIF_UNKNOWN)
		fif = FreeImage_GetFIFFromFilename(fileName.c_str());
	//if still unkown, return failure
	if(fif == FIF_UNKNOWN)
		return false;

	return true;*/
}
Пример #6
0
static void DiffDir_WalkDir(LPCTSTR strDirIn, CDiffer& D)
{
	std::string strDir(strDirIn);
	if( '\\' != (strDir.at(strDir.length()-1)) )
	{
		strDir.append("\\");
	}

	std::string strSearch(strDir);
	strSearch.append("*");

	//printf("Scanning \"%s\"...\n", strDir.c_str());

	WIN32_FIND_DATA FD;
	HANDLE hFind = FindFirstFile(strSearch.c_str(), &FD);
	if(INVALID_HANDLE_VALUE == hFind)
		return;

	do
	{
		//If we have a directory we behave a little differently.
		if(((FILE_ATTRIBUTE_DIRECTORY&FD.dwFileAttributes) != 0))
		{
			//printf("Found directory.\n");
			if('.' == FD.cFileName[0])
				continue;

			std::string strSubDir(strDir);
			strSubDir.append(FD.cFileName);
			DiffDir_WalkDir(strSubDir.c_str(), D);
		}
		else
		{
			std::string strFile(strDir);
			strFile.append(FD.cFileName);
			//printf("Found %s.\n", strFile.c_str());
			D.AddFile(strFile.c_str(), FD);
		}

	}while(FindNextFile(hFind, &FD));

	FindClose(hFind);
}
Пример #7
0
bool CTextSearch::Search(const std::string &strHaystack) const
{
  if (strHaystack.empty() || !IsValid())
    return false;

  std::string strSearch(strHaystack);
  if (!m_bCaseSensitive)
    StringUtils::ToLower(strSearch);

  /* check whether any of the NOT terms matches and return false if there's a match */
  for (unsigned int iNotPtr = 0; iNotPtr < m_NOT.size(); iNotPtr++)
  {
    if (strSearch.find(m_NOT.at(iNotPtr)) != std::string::npos)
      return false;
  }

  /* check whether at least one of the OR terms matches and return false if there's no match found */
  bool bFound(m_OR.size() == 0);
  for (unsigned int iOrPtr = 0; iOrPtr < m_OR.size(); iOrPtr++)
  {
    if (strSearch.find(m_OR.at(iOrPtr)) != std::string::npos)
    {
      bFound = true;
      break;
    }
  }
  if (!bFound)
    return false;

  /* check whether all of the AND terms match and return false if one of them wasn't found */
  for (unsigned int iAndPtr = 0; iAndPtr < m_AND.size(); iAndPtr++)
  {
    if (strSearch.find(m_AND[iAndPtr]) == std::string::npos)
      return false;
  }

  /* all ok, return true */
  return true;
}
bool SkeletonLoader::canLoad(OS::IStream* file){
	core::string str=core::StringUtil::ToLower(file->getStreamName());
	return strSearch(str.c_str(),mT(".skel"))!=0;
}
bool SkeletonLoader::canLoad(const core::string& fileName){
	core::string str=core::StringUtil::ToLower(fileName);
	return strSearch(str.c_str(),mT(".skel"))!=0;
}
Пример #10
0
int main(void){
    char str[] = "apple";
    strSearch('a', str);
    printf("%s", str);
}
Пример #11
0
bool CPakLoader::canLoadArchive(const  core::string&filename){
	core::string str(filename);
	str.make_lower();
	return strSearch(str.c_str(),mT(".pak"))!=0;
}
Пример #12
0
// CFileOpenDlg::EnumFiles
//
//		Enumerates all files in a folder
//
void CFileOpenDlg::EnumFiles(LPCTSTR pszPath, LPCTSTR pszFilter)
{
	WIN32_FIND_DATA	fd;
	HANDLE			hFind;
	BOOL			bFind;
	CString			strSearch(pszPath),
					strFile;
	int				i = 0,
					iItem;
	COleDateTime	odt;
	CDateTimeFormat	dtf;
	CWaitCursor		wait;

	//
	// Flush the list
	//
	m_listFile.DeleteAllItems();
	m_cont.clear();

	//
	// Fill in the list
	//
	strSearch += pszFilter;

	hFind = FindFirstFile(strSearch, &fd);
	bFind = (hFind != INVALID_HANDLE_VALUE);

	//
	// Disable painting the list
	//
	m_listFile.SetRedraw(FALSE);

	while(bFind)
	{
		if(!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && 
		   !(fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
		{
			strFile = pszPath;
			strFile += fd.cFileName;
			iItem = m_listFile.InsertItem(i, fd.cFileName, GetIconIndex(strFile));
			if(iItem != -1)
			{
				//
				// Format size according to locale
				//
				m_listFile.SetItemText(iItem, 1, FormatSize(fd.nFileSizeLow));

				//
				// Format date according to locale
				//
				odt = fd.ftLastWriteTime;
				dtf.SetDateTime(odt);
				dtf.SetFormat(m_strDateFormat);

				m_listFile.SetItemText(iItem, 2, dtf.GetString());
				m_listFile.SetItemData(iItem, i);

				m_cont.push_back(fd);
			}

			i++;
		}

		bFind = FindNextFile(hFind, &fd);
	}
	DoSortList();

	//
	// Enable painting the list
	//
	m_listFile.SetRedraw(TRUE);

}
Пример #13
0
void CDirectoryListing::Init(const char *szDirPath, int nMode)
{
	static GString dotdot("..");
	static GString dot(".");
	
	bool bIncludeSubDirs = (nMode == 2 || nMode == 3) ? 1 : 0;
	bool bIncludeFiles = (nMode == 1 || nMode == 3) ? 1 : 0;
	
	
	GString strPathWithTrailingSlash(szDirPath);
	GString strPathWithNoTrailingSlash(szDirPath);

	// if szDirPath ends with a slash
	if ( strPathWithNoTrailingSlash.Right(1) == "/" ||
		 strPathWithNoTrailingSlash.Right(1) == "\\" )
	{
		// if the path is "/" leave it alone
		if (strPathWithNoTrailingSlash.Length() > 1)
			strPathWithNoTrailingSlash = strPathWithNoTrailingSlash.Left(strPathWithNoTrailingSlash.Length() - 1);
	}
	else
	{
		strPathWithTrailingSlash += "\\";

	}

	if( _access( (const char *)strPathWithNoTrailingSlash, 0 ) )
	{
		throw GenericException("GDirectoryListing",0,(const char *)strPathWithNoTrailingSlash, errno);
	}

	// FindFirstFile & FindNextFile
	HANDLE hFindFile;
	WIN32_FIND_DATA find;
	BOOL fRet = TRUE;
	GString strSearch( strPathWithTrailingSlash );
	strSearch += "*.*";
	hFindFile = FindFirstFile((const char *)strSearch, &find);
	while (hFindFile != (HANDLE)-1 && fRet == TRUE) 
	{
		GString strTemp( strPathWithTrailingSlash );
		strTemp += find.cFileName;
		struct stat sstruct;

		int result = stat(strTemp, &sstruct);
		if (result == 0)
		{
			if ( !(sstruct.st_mode & _S_IFDIR)  )
			{
				// Add the file
				if (bIncludeFiles)
				{
					AddLast((const char *)find.cFileName);
				}
			}
			else if (bIncludeSubDirs)
			{
				GString strFileName( LastLeaf( (char *)(const char *)strTemp,'\\') );
				if ( ( dotdot.Compare(strFileName) != 0 ) && ( dot.Compare(strFileName) != 0 ))
				{
					GString strFormattedDir;
					strFormattedDir.Format("[dir] %s", LastLeaf( (char *)(const char *)strFileName,'\\') );
					AddLast((const char *)strFormattedDir);
				}
			}

		}

		fRet = FindNextFile(hFindFile, &find);
	}
	FindClose(hFindFile);
}
Пример #14
0
bool CZipLoader::canLoadArchive(const  core::string&filename){
	core::string str=core::StringUtil::ToLower(filename);
	return strSearch(str.c_str(),mT(".zip"))!=0;
}