本文整理汇总了C++中PString::ReverseFind方法的典型用法代码示例。如果您正苦于以下问题:C++ PString::ReverseFind方法的具体用法?C++ PString::ReverseFind怎么用?C++ PString::ReverseFind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PString
的用法示例。
在下文中一共展示了PString::ReverseFind方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PositionToEntry
bool SIDStil::PositionToEntry(PString entryStr, PFile *inFile, PList<DirList *> &dirs)
{
DirList *item = NULL;
int32 slashIndex;
int32 startPos;
int32 i, count;
int32 pathLen, entryStrLen;
PString line;
bool foundIt = false;
bool globComm = false;
bool temp;
PCharSet_MS_WIN_1252 charSet;
try
{
// Seek to the start of the file
inFile->SeekToBegin();
// Get the dirpath
slashIndex = entryStr.ReverseFind('/');
// If no slash was found, something is screwed up in the entryStr
if (slashIndex == -1)
return (false);
pathLen = slashIndex + 1;
// Determine whether a section-global comment is asked for
entryStrLen = entryStr.GetLength();
if (pathLen == entryStrLen)
globComm = true;
// Find it in the table
count = dirs.CountItems();
for (i = 0; i < count; i++)
{
item = dirs.GetItem(i);
if (entryStr.Left(pathLen) == item->dirName)
{
foundIt = true;
break;
}
}
if (!foundIt)
{
// The directory was not found
return (false);
}
// Jump to the first entry of this section
inFile->Seek(item->position, PFile::pSeekBegin);
foundIt = false;
// Now find the desired entry
do
{
startPos = inFile->GetPosition();
line = inFile->ReadLine(&charSet);
if (inFile->IsEOF())
break;
// Check if it is the start of an entry
if (!line.IsEmpty() && (line.GetAt(0) == '/'))
{
if (line.Left(pathLen) != item->dirName)
{
// We are outside the section - get out of the loop,
// which will fail the search
break;
}
// Check whether we need to find a section-global comment or
// a specific entry
if (globComm || (stilVersion > 2.59f))
temp = (line == entryStr);
else
{
// To be compatible with older versions of STIL, which may have
// the tune designation on the first line of a STIL entry
// together with the pathname
temp = (line.Left(entryStrLen) == entryStr);
}
if (temp)
{
// Found it!
foundIt = true;
}
}
}
while (!foundIt);
if (foundIt)
{
// Reposition the file pointer back to the start of the entry
inFile->Seek(startPos, PFile::pSeekBegin);
return (true);
}
//.........这里部分代码省略.........
示例2: GetGlobalComment
PString SIDStil::GetGlobalComment(PString relPathToEntry)
{
PString dir;
int32 lastSlash, pathLen;
int32 temp;
if (baseDir.IsEmpty())
return ("");
// Save the dirpath
lastSlash = relPathToEntry.ReverseFind('/');
if (lastSlash == -1)
return ("");
pathLen = lastSlash + 1;
dir = relPathToEntry.Left(pathLen);
// Find out whether we have this global comment in the buffer.
// If the baseDir was changed, we'll have to read it in again,
// even if it might be in the buffer already
if ((globalBuf.Left(dir.GetLength()) != dir) || ((globalBuf.Find('\n') != pathLen) && (stilVersion > 2.59f)))
{
// The relative pathnames don't match or they're not the same length:
// We don't have it in the buffer, so pull it in
try
{
PDirectory tempDir;
tempDir.SetDirectory(baseDir);
tempDir.Append("DOCUMENTS");
stilFile->Open(tempDir.GetDirectory() + "STIL.txt", PFile::pModeRead | PFile::pModeShareRead);
if (PositionToEntry(dir, stilFile, stilDirs) == false)
{
// Copy the dirname to the buffer
globalBuf = dir + "\n";
}
else
{
globalBuf.MakeEmpty();
ReadEntry(stilFile, globalBuf);
}
stilFile->Close();
}
catch(PFileException e)
{
// Failed reading from the STIL.txt file
stilFile->Close();
return ("");
}
}
// Position the index to the global comment field
temp = globalBuf.Find('\n');
temp++;
// Check whether this is a NULL entry or not
if (temp == globalBuf.GetLength())
return ("");
return (globalBuf.Mid(temp));
}