MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / CmpName

Function CmpName

Libraries/unrar/match.cpp:19–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17
18
19bool CmpName(const wchar *Wildcard,const wchar *Name,int CmpMode)
20{
21 bool ForceCase=(CmpMode&MATCH_FORCECASESENSITIVE)!=0;
22
23 CmpMode&=MATCH_MODEMASK;
24
25 if (CmpMode!=MATCH_NAMES)
26 {
27 size_t WildLength=wcslen(Wildcard);
28 if (CmpMode!=MATCH_EXACT && CmpMode!=MATCH_EXACTPATH && CmpMode!=MATCH_ALLWILD &&
29 mwcsnicompc(Wildcard,Name,WildLength,ForceCase)==0)
30 {
31 // For all modes except MATCH_NAMES, MATCH_EXACT, MATCH_EXACTPATH, MATCH_ALLWILD,
32 // "path1" mask must match "path1\path2\filename.ext" and "path1" names.
33 wchar NextCh=Name[WildLength];
34 if (NextCh==L'\\' || NextCh==L'/' || NextCh==0)
35 return(true);
36 }
37
38 // Nothing more to compare for MATCH_SUBPATHONLY.
39 if (CmpMode==MATCH_SUBPATHONLY)
40 return(false);
41
42 wchar Path1[NM],Path2[NM];
43 GetFilePath(Wildcard,Path1,ASIZE(Path1));
44 GetFilePath(Name,Path2,ASIZE(Path2));
45
46 if ((CmpMode==MATCH_EXACT || CmpMode==MATCH_EXACTPATH) &&
47 mwcsicompc(Path1,Path2,ForceCase)!=0)
48 return(false);
49 if (CmpMode==MATCH_ALLWILD)
50 return match(Wildcard,Name,ForceCase);
51 if (CmpMode==MATCH_SUBPATH || CmpMode==MATCH_WILDSUBPATH)
52 if (IsWildcard(Path1))
53 return(match(Wildcard,Name,ForceCase));
54 else
55 if (CmpMode==MATCH_SUBPATH || IsWildcard(Wildcard))
56 {
57 if (*Path1 && mwcsnicompc(Path1,Path2,wcslen(Path1),ForceCase)!=0)
58 return(false);
59 }
60 else
61 if (mwcsicompc(Path1,Path2,ForceCase)!=0)
62 return(false);
63 }
64 wchar *Name1=PointToName(Wildcard);
65 wchar *Name2=PointToName(Name);
66
67 // Always return false for RAR temporary files to exclude them
68 // from archiving operations.
69// if (mwcsnicompc(L"__rar_",Name2,6,false)==0)
70// return(false);
71
72 if (CmpMode==MATCH_EXACT)
73 return(mwcsicompc(Name1,Name2,ForceCase)==0);
74
75 return(match(Name1,Name2,ForceCase));
76}

Callers 4

CheckArgsMethod · 0.85
IsProcessFileMethod · 0.85
FindProcMethod · 0.85
NextMethod · 0.85

Calls 6

mwcsnicompcFunction · 0.85
GetFilePathFunction · 0.85
mwcsicompcFunction · 0.85
matchFunction · 0.85
IsWildcardFunction · 0.85
PointToNameFunction · 0.85

Tested by

no test coverage detected