本文整理汇总了C++中WStrVec::size方法的典型用法代码示例。如果您正苦于以下问题:C++ WStrVec::size方法的具体用法?C++ WStrVec::size怎么用?C++ WStrVec::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WStrVec
的用法示例。
在下文中一共展示了WStrVec::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CmdLineParserTest
void CmdLineParserTest() {
WStrVec args;
ParseCmdLine(L"test.exe -arg foo.pdf", args);
utassert(3 == args.size());
utassert(str::Eq(args.at(0), L"test.exe"));
utassert(str::Eq(args.at(1), L"-arg"));
utassert(str::Eq(args.at(2), L"foo.pdf"));
args.Reset();
ParseCmdLine(L"test.exe \"foo \\\" bar \\\\.pdf\" un\\\"quoted.pdf", args);
utassert(3 == args.size());
utassert(str::Eq(args.at(0), L"test.exe"));
utassert(str::Eq(args.at(1), L"foo \" bar \\\\.pdf"));
utassert(str::Eq(args.at(2), L"un\"quoted.pdf"));
args.Reset();
ParseCmdLine(L"test.exe \"foo\".pdf foo\" bar.pdf ", args);
utassert(3 == args.size());
utassert(str::Eq(args.at(0), L"test.exe"));
utassert(str::Eq(args.at(1), L"foo.pdf"));
utassert(str::Eq(args.at(2), L"foo bar.pdf "));
args.Reset();
ParseCmdLine(L"test.exe -arg \"%1\" -more", args, 2);
utassert(2 == args.size());
utassert(str::Eq(args.at(0), L"test.exe"));
utassert(str::Eq(args.at(1), L"-arg \"%1\" -more"));
args.Reset();
}
示例2: SetCloseProcessMsg
static void SetCloseProcessMsg() {
AutoFreeW procNames(str::Dup(ReadableProcName(gProcessesToClose.at(0))));
for (size_t i = 1; i < gProcessesToClose.size(); i++) {
const WCHAR* name = ReadableProcName(gProcessesToClose.at(i));
if (i < gProcessesToClose.size() - 1)
procNames.Set(str::Join(procNames, L", ", name));
else
procNames.Set(str::Join(procNames, L" and ", name));
}
AutoFreeW s(str::Format(_TR("Please close %s to proceed!"), procNames));
SetMsg(s, COLOR_MSG_FAILED);
}
示例3: SourceToRecord
// Find a record corresponding to the given source file, line number and optionally column number.
// (at the moment the column parameter is ignored)
//
// If there are several *consecutively declared* records for the same line then they are all returned.
// The list of records is added to the vector 'records'
//
// If there is no record for that line, the record corresponding to the nearest line is selected
// (within a range of EPSILON_LINE)
//
// The function returns PDFSYNCERR_SUCCESS if a matching record was found.
UINT Pdfsync::SourceToRecord(const WCHAR* srcfilename, UINT line, UINT col, Vec<size_t>& records) {
UNUSED(col);
if (!srcfilename)
return PDFSYNCERR_INVALID_ARGUMENT;
AutoFreeW srcfilepath;
// convert the source file to an absolute path
if (PathIsRelative(srcfilename))
srcfilepath.Set(PrependDir(srcfilename));
else
srcfilepath.SetCopy(srcfilename);
if (!srcfilepath)
return PDFSYNCERR_OUTOFMEMORY;
// find the source file entry
size_t isrc;
for (isrc = 0; isrc < srcfiles.size(); isrc++)
if (path::IsSame(srcfilepath, srcfiles.at(isrc)))
break;
if (isrc == srcfiles.size())
return PDFSYNCERR_UNKNOWN_SOURCEFILE;
if (fileIndex.at(isrc).start == fileIndex.at(isrc).end)
return PDFSYNCERR_NORECORD_IN_SOURCEFILE; // there is not any record declaration for that particular source file
// look for sections belonging to the specified file
// starting with the first section that is declared within the scope of the file.
UINT min_distance = EPSILON_LINE; // distance to the closest record
size_t lineIx = (size_t)-1; // closest record-line index
for (size_t isec = fileIndex.at(isrc).start; isec < fileIndex.at(isrc).end; isec++) {
// does this section belong to the desired file?
if (lines.at(isec).file != isrc)
continue;
UINT d = abs((int)lines.at(isec).line - (int)line);
if (d < min_distance) {
min_distance = d;
lineIx = isec;
if (0 == d)
break; // We have found a record for the requested line!
}
}
if (lineIx == (size_t)-1)
return PDFSYNCERR_NORECORD_FOR_THATLINE;
// we read all the consecutive records until we reach a record belonging to another line
for (size_t i = lineIx; i < lines.size() && lines.at(i).line == lines.at(lineIx).line; i++)
records.Push(lines.at(i).record);
return PDFSYNCERR_SUCCESS;
}
示例4: RandomizeFiles
// Select random files to test. We want to test each file type equally, so
// we first group them by file extension and then select up to maxPerType
// for each extension, randomly, and inter-leave the files with different
// extensions, so their testing is evenly distributed.
// Returns result in <files>.
static void RandomizeFiles(WStrVec& files, int maxPerType) {
WStrVec fileExts;
Vec<WStrVec*> filesPerType;
for (size_t i = 0; i < files.size(); i++) {
const WCHAR* file = files.at(i);
const WCHAR* ext = path::GetExt(file);
CrashAlwaysIf(!ext);
int typeNo = fileExts.FindI(ext);
if (-1 == typeNo) {
fileExts.Append(str::Dup(ext));
filesPerType.Append(new WStrVec());
typeNo = (int)filesPerType.size() - 1;
}
filesPerType.at(typeNo)->Append(str::Dup(file));
}
for (size_t j = 0; j < filesPerType.size(); j++) {
WStrVec* all = filesPerType.at(j);
WStrVec* random = new WStrVec();
for (int n = 0; n < maxPerType && all->size() > 0; n++) {
int idx = rand() % all->size();
WCHAR* file = all->at(idx);
random->Append(file);
all->RemoveAtFast(idx);
}
filesPerType.at(j) = random;
delete all;
}
files.Reset();
bool gotAll = false;
while (!gotAll) {
gotAll = true;
for (size_t j = 0; j < filesPerType.size(); j++) {
WStrVec* random = filesPerType.at(j);
if (random->size() > 0) {
gotAll = false;
WCHAR* file = random->at(0);
files.Append(file);
random->RemoveAtFast(0);
}
}
}
for (size_t j = 0; j < filesPerType.size(); j++) {
delete filesPerType.at(j);
}
}
示例5: NextFile
WCHAR* DirFileProvider::NextFile() {
if (filesToOpen.size() > 0) {
return filesToOpen.PopAt(0);
}
if (dirsToVisit.size() > 0) {
// test next directory
AutoFreeW path(dirsToVisit.PopAt(0));
OpenDir(path);
return NextFile();
}
return nullptr;
}
示例6: BenchDir
static void BenchDir(WCHAR* dir) {
WStrVec files;
CollectFilesToBench(dir, files);
for (size_t i = 0; i < files.size(); i++) {
BenchFile(files.at(i), nullptr);
}
}
示例7: FilesProvider
FilesProvider(WStrVec& newFiles, int n, int offset) {
// get every n-th file starting at offset
for (size_t i = offset; i < newFiles.size(); i += n) {
const WCHAR* f = newFiles.at(i);
files.Append(str::Dup(f));
}
provided = 0;
}
示例8: GetAllMatchingFiles
static size_t GetAllMatchingFiles(const WCHAR* dir, const WCHAR* filter, WStrVec& files, bool showProgress) {
WStrVec dirsToVisit;
dirsToVisit.Append(str::Dup(dir));
while (dirsToVisit.size() > 0) {
if (showProgress) {
wprintf(L".");
fflush(stdout);
}
AutoFreeW path(dirsToVisit.PopAt(0));
CollectStressTestSupportedFilesFromDirectory(path, filter, files);
AutoFreeW pattern(str::Format(L"%s\\*", path));
CollectPathsFromDirectory(pattern, dirsToVisit, true);
}
return files.size();
}
示例9: VisitChmIndexItem
/* The html looks like:
<li>
<object type="text/sitemap">
<param name="Keyword" value="- operator">
<param name="Name" value="Subtraction Operator (-)">
<param name="Local" value="html/vsoprsubtract.htm">
<param name="Name" value="Subtraction Operator (-)">
<param name="Local" value="html/js56jsoprsubtract.htm">
</object>
<ul> ... optional children ... </ul>
<li>
... siblings ...
*/
static bool VisitChmIndexItem(EbookTocVisitor* visitor, HtmlElement* el, UINT cp, int level) {
CrashIf(el->tag != Tag_Object || level > 1 && (!el->up || el->up->tag != Tag_Li));
WStrVec references;
AutoFreeW keyword, name;
for (el = el->GetChildByTag(Tag_Param); el; el = el->next) {
if (Tag_Param != el->tag)
continue;
AutoFreeW attrName(el->GetAttribute("name"));
AutoFreeW attrVal(el->GetAttribute("value"));
if (attrName && attrVal && cp != CP_CHM_DEFAULT) {
OwnedData bytes(str::conv::ToCodePage(attrVal, CP_CHM_DEFAULT));
attrVal.Set(str::conv::FromCodePage(bytes.Get(), cp));
}
if (!attrName || !attrVal)
/* ignore incomplete/unneeded <param> */;
else if (str::EqI(attrName, L"Keyword"))
keyword.Set(attrVal.StealData());
else if (str::EqI(attrName, L"Name")) {
name.Set(attrVal.StealData());
// some CHM documents seem to use a lonely Name instead of Keyword
if (!keyword)
keyword.SetCopy(name);
} else if (str::EqI(attrName, L"Local") && name) {
// remove the ITS protocol and any filename references from the URLs
if (str::Find(attrVal, L"::/"))
attrVal.SetCopy(str::Find(attrVal, L"::/") + 3);
references.Append(name.StealData());
references.Append(attrVal.StealData());
}
}
if (!keyword)
return false;
if (references.size() == 2) {
visitor->Visit(keyword, references.at(1), level);
return true;
}
visitor->Visit(keyword, nullptr, level);
for (size_t i = 0; i < references.size(); i += 2) {
visitor->Visit(references.at(i), references.at(i + 1), level + 1);
}
return true;
}
示例10: ParseCommandLine
static void ParseCommandLine(WCHAR* cmdLine) {
WStrVec argList;
ParseCmdLine(cmdLine, argList);
#define is_arg(param) str::EqI(arg + 1, TEXT(param))
#define is_arg_with_param(param) (is_arg(param) && i < argList.size() - 1)
// skip the first arg (exe path)
for (size_t i = 1; i < argList.size(); i++) {
WCHAR* arg = argList.at(i);
if ('-' != *arg && '/' != *arg)
continue;
if (is_arg("s"))
gGlobalData.silent = true;
else if (is_arg_with_param("d"))
str::ReplacePtr(&gGlobalData.installDir, argList.at(++i));
#ifndef BUILD_UNINSTALLER
else if (is_arg("register"))
gGlobalData.registerAsDefault = true;
else if (is_arg_with_param("opt")) {
WCHAR* opts = argList.at(++i);
str::ToLowerInPlace(opts);
str::TransChars(opts, L" ;", L",,");
WStrVec optlist;
optlist.Split(opts, L",", true);
if (optlist.Contains(L"pdffilter"))
gGlobalData.installPdfFilter = true;
if (optlist.Contains(L"pdfpreviewer"))
gGlobalData.installPdfPreviewer = true;
// uninstall the deprecated browser plugin if it's not
// explicitly listed (only applies if the /opt flag is used)
if (!optlist.Contains(L"plugin"))
gGlobalData.keepBrowserPlugin = false;
} else if (is_arg("x")) {
gGlobalData.justExtractFiles = true;
// silently extract files to the current directory (if /d isn't used)
gGlobalData.silent = true;
if (!gGlobalData.installDir)
str::ReplacePtr(&gGlobalData.installDir, L".");
} else if (is_arg("autoupdate")) {
gGlobalData.autoUpdate = true;
}
#endif
else if (is_arg("h") || is_arg("help") || is_arg("?"))
gGlobalData.showUsageAndQuit = true;
#ifdef ENABLE_CRASH_TESTING
else if (is_arg("crash")) {
// will induce crash when 'Install' button is pressed
// for testing crash handling
gForceCrash = true;
}
#endif
}
}
示例11: OpenDir
bool DirFileProvider::OpenDir(const WCHAR* dirPath) {
AssertCrash(filesToOpen.size() == 0);
bool hasFiles = CollectStressTestSupportedFilesFromDirectory(dirPath, fileFilter, filesToOpen);
filesToOpen.SortNatural();
AutoFreeW pattern(str::Format(L"%s\\*", dirPath));
bool hasSubDirs = CollectPathsFromDirectory(pattern, dirsToVisit, true);
return hasFiles || hasSubDirs;
}
示例12: CleanUpThumbnailCache
// removes thumbnails that don't belong to any frequently used item in file history
void CleanUpThumbnailCache(const FileHistory& fileHistory) {
AutoFreeW thumbsPath(AppGenDataFilename(THUMBNAILS_DIR_NAME));
if (!thumbsPath)
return;
AutoFreeW pattern(path::Join(thumbsPath, L"*.png"));
WStrVec files;
WIN32_FIND_DATA fdata;
HANDLE hfind = FindFirstFile(pattern, &fdata);
if (INVALID_HANDLE_VALUE == hfind)
return;
do {
if (!(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
files.Append(str::Dup(fdata.cFileName));
} while (FindNextFile(hfind, &fdata));
FindClose(hfind);
Vec<DisplayState*> list;
fileHistory.GetFrequencyOrder(list);
for (size_t i = 0; i < list.size() && i < FILE_HISTORY_MAX_FREQUENT * 2; i++) {
AutoFreeW bmpPath(GetThumbnailPath(list.at(i)->filePath));
if (!bmpPath)
continue;
int idx = files.Find(path::GetBaseName(bmpPath));
if (idx != -1) {
CrashIf(idx < 0 || files.size() <= (size_t)idx);
free(files.PopAt(idx));
}
}
for (size_t i = 0; i < files.size(); i++) {
AutoFreeW bmpPath(path::Join(thumbsPath, files.at(i)));
file::Delete(bmpPath);
}
}
示例13: CheckInstallUninstallPossible
bool CheckInstallUninstallPossible(bool silent) {
gProcessesToClose.Reset();
ProcessesUsingInstallation(gProcessesToClose);
bool possible = gProcessesToClose.size() == 0;
if (possible) {
SetDefaultMsg();
} else {
SetCloseProcessMsg();
if (!silent)
MessageBeep(MB_ICONEXCLAMATION);
}
InvalidateFrame();
return possible;
}
示例14: BenchFileOrDir
void BenchFileOrDir(WStrVec& pathsToBench) {
gLog = new slog::StderrLogger();
size_t n = pathsToBench.size() / 2;
for (size_t i = 0; i < n; i++) {
WCHAR* path = pathsToBench.at(2 * i);
if (file::Exists(path))
BenchFile(path, pathsToBench.at(2 * i + 1));
else if (dir::Exists(path))
BenchDir(path);
else
logbench(L"Error: file or dir %s doesn't exist", path);
}
delete gLog;
}
示例15: ParsePageRanges
// parses a list of page ranges such as 1,3-5,7- (i..e all but pages 2 and 6)
// into an interable list (returns nullptr on parsing errors)
// caller must delete the result
bool ParsePageRanges(const WCHAR* ranges, Vec<PageRange>& result) {
if (!ranges)
return false;
WStrVec rangeList;
rangeList.Split(ranges, L",", true);
rangeList.SortNatural();
for (size_t i = 0; i < rangeList.size(); i++) {
int start, end;
if (str::Parse(rangeList.at(i), L"%d-%d%$", &start, &end) && 0 < start && start <= end)
result.Append(PageRange(start, end));
else if (str::Parse(rangeList.at(i), L"%d-%$", &start) && 0 < start)
result.Append(PageRange(start, INT_MAX));
else if (str::Parse(rangeList.at(i), L"%d%$", &start) && 0 < start)
result.Append(PageRange(start, start));
else
return false;
}
return result.size() > 0;
}