本文整理汇总了C++中WStrVec::Count方法的典型用法代码示例。如果您正苦于以下问题:C++ WStrVec::Count方法的具体用法?C++ WStrVec::Count怎么用?C++ WStrVec::Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WStrVec
的用法示例。
在下文中一共展示了WStrVec::Count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ViewWithExternalViewer
bool ViewWithExternalViewer(size_t idx, const WCHAR *filePath, int pageNo)
{
if (!HasPermission(Perm_DiskAccess) || !file::Exists(filePath))
return false;
for (size_t i = 0; i < gGlobalPrefs->externalViewers->Count() && i <= idx; i++) {
ExternalViewer *ev = gGlobalPrefs->externalViewers->At(i);
// cf. AppendExternalViewersToMenu in Menu.cpp
if (!ev->commandLine || ev->filter && !str::Eq(ev->filter, L"*") && !(filePath && path::Match(filePath, ev->filter)))
idx++;
}
if (idx >= gGlobalPrefs->externalViewers->Count() || !gGlobalPrefs->externalViewers->At(idx)->commandLine)
return false;
ExternalViewer *ev = gGlobalPrefs->externalViewers->At(idx);
WStrVec args;
ParseCmdLine(ev->commandLine, args, 2);
if (args.Count() == 0 || !file::Exists(args.At(0)))
return false;
// if the command line contains %p, it's replaced with the current page number
// if it contains %1, it's replaced with the file path (else the file path is appended)
const WCHAR *cmdLine = args.Count() > 1 ? args.At(1) : L"\"%1\"";
ScopedMem<WCHAR> pageNoStr(str::Format(L"%d", pageNo));
ScopedMem<WCHAR> params(str::Replace(cmdLine, L"%p", pageNoStr));
if (str::Find(params, L"%1"))
params.Set(str::Replace(params, L"%1", filePath));
else
params.Set(str::Format(L"%s \"%s\"", params.Get(), filePath));
return LaunchFile(args.At(0), params);
}
示例2: LoadImageDir
bool ImageDirEngineImpl::LoadImageDir(const WCHAR *dirName)
{
fileName = str::Dup(dirName);
fileExt = L"";
ScopedMem<WCHAR> pattern(path::Join(dirName, L"*"));
WIN32_FIND_DATA fdata;
HANDLE hfind = FindFirstFile(pattern, &fdata);
if (INVALID_HANDLE_VALUE == hfind)
return false;
do {
if (!(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
if (ImageEngine::IsSupportedFile(fdata.cFileName))
pageFileNames.Append(path::Join(dirName, fdata.cFileName));
}
} while (FindNextFile(hfind, &fdata));
FindClose(hfind);
if (pageFileNames.Count() == 0)
return false;
pageFileNames.SortNatural();
pages.AppendBlanks(pageFileNames.Count());
mediaboxes.AppendBlanks(pageFileNames.Count());
return true;
}
示例3: TesterMain
int TesterMain()
{
RedirectIOToConsole();
WCHAR *cmdLine = GetCommandLine();
WStrVec argv;
ParseCmdLine(cmdLine, argv);
InitAllCommonControls();
ScopedGdiPlus gdi;
mui::Initialize();
WCHAR *dirOrFile = NULL;
bool mobiTest = false;
size_t i = 2; // skip program name and "/tester"
while (i < argv.Count()) {
if (str::Eq(argv[i], L"-mobi")) {
++i;
if (i == argv.Count())
return Usage();
mobiTest = true;
dirOrFile = argv[i];
++i;
} else if (str::Eq(argv[i], L"-layout")) {
gLayout = true;
++i;
} else if (str::Eq(argv[i], L"-save-html")) {
gSaveHtml = true;
++i;
} else if (str::Eq(argv[i], L"-save-images")) {
gSaveImages = true;
++i;
} else if (str::Eq(argv[i], L"-zip-create")) {
ZipCreateTest();
++i;
} else if (str::Eq(argv[i], L"-bench-md5")) {
BenchMD5();
++i;
} else {
// unknown argument
return Usage();
}
}
if (2 == i) {
// no arguments
return Usage();
}
if (mobiTest) {
MobiTest(dirOrFile);
}
mui::Destroy();
system("pause");
return 0;
}
示例4: WStrVecTest
static void WStrVecTest()
{
WStrVec v;
v.Append(str::Dup(L"foo"));
v.Append(str::Dup(L"bar"));
WCHAR *s = v.Join();
utassert(v.Count() == 2);
utassert(str::Eq(L"foobar", s));
free(s);
s = v.Join(L";");
utassert(v.Count() == 2);
utassert(str::Eq(L"foo;bar", s));
free(s);
v.Append(str::Dup(L"glee"));
s = v.Join(L"_ _");
utassert(v.Count() == 3);
utassert(str::Eq(L"foo_ _bar_ _glee", s));
free(s);
v.Sort();
s = v.Join();
utassert(str::Eq(L"barfooglee", s));
free(s);
{
WStrVec v2(v);
utassert(str::Eq(v2.At(1), L"foo"));
v2.Append(str::Dup(L"nobar"));
utassert(str::Eq(v2.At(3), L"nobar"));
v2 = v;
utassert(v2.Count() == 3 && v2.At(0) != v.At(0));
utassert(str::Eq(v2.At(1), L"foo"));
utassert(&v2.At(2) == v2.AtPtr(2) && str::Eq(*v2.AtPtr(2), L"glee"));
}
{
WStrVec v2;
size_t count = v2.Split(L"a,b,,c,", L",");
utassert(count == 5 && v2.Find(L"c") == 3);
utassert(v2.Find(L"") == 2 && v2.Find(L"", 3) == 4 && v2.Find(L"", 5) == -1);
utassert(v2.Find(L"B") == -1 && v2.FindI(L"B") == 1);
ScopedMem<WCHAR> joined(v2.Join(L";"));
utassert(str::Eq(joined, L"a;b;;c;"));
}
{
WStrVec v2;
size_t count = v2.Split(L"a,b,,c,", L",", true);
utassert(count == 3 && v2.Find(L"c") == 2);
ScopedMem<WCHAR> joined(v2.Join(L";"));
utassert(str::Eq(joined, L"a;b;c"));
ScopedMem<WCHAR> last(v2.Pop());
utassert(v2.Count() == 2 && str::Eq(last, L"c"));
}
}
示例5: Execute
virtual void Execute() {
for (size_t i = 0; i < paths.Count(); i++) {
gFileHistory.MarkFileInexistent(paths.At(i), true);
}
// update the Frequently Read page in case it's been displayed already
if (paths.Count() > 0 && gWindows.Count() > 0 && gWindows.At(0)->IsAboutWindow())
gWindows.At(0)->RedrawAll(true);
// prepare for clean-up (Join() just to be safe)
gFileExistenceChecker = NULL;
Join();
}
示例6: 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.Count(); 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.Count() - 1;
}
filesPerType.At(typeNo)->Append(str::Dup(file));
}
for (size_t j = 0; j < filesPerType.Count(); j++) {
WStrVec *all = filesPerType.At(j);
WStrVec *random = new WStrVec();
for (int n = 0; n < maxPerType && all->Count() > 0; n++) {
int idx = rand() % all->Count();
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.Count(); j++) {
WStrVec *random = filesPerType.At(j);
if (random->Count() > 0) {
gotAll = false;
WCHAR *file = random->At(0);
files.Append(file);
random->RemoveAtFast(0);
}
}
}
for (size_t j = 0; j < filesPerType.Count(); j++) {
delete filesPerType.At(j);
}
}
示例7: 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)
{
if (!srcfilename)
return PDFSYNCERR_INVALID_ARGUMENT;
ScopedMem<WCHAR> srcfilepath;
// convert the source file to an absolute path
if (PathIsRelative(srcfilename))
srcfilepath.Set(PrependDir(srcfilename));
else
srcfilepath.Set(str::Dup(srcfilename));
if (!srcfilepath)
return PDFSYNCERR_OUTOFMEMORY;
// find the source file entry
size_t isrc;
for (isrc = 0; isrc < srcfiles.Count(); isrc++)
if (path::IsSame(srcfilepath, srcfiles.At(isrc)))
break;
if (isrc == srcfiles.Count())
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.Count() && lines.At(i).line == lines.At(lineIx).line; i++)
records.Push(lines.At(i).record);
return PDFSYNCERR_SUCCESS;
}
示例8: SetCloseProcessMsg
static void SetCloseProcessMsg()
{
ScopedMem<WCHAR> procNames(str::Dup(ReadableProcName(gProcessesToClose.At(0))));
for (size_t i = 1; i < gProcessesToClose.Count(); i++) {
const WCHAR *name = ReadableProcName(gProcessesToClose.At(i));
if (i < gProcessesToClose.Count() - 1)
procNames.Set(str::Join(procNames, L", ", name));
else
procNames.Set(str::Join(procNames, L" and ", name));
}
ScopedMem<WCHAR> s(str::Format(_TR("Please close %s to proceed!"), procNames));
SetMsg(s, COLOR_MSG_FAILED);
}
示例9: NextFile
WCHAR *DirFileProvider::NextFile()
{
if (filesToOpen.Count() > 0) {
return filesToOpen.PopAt(0);
}
if (dirsToVisit.Count() > 0) {
// test next directory
ScopedMem<WCHAR> path(dirsToVisit.PopAt(0));
OpenDir(path);
return NextFile();
}
return nullptr;
}
示例10: CreateArchive
// creates an archive from files (starting at index skipFiles);
// file paths may be relative to the current directory or absolute and
// may end in a colon followed by the desired path in the archive
// (this is required for absolute paths)
bool CreateArchive(const WCHAR *archivePath, WStrVec& files, size_t skipFiles=0)
{
size_t prevDataLen = 0;
ScopedMem<char> prevData(file::ReadAll(archivePath, &prevDataLen));
lzma::SimpleArchive prevArchive;
if (!lzma::ParseSimpleArchive(prevData, prevDataLen, &prevArchive))
prevArchive.filesCount = 0;
str::Str<char> data;
str::Str<char> content;
ByteWriterLE lzsaHeader(data.AppendBlanks(8), 8);
lzsaHeader.Write32(LZMA_MAGIC_ID);
lzsaHeader.Write32((uint32_t)(files.Count() - skipFiles));
for (size_t i = skipFiles; i < files.Count(); i++) {
ScopedMem<WCHAR> filePath(str::Dup(files.At(i)));
WCHAR *sep = str::FindCharLast(filePath, ':');
ScopedMem<char> utf8Name;
if (sep) {
utf8Name.Set(str::conv::ToUtf8(sep + 1));
*sep = '\0';
}
else {
utf8Name.Set(str::conv::ToUtf8(filePath));
}
str::TransChars(utf8Name, "/", "\\");
if ('/' == *utf8Name || str::Find(utf8Name, "../")) {
fprintf(stderr, "In-archive name must not be an absolute path: %s\n", utf8Name);
return false;
}
int idx = GetIdxFromName(&prevArchive, utf8Name);
lzma::FileInfo *fi = NULL;
if (idx != -1)
fi = &prevArchive.files[idx];
if (!AppendEntry(data, content, filePath, utf8Name, fi))
return false;
}
uint32_t headerCrc32 = crc32(0, (const uint8_t *)data.Get(), (uint32_t)data.Size());
ByteWriterLE(data.AppendBlanks(4), 4).Write32(headerCrc32);
if (!data.AppendChecked(content.Get(), content.Size()))
return false;
return file::WriteAll(archivePath, data.Get(), data.Size());
}
示例11: Visit
// extract ComicBookInfo metadata
// cf. http://code.google.com/p/comicbookinfo/
bool CbxEngineImpl::Visit(const char *path, const char *value, json::DataType type)
{
if (json::Type_String == type && str::Eq(path, "/ComicBookInfo/1.0/title"))
propTitle.Set(str::conv::FromUtf8(value));
else if (json::Type_Number == type && str::Eq(path, "/ComicBookInfo/1.0/publicationYear"))
propDate.Set(str::Format(L"%s/%d", propDate ? propDate : L"", atoi(value)));
else if (json::Type_Number == type && str::Eq(path, "/ComicBookInfo/1.0/publicationMonth"))
propDate.Set(str::Format(L"%d%s", atoi(value), propDate ? propDate : L""));
else if (json::Type_String == type && str::Eq(path, "/appID"))
propCreator.Set(str::conv::FromUtf8(value));
else if (json::Type_String == type && str::Eq(path, "/lastModified"))
propModDate.Set(str::conv::FromUtf8(value));
else if (json::Type_String == type && str::Eq(path, "/X-summary"))
propSummary.Set(str::conv::FromUtf8(value));
else if (str::StartsWith(path, "/ComicBookInfo/1.0/credits[")) {
int idx = -1;
const char *prop = str::Parse(path, "/ComicBookInfo/1.0/credits[%d]/", &idx);
if (prop) {
if (json::Type_String == type && str::Eq(prop, "person"))
propAuthorTmp.Set(str::conv::FromUtf8(value));
else if (json::Type_Bool == type && str::Eq(prop, "primary") &&
propAuthorTmp && propAuthors.Find(propAuthorTmp) == -1) {
propAuthors.Append(propAuthorTmp.StealData());
}
}
return true;
}
// stop parsing once we have all desired information
return !propTitle || propAuthors.Count() == 0 || !propCreator ||
!propDate || str::FindChar(propDate, '/') <= propDate;
}
示例12: 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;
ScopedMem<WCHAR> keyword, name;
for (el = el->GetChildByTag(Tag_Param); el; el = el->next) {
if (Tag_Param != el->tag)
continue;
ScopedMem<WCHAR> attrName(el->GetAttribute("name"));
ScopedMem<WCHAR> attrVal(el->GetAttribute("value"));
if (attrName && attrVal && cp != CP_CHM_DEFAULT) {
ScopedMem<char> bytes(str::conv::ToCodePage(attrVal, CP_CHM_DEFAULT));
attrVal.Set(str::conv::FromCodePage(bytes, 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.Set(str::Dup(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.Set(str::Dup(str::Find(attrVal, L"::/") + 3));
references.Append(name.StealData());
references.Append(attrVal.StealData());
}
}
if (!keyword)
return false;
if (references.Count() == 2) {
visitor->Visit(keyword, references.At(1), level);
return true;
}
visitor->Visit(keyword, NULL, level);
for (size_t i = 0; i < references.Count(); i += 2) {
visitor->Visit(references.At(i), references.At(i + 1), level + 1);
}
return true;
}
示例13: FilesProvider
FilesProvider(WStrVec& newFiles, int n, int offset) {
// get every n-th file starting at offset
for (size_t i = offset; i < newFiles.Count(); i += n) {
const WCHAR *f = newFiles.At(i);
files.Append(str::Dup(f));
}
provided = 0;
}
示例14: BenchDir
static void BenchDir(WCHAR *dir)
{
WStrVec files;
CollectFilesToBench(dir, files);
for (size_t i = 0; i < files.Count(); i++) {
BenchFile(files.At(i), nullptr);
}
}
示例15: 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.Count() - 1)
// skip the first arg (exe path)
for (size_t i = 1; i < argList.Count(); 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::ToLower(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
}
}