Beispiel #1
0
// get first next word or quoted string
CTString GetNextParam(void)
{
    // strip leading spaces/tabs
    _strCmd.TrimSpacesLeft();
    // if nothing left
    if (_strCmd=="") {
        // no word to return
        return "";
    }

    // if the first char is quote
    if (_strCmd[0]=='"') {
        // find first next quote
        const char* pCmd = _strCmd;
        char *pchClosingQuote = strchr((char*)pCmd+1, '"');
        // if not found
        if (pchClosingQuote==NULL) {
            // error in command line
            cmd_strOutput+=CTString(0, TRANS("Command line error!\n"));
            // finish parsing
            _strCmd = "";
            return "";
        }
        INDEX iQuote = pchClosingQuote-_strCmd;

        // get the quoted string
        CTString strWord;
        CTString strRest;
        _strCmd.Split(iQuote, strWord, strRest);
        // remove the quotes
        strWord.DeleteChar(0);
        strRest.DeleteChar(0);
        // get the word
        _strCmd = strRest;
        return strWord;

        // if the first char is not quote
    } else {
        // find first next space
        INDEX iSpace;
        INDEX ctChars = strlen(_strCmd);
        for(iSpace=0; iSpace<ctChars; iSpace++) {
            if (isspace(_strCmd[iSpace])) {
                break;
            }
        }
        // get the word string
        CTString strWord;
        CTString strRest;
        _strCmd.Split(iSpace, strWord, strRest);
        // remove the space
        strRest.DeleteChar(0);
        // get the word
        _strCmd = strRest;
        return strWord;
    }
}
Beispiel #2
0
void StringSplit(std::vector<CTString>& vecOutput, CTString strInput, ULONG ulColumnWidth)
{
	CDrawPort* pDrawPort = CUIManager::getSingleton()->GetDrawPort();

	ULONG ulWidth = 0;
#if defined(G_RUSSIA)
	ulWidth = UTIL_HELP()->GetNoFixedWidth(_pfdDefaultFont, strInput.str_String);
#else	//	defined(G_RUSSIA)
	ulWidth = pDrawPort->GetTextWidth2(strInput);
#endif	//	defined(G_RUSSIA)
	
	if (ulWidth <= ulColumnWidth)
	{
		strInput.TrimSpacesLeft();
		strInput.TrimSpacesRight();
		vecOutput.push_back(strInput);
		return;
	}
	
	char szTemp[4];
	int len = strInput.Length(), pos = 0;
	ulWidth = 0;
	for (int i = 0, j = 0; i < len; j = 0)
	{
		if (IsDBCSLeadByte(strInput[i]))
			szTemp[j++] = strInput[i++];
		szTemp[j++] = strInput[i++];
		szTemp[j] = 0;
		ULONG ulTempWidth = 0;
#if defined(G_RUSSIA)
		ulTempWidth = UTIL_HELP()->GetNoFixedWidth(_pfdDefaultFont, szTemp);
#else	//	defined(G_RUSSIA)
		ulTempWidth = pDrawPort->GetTextWidth2(szTemp);
#endif	//	defined(G_RUSSIA)
		if (ulWidth + ulTempWidth > ulColumnWidth &&
			!(j == 1 && (szTemp[0] == '.' || szTemp[0] == ',' || szTemp[0] == ' ')))
			break;

		pos = i;
		ulWidth += ulTempWidth;
		if( strInput[pos] == '\n' || strInput[pos] == '\r' )
		{
			pos++;
			break;
		}	
	}
	CTString strLeft, strRight;
	strInput.Split(pos, strLeft, strRight);
	strLeft.TrimSpacesLeft();
	strLeft.TrimSpacesRight();
	vecOutput.push_back(strLeft);

	if (strRight.Length() > 0)
		StringSplit(vecOutput, strRight, ulColumnWidth);
}
Beispiel #3
0
// load a filelist
static BOOL LoadFileList(CDynamicStackArray<CTFileName> &afnm, const CTFileName &fnmList)
{
  afnm.PopAll();
  try {
    CTFileStream strm;
    strm.Open_t(fnmList);
    while(!strm.AtEOF()) {
      CTString strLine;
      strm.GetLine_t(strLine);
      strLine.TrimSpacesLeft();
      strLine.TrimSpacesRight();
      if (strLine!="") {
        afnm.Push() = strLine;
      }
    }
    return TRUE;
  } catch(char *strError) {
    CPrintF("%s\n", strError);
    return FALSE;
  }
}