本文整理汇总了C++中StrVec::Count方法的典型用法代码示例。如果您正苦于以下问题:C++ StrVec::Count方法的具体用法?C++ StrVec::Count怎么用?C++ StrVec::Count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StrVec
的用法示例。
在下文中一共展示了StrVec::Count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GoToNextFile
bool StressTest::GoToNextFile()
{
for (;;) {
while (filesToOpen.Count() > 0) {
// test next file
ScopedMem<TCHAR> path(filesToOpen.At(0));
filesToOpen.RemoveAt(0);
if (!IsInRange(fileRanges, ++fileIndex))
continue;
if (OpenFile(path))
return true;
}
if (dirsToVisit.Count() > 0) {
// test next directory
ScopedMem<TCHAR> path(dirsToVisit.At(0));
dirsToVisit.RemoveAt(0);
OpenDir(path);
continue;
}
if (--cycles <= 0)
return false;
// start next cycle
if (file::Exists(basePath))
filesToOpen.Append(str::Dup(basePath));
else
OpenDir(basePath);
}
}
示例2: LoadImageDir
bool ImageDirEngineImpl::LoadImageDir(const TCHAR *dirName)
{
fileName = str::Dup(dirName);
fileExt = _T("");
ScopedMem<TCHAR> pattern(path::Join(dirName, _T("*")));
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: StrVecTest
static void StrVecTest()
{
StrVec v;
v.Append(str::Dup(_T("foo")));
v.Append(str::Dup(_T("bar")));
TCHAR *s = v.Join();
assert(v.Count() == 2);
assert(str::Eq(_T("foobar"), s));
free(s);
s = v.Join(_T(";"));
assert(v.Count() == 2);
assert(str::Eq(_T("foo;bar"), s));
free(s);
v.Append(str::Dup(_T("glee")));
s = v.Join(_T("_ _"));
assert(v.Count() == 3);
assert(str::Eq(_T("foo_ _bar_ _glee"), s));
free(s);
v.Sort();
s = v.Join();
assert(str::Eq(_T("barfooglee"), s));
free(s);
{
StrVec v2(v);
assert(str::Eq(v2.At(1), _T("foo")));
v2.Append(str::Dup(_T("nobar")));
assert(str::Eq(v2.At(3), _T("nobar")));
v2 = v;
assert(v2.Count() == 3 && v2.At(0) != v.At(0));
assert(str::Eq(v2.At(1), _T("foo")));
assert(&v2.At(2) == v2.AtPtr(2) && str::Eq(*v2.AtPtr(2), _T("glee")));
}
{
StrVec v2;
size_t count = v2.Split(_T("a,b,,c,"), _T(","));
assert(count == 5 && v2.Find(_T("c")) == 3);
assert(v2.Find(_T("")) == 2 && v2.Find(_T(""), 3) == 4 && v2.Find(_T(""), 5) == -1);
assert(v2.Find(_T("B")) == -1 && v2.FindI(_T("B")) == 1);
ScopedMem<TCHAR> joined(v2.Join(_T(";")));
assert(str::Eq(joined, _T("a;b;;c;")));
}
{
StrVec v2;
size_t count = v2.Split(_T("a,b,,c,"), _T(","), true);
assert(count == 3 && v2.Find(_T("c")) == 2);
ScopedMem<TCHAR> joined(v2.Join(_T(";")));
assert(str::Eq(joined, _T("a;b;c")));
ScopedMem<TCHAR> last(v2.Pop());
assert(v2.Count() == 2 && str::Eq(last, _T("c")));
}
}
示例4: 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 TCHAR* srcfilename, UINT line, UINT col, Vec<size_t> &records)
{
if (!srcfilename)
return PDFSYNCERR_INVALID_ARGUMENT;
ScopedMem<TCHAR> 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;
}
示例5: 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->NameIs("li"));
el = el->GetChildByName("object");
if (!el)
return false;
StrVec references;
ScopedMem<TCHAR> keyword, name;
for (el = el->GetChildByName("param"); el; el = el->next) {
if (!el->NameIs("param"))
continue;
ScopedMem<TCHAR> attrName(el->GetAttribute("name"));
ScopedMem<TCHAR> attrVal(el->GetAttribute("value"));
#ifdef UNICODE
if (attrName && attrVal && cp != CP_CHM_DEFAULT) {
ScopedMem<char> bytes(str::conv::ToCodePage(attrVal, CP_CHM_DEFAULT));
attrVal.Set(str::conv::FromCodePage(bytes, cp));
}
#endif
if (!attrName || !attrVal)
/* ignore incomplete/unneeded <param> */;
else if (str::EqI(attrName, _T("Keyword")))
keyword.Set(attrVal.StealData());
else if (str::EqI(attrName, _T("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, _T("Local")) && name) {
// remove the ITS protocol and any filename references from the URLs
if (str::Find(attrVal, _T("::/")))
attrVal.Set(str::Dup(str::Find(attrVal, _T("::/")) + 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;
}
示例6: observe
// extract ComicBookInfo metadata
// cf. http://code.google.com/p/comicbookinfo/
bool CbxEngineImpl::observe(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(_T("%s/%d"), propDate ? propDate : _T(""), atoi(value)));
else if (json::Type_Number == type && str::Eq(path, "/ComicBookInfo/1.0/publicationMonth"))
propDate.Set(str::Format(_T("%d%s"), atoi(value), propDate ? propDate : _T("")));
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;
}
示例7: BenchDir
static void BenchDir(TCHAR *dir)
{
StrVec files;
ScopedMem<TCHAR> pattern(str::Format(_T("%s\\*.pdf"), dir));
CollectPathsFromDirectory(pattern, files, false);
for (size_t i = 0; i < files.Count(); i++) {
BenchFile(files.At(i), NULL);
}
}
示例8: OpenDir
bool StressTest::OpenDir(const TCHAR *dirPath)
{
assert(filesToOpen.Count() == 0);
bool hasFiles = CollectStressTestSupportedFilesFromDirectory(dirPath, fileFilter, filesToOpen);
filesToOpen.SortNatural();
ScopedMem<TCHAR> pattern(str::Format(_T("%s\\*"), dirPath));
bool hasSubDirs = CollectPathsFromDirectory(pattern, dirsToVisit, true);
return hasFiles || hasSubDirs;
}
示例9: GetPageByLabel
int ImageDirEngineImpl::GetPageByLabel(const TCHAR *label)
{
for (size_t i = 0; i < pageFileNames.Count(); i++) {
const TCHAR *fileName = path::GetBaseName(pageFileNames.At(i));
const TCHAR *fileExt = path::GetExt(fileName);
if (str::StartsWithI(fileName, label) &&
(fileName + str::Len(label) == fileExt || fileName[str::Len(label)] == '\0'))
return (int)i + 1;
}
return BaseEngine::GetPageByLabel(label);
}
示例10: SetupPluginMode
static bool SetupPluginMode(CommandLineInfo& i)
{
if (!IsWindow(i.hwndPluginParent) || i.fileNames.Count() == 0)
return false;
gPluginURL = i.pluginURL;
if (!gPluginURL)
gPluginURL = i.fileNames.At(0);
assert(i.fileNames.Count() == 1);
while (i.fileNames.Count() > 1) {
free(i.fileNames.Pop());
}
i.reuseInstance = i.exitOnPrint = false;
// always display the toolbar when embedded (as there's no menubar in that case)
gGlobalPrefs.toolbarVisible = true;
// never allow esc as a shortcut to quit
gGlobalPrefs.escToExit = false;
// never show the sidebar by default
gGlobalPrefs.tocVisible = false;
if (DM_AUTOMATIC == gGlobalPrefs.defaultDisplayMode) {
// if the user hasn't changed the default display mode,
// display documents as single page/continuous/fit width
// (similar to Adobe Reader, Google Chrome and how browsers display HTML)
gGlobalPrefs.defaultDisplayMode = DM_CONTINUOUS;
gGlobalPrefs.defaultZoom = ZOOM_FIT_WIDTH;
}
// extract some command line arguments from the URL's hash fragment where available
// see http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf#nameddest=G4.1501531
if (i.pluginURL && str::FindChar(i.pluginURL, '#')) {
ScopedMem<TCHAR> args(str::Dup(str::FindChar(i.pluginURL, '#') + 1));
str::TransChars(args, _T("#"), _T("&"));
StrVec parts;
parts.Split(args, _T("&"), true);
for (size_t k = 0; k < parts.Count(); k++) {
TCHAR *part = parts.At(k);
int pageNo;
if (str::StartsWithI(part, _T("page=")) && str::Parse(part + 4, _T("=%d%$"), &pageNo))
i.pageNumber = pageNo;
else if (str::StartsWithI(part, _T("nameddest=")) && part[10])
str::ReplacePtr(&i.destName, part + 10);
else if (!str::FindChar(part, '=') && part[0])
str::ReplacePtr(&i.destName, part);
}
}
return true;
}
示例11: BenchFileOrDir
void BenchFileOrDir(StrVec& pathsToBench)
{
gLog = new slog::StderrLogger();
size_t n = pathsToBench.Count() / 2;
for (size_t i = 0; i < n; i++) {
TCHAR *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("Error: file or dir %s doesn't exist", path);
}
delete gLog;
}
示例12: switch
TCHAR *CbxEngineImpl::GetProperty(DocumentProperty prop)
{
switch (prop) {
case Prop_Title:
return propTitle ? str::Dup(propTitle) : NULL;
case Prop_Author:
return propAuthors.Count() ? propAuthors.Join(_T(", ")) : NULL;
case Prop_CreationDate:
return propDate ? str::Dup(propDate) : NULL;
case Prop_ModificationDate:
return propModDate ? str::Dup(propModDate) : NULL;
case Prop_CreatorApp:
return propCreator ? str::Dup(propCreator) : NULL;
// TODO: replace with Prop_Summary
case Prop_Subject:
return propSummary ? str::Dup(propSummary) : NULL;
default:
return NULL;
}
}
示例13: CollectStressTestSupportedFilesFromDirectory
static bool CollectStressTestSupportedFilesFromDirectory(const TCHAR *dirPath, const TCHAR *filter, StrVec& paths)
{
ScopedMem<TCHAR> pattern(path::Join(dirPath, _T("*")));
WIN32_FIND_DATA fdata;
HANDLE hfind = FindFirstFile(pattern, &fdata);
if (INVALID_HANDLE_VALUE == hfind)
return false;
do {
if (!(fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
if (IsStressTestSupportedFile(fdata.cFileName, filter)) {
paths.Append(path::Join(dirPath, fdata.cFileName));
}
}
} while (FindNextFile(hfind, &fdata));
FindClose(hfind);
return paths.Count() > 0;
}
示例14: CollectPathsFromDirectory
bool CollectPathsFromDirectory(const TCHAR *pattern, StrVec& paths, bool dirsInsteadOfFiles)
{
ScopedMem<TCHAR> dirPath(path::GetDir(pattern));
WIN32_FIND_DATA fdata;
HANDLE hfind = FindFirstFile(pattern, &fdata);
if (INVALID_HANDLE_VALUE == hfind)
return false;
do {
bool append = !dirsInsteadOfFiles;
if ((fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
append = dirsInsteadOfFiles && !IsSpecialDir(fdata.cFileName);
if (append)
paths.Append(path::Join(dirPath, fdata.cFileName));
} while (FindNextFile(hfind, &fdata));
FindClose(hfind);
return paths.Count() > 0;
}
示例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 NULL on parsing errors)
// caller must delete the result
static bool ParsePageRanges(const TCHAR *ranges, Vec<PageRange>& result)
{
if (!ranges)
return false;
StrVec rangeList;
rangeList.Split(ranges, _T(","), true);
rangeList.SortNatural();
for (size_t i = 0; i < rangeList.Count(); i++) {
int start, end;
if (str::Parse(rangeList.At(i), _T("%d-%d%$"), &start, &end) && 0 < start && start <= end)
result.Append(PageRange(start, end));
else if (str::Parse(rangeList.At(i), _T("%d-%$"), &start) && 0 < start)
result.Append(PageRange(start, INT_MAX));
else if (str::Parse(rangeList.At(i), _T("%d%$"), &start) && 0 < start)
result.Append(PageRange(start, start));
else
return false;
}
return result.Count() > 0;
}