MCPcopy Create free account
hub / github.com/ConEmu/ConEmu / CompareFileMask

Function CompareFileMask

src/common/CmdLine.cpp:491–529  ·  view source on GitHub ↗

One trailing (or middle) asterisk allowed

Source from the content-addressed store, hash-verified

489
490// One trailing (or middle) asterisk allowed
491bool CompareFileMask(const wchar_t* asFileName, const wchar_t* asMask)
492{
493 if (!asFileName || !*asFileName || !asMask || !*asMask)
494 return false;
495 // Any file?
496 if (*asMask == L'*' && *(asMask+1) == 0)
497 return true;
498
499 int iCmp = -1;
500
501 wchar_t sz1[MAX_PATH+1], sz2[MAX_PATH+1];
502 lstrcpyn(sz1, asFileName, countof(sz1));
503 size_t nLen1 = lstrlen(sz1);
504 CharUpperBuffW(sz1, (DWORD)nLen1);
505 lstrcpyn(sz2, asMask, countof(sz2));
506 size_t nLen2 = lstrlen(sz2);
507 CharUpperBuffW(sz2, (DWORD)nLen2);
508
509 wchar_t* pszAst = wcschr(sz2, L'*');
510 if (!pszAst)
511 {
512 iCmp = lstrcmp(sz1, sz2);
513 }
514 else
515 {
516 *pszAst = 0;
517 size_t nLen = pszAst - sz2;
518 size_t nRight = lstrlen(pszAst+1);
519 if (wcsncmp(sz1, sz2, nLen) == 0)
520 {
521 if (!nRight)
522 iCmp = 0;
523 else if (nLen1 >= (nRight + nLen))
524 iCmp = lstrcmp(sz1+nLen1-nRight, pszAst+1);
525 }
526 }
527
528 return (iCmp == 0);
529}
530
531LPCWSTR GetDrive(LPCWSTR pszPath, wchar_t* szDrive, int/*countof(szDrive)*/ cchDriveMax)
532{

Callers 3

UnitMaskTestsFunction · 0.85
cmdIsAnsiExecAllowedMethod · 0.85
DoExportEnvFunction · 0.85

Calls

no outgoing calls

Tested by 1

UnitMaskTestsFunction · 0.68