예제 #1
0
int MonitorThread::ParserExpression(CString strExpression, CStringList &lstOperator, CStringList &lstID)
{
	if(strExpression.IsEmpty())
		return -1;

	CString strTemp="";

	int pos=0;
	int nb=0;
	int n=0;
	if((pos=strExpression.Find(SEPARATOR,0))<0)
	{
	//	lstID.AddTail(strExpression);
		lstID.push_back(strExpression.getText());
		return 0;
	}

	for(nb=0;pos>-1;nb++)
	{
		strTemp=strExpression.Mid(nb,pos-nb);
//		lstID.AddTail(strTemp);
		lstID.push_back(strTemp.getText());
		pos++;
		nb=strExpression.Find(SEPARATOR,pos);
		if(nb<0)
			return -2;
		strTemp=strExpression.Mid(pos,nb-pos);
//		lstOperator.AddTail(strTemp);
		lstOperator.push_back(strTemp.getText());
		pos=strExpression.Find(SEPARATOR,nb+1);
		n++;
	}

//	lstID.AddTail(strExpression.Right(strExpression.GetLength()-strExpression.ReverseFind(SEPARATOR)-1));
	lstID.push_back(strExpression.Right(strExpression.GetLength()-strExpression.ReverseFind(SEPARATOR)-1).getText());

	return n;

}
예제 #2
0
static
void
tokenize(CStringList& tokens, const CString& src)
{
	// find first non-whitespace
	CString::size_type x = src.find_first_not_of(" \t\r\n");
	if (x == CString::npos) {
		return;
	}

	// find next whitespace
	do {
		CString::size_type y = src.find_first_of(" \t\r\n", x);
		if (y == CString::npos) {
			y = src.size();
		}
		tokens.push_back(src.substr(x, y - x));
		x = src.find_first_not_of(" \t\r\n", y);
	} while (x != CString::npos);
}
예제 #3
0
파일: STLUtil.cpp 프로젝트: Arkshine/NS
// Pass in relative path, do search on path including mod directory, return files relative to mod directory
bool BuildFileList(const string& inBaseDirectoryName, const string& inDirectoryName, const string& inFileExtension, CStringList& outList)
{
#ifdef WIN32
    const string kDelimiter("\\");
#else
    const string kDelimiter("/");
#endif

    bool theSuccess = false;

    string theBaseDirectoryName = inBaseDirectoryName;
    string theDirectoryName = inDirectoryName;

#ifdef WIN32
    // Replace all forward slashes with \\'s if needed
    std::replace(theBaseDirectoryName.begin(), theBaseDirectoryName.end(), '/', '\\');
    std::replace(theDirectoryName.begin(), theDirectoryName.end(), '/', '\\');
#endif

    string theFullDirName = theBaseDirectoryName + theDirectoryName;

    size_t theEndOffset = theDirectoryName.find_last_of(kDelimiter);
    string theBaseDirName = theDirectoryName.substr(0, theEndOffset);

    theFullDirName += inFileExtension;

#ifdef WIN32
    WIN32_FIND_DATA		theFindData;
    HANDLE				theFileHandle;

    theFileHandle = FindFirstFile(theFullDirName.c_str(), &theFindData);
    if (theFileHandle != INVALID_HANDLE_VALUE)
    {
        do
        {
            string theFoundFilename = string(theFindData.cFileName);


#else

    string theFoundFilename;
    FIND_DATA theFindData;

    const char* theFullDirNameCStr = theFullDirName.c_str();
    int theRC = FindFirstFile(theFullDirNameCStr, &theFindData);
    if(theRC != -1)
    {
        do
        {
            string theFoundFilename = string(theFindData.cFileName);
#endif
            CString theCString;
            string theFullFileName = theBaseDirName + string("/") + theFoundFilename;

            // Precache requires / in the filename
            std::replace(theFullFileName.begin(), theFullFileName.end(), '\\', '/');

            theCString = theFullFileName;
            outList.push_back(theCString);
            theSuccess = true;
#ifdef WIN32
        }
        while(FindNextFile(theFileHandle, &theFindData));
    }
#else
        }
        while(FindNextFile(0, &theFindData));
    }
#endif

    //DIR theDirp = opendir(theDirName.c_str());
    //	while(theDirp)
    //	{
    //		int theErrno = 0;
    //		     if ((dp = readdir(theDirp)) != NULL) {
    //			         if (strcmp(dp->d_name, name) == 0) {
    //				             closedir(theDirp);
    //				             return FOUND;
    //				         }
    //			     } else {
    //				         if (theErrno == 0) {
    //					             closedir(theDirp);
    //					             return NOT_FOUND;
    //					         }
    //				         closedir(theDirp);
    //				         return READ_ERROR;
    //				     }
    //			 }
    //	return OPEN_ERROR;

    return theSuccess;
}