本文整理汇总了C++中CPVRTString::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ CPVRTString::substr方法的具体用法?C++ CPVRTString::substr怎么用?C++ CPVRTString::substr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CPVRTString
的用法示例。
在下文中一共展示了CPVRTString::substr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PVRTStringGetContainingDirectoryPath
/*!***********************************************************************
@Function PVRTStringGetContainingDirectoryPath
@Input strFilePath A string
@Returns Directory
@Description Extracts the directory portion from a file path.
************************************************************************/
CPVRTString PVRTStringGetContainingDirectoryPath(const CPVRTString& strFilePath)
{
size_t i32sep = strFilePath.find_last_of('/');
if(i32sep == strFilePath.npos)
{
i32sep = strFilePath.find_last_of('\\');
if(i32sep == strFilePath.npos)
{ // can't find an actual \ or / so leave it be
return strFilePath;
}
}
return strFilePath.substr(0,i32sep);
}
示例2: PVRTStringGetFileName
/*!***********************************************************************
@Function PVRTStringGetFileName
@Input strFilePath A string
@Returns FileName
@Description Extracts the name and extension portion from a file path.
************************************************************************/
CPVRTString PVRTStringGetFileName(const CPVRTString& strFilePath)
{
size_t i32sep = strFilePath.find_last_of('/');
if(i32sep == strFilePath.npos)
{
i32sep = strFilePath.find_last_of('\\');
if(i32sep == strFilePath.npos)
{ // can't find an actual \ or / so leave it be
return strFilePath;
}
}
return strFilePath.substr(i32sep+1,strFilePath.length());
}
示例3: Parse
PVRES PVRESParser::Parse()
{
if(m_bScriptFileSpecified)
{ // file has been specified
// read script file; seriously unsubtle atm
FILE *file = fopen(m_pcPVRES->getScriptFileName().c_str(),"rb");
if(!file)
{
m_strError = CPVRTString("Couldn't open file.");
return *m_pcPVRES;
}
// obtain file size:
fseek (file , 0 , SEEK_END);
long lSize = ftell(file);
fclose(file); // some OSs don't understand rewind
file = fopen(m_pcPVRES->getScriptFileName().c_str(), "rb");
if(!lSize)
{
m_strError = CPVRTString("File is empty.");
return *m_pcPVRES;
}
// Allocate an array large enough
char* allData = new char[lSize+1];
if(!allData)
{
m_strError = CPVRTString("Couldn't allocate memory for reading script.");
return *m_pcPVRES;
}
fread(allData,1,lSize,file);
fclose(file);
allData[lSize]='0'; // terminate the file properly
m_strScript = CPVRTString(allData);
PVRDELETEARRAY(allData);
}
else
{
return *m_pcPVRES; //use default PVRES that should outlive the PVRESParser class
}
// parse the script file
CPVRTString strLine;
char cBool;
int i32Int;
// TODO: do this in a slightly less pre-school way
while(getline(m_strScript, strLine, '\n'))
{
if (strLine.substr(0,strlen("fullscreen:")).compare("fullscreen:")==0)
{
sscanf(strLine.c_str(),"fullscreen:%c", &cBool);
m_pcPVRES->setFullScreen(cBool=='Y' || cBool=='y');
}
else if (strLine.substr(0,strlen("title:")).compare("title:")==0)
{
m_pcPVRES->setTitle(strLine.substr(6));
}
else if (strLine.substr(0,strlen("pod:")).compare("pod:")==0)
{
m_pcPVRES->setPODFileName(strLine.substr(4));
}
else if (strLine.substr(0,strlen("startframe:")).compare("startframe:")==0)
{
CPVRTString strTemp = (strLine.substr(11));
char* pszTemp = new char[strTemp.size()+1];
sprintf(pszTemp,"%s",strTemp.c_str());
m_pcPVRES->setStartFrame((float)atof(pszTemp));
PVRDELETEARRAY(pszTemp);
}
else if (strLine.substr(0,strlen("showfps:")).compare("showfps:")==0)
{
sscanf(strLine.c_str(),"showfps:%c", &cBool);
m_pcPVRES->setShowFPS(cBool=='Y' || cBool=='y');
}
else if (strLine.substr(0,strlen("animspeed:")).compare("animspeed:")==0)
{
float fAnimationSpeed;
sscanf(strLine.c_str(),"animspeed:%f", &fAnimationSpeed);
m_pcPVRES->setAnimationSpeed(fAnimationSpeed);
}
else if (strLine.substr(0,strlen("vertsync:")).compare("vertsync:")==0)
{
sscanf(strLine.c_str(),"vertsync:%c", &cBool);
m_pcPVRES->setVertSync(cBool=='Y' || cBool=='y');
}
else if (strLine.substr(0,strlen("logtofile:")).compare("logtofile:")==0)
{
sscanf(strLine.c_str(),"logtofile:%c", &cBool);
m_pcPVRES->setLogToFile(cBool=='Y' || cBool=='y');
}
else if (strLine.substr(0,strlen("powersaving:")).compare("powersaving:")==0)
{
sscanf(strLine.c_str(),"powersaving:%c", &cBool);
//.........这里部分代码省略.........