Beispiel #1
0
bool isGoodDecomp(wchar32 rune, wchar32 decomp){
    if (
           (NUnicode::NPrivate::CharInfo(rune) == NUnicode::NPrivate::CharInfo(decomp))
        || (IsAlpha(rune) && IsAlpha(decomp))
        || (IsNumeric(rune) && IsNumeric(decomp))
        || (IsQuotation(rune) && IsQuotation(decomp))
       )
    {
        return true;
    }
    return false;
}
Beispiel #2
0
BOOL CSZCommandLine::Analyze(LPCTSTR lpszCmdLine)
{
    BOOL    bResult = FALSE;
    int     nParamNamePos  = 0;
    int     nParamValuePos = 0;
    int     nSubCommandPos = 0;
    CString strParamName;
    CString strSubCommand;

    BOOL    bInQuotation   = FALSE;

    EM_CMDLINE_STATUS nStatus = em_Cmd_New_Arg;

    m_mapParams.RemoveAll();

    if (!lpszCmdLine)
        goto Exit0;

    for (int nPos = 0; 0 == nPos || lpszCmdLine[nPos - 1]; ++nPos)
    {
        TCHAR ch = lpszCmdLine[nPos];
        switch (nStatus)
        {
        case em_Cmd_New_Arg:
            bInQuotation = FALSE;
            // no break;

        case em_Cmd_White_Space:

            if (IsWhiteSpace(ch))
            {
                nStatus = em_Cmd_White_Space;
            }
            else if (IsArgNamePrefix(ch))
            {
                nStatus = em_Cmd_Arg_Name_Prefix;
            }
            else if (IsAlpha(ch))
            {   // skip sub command
                nSubCommandPos  = nPos;
                nStatus         = em_Cmd_Sub_Command;
            }
            else if (IsQuotation(ch))
            {
                bInQuotation = TRUE;
                nStatus = em_Cmd_White_Space;
            }
            else
            {
                goto Exit0;
            }

            break;

        case em_Cmd_Sub_Command:

            if (IsWhiteSpace(ch))
            {
                strSubCommand.SetString(lpszCmdLine + nSubCommandPos, nPos - nSubCommandPos);
                AppendSubCommand(strSubCommand);
                nStatus = em_Cmd_New_Arg;
            }
            else if (IsAlpha(ch))
            {   // skip sub command
                nStatus = em_Cmd_Sub_Command;
            }
            else if (IsQuotation(ch))
            {
                strSubCommand.SetString(lpszCmdLine + nSubCommandPos, nPos - nSubCommandPos);
                AppendSubCommand(strSubCommand);
                nStatus = em_Cmd_New_Arg;
            }
            else
            {
                goto Exit0;
            }

            break;

        case em_Cmd_Arg_Name_Prefix:

            if (IsWhiteSpace(ch))
            {
                goto Exit0;
            }
            else if (IsArgNamePrefix(ch))
            {   // Á¬ÐøµÄǰ׺
                nStatus = em_Cmd_Arg_Name_Prefix;
            }
            else
            {
                nParamNamePos = nPos;
                nStatus = em_Cmd_Arg_Name;
            }

            break;

        case em_Cmd_Arg_Name:

            if (IsWhiteSpace(ch))
            {
                strParamName.SetString(lpszCmdLine + nParamNamePos, nPos - nParamNamePos);
                SetParam(strParamName, _T(""));
                nStatus = em_Cmd_New_Arg;
            }
            else if (IsArgValuePrefix(ch))
            {
                strParamName.SetString(lpszCmdLine + nParamNamePos, nPos - nParamNamePos);
                nStatus = em_Cmd_Arg_Value_Prefix;
            }
            else if (IsQuotation(ch))
            {
                strParamName.SetString(lpszCmdLine + nParamNamePos, nPos - nParamNamePos);
                SetParam(strParamName, _T(""));
                nStatus = em_Cmd_New_Arg;
            }
            else
            {
                nStatus = em_Cmd_Arg_Name;
            }

            break;

        case em_Cmd_Arg_Value_Prefix:

            if (IsWhiteSpace(ch))
            {
                if (bInQuotation)
                {   // treat quoted white space as arg-value
                    nParamValuePos  = nPos;
                    nStatus         = em_Cmd_Arg_Value;
                }
                else
                {
                    SetParam(strParamName, _T(""));
                    nStatus         = em_Cmd_New_Arg;
                }

            }
            else if (IsQuotation(ch))
            {
                nParamValuePos  = nPos + 1;
                bInQuotation    = TRUE;
                nStatus         = em_Cmd_Arg_Value_Prefix;
            }
            else
            {
                nParamValuePos  = nPos;
                nStatus         = em_Cmd_Arg_Value;
            }

            break;

        case em_Cmd_Arg_Value:

            if (IsWhiteSpace(ch) && !bInQuotation)
            {
                SetParam(strParamName, lpszCmdLine + nParamValuePos, nPos - nParamValuePos);
                nStatus = em_Cmd_New_Arg;
            }
            else if (IsQuotation(ch))
            {
                SetParam(strParamName, lpszCmdLine + nParamValuePos, nPos - nParamValuePos);
                nStatus = em_Cmd_New_Arg;
            }
            else
            {
                nStatus = em_Cmd_Arg_Value;
            }

            break;
        }
     }

     bResult = TRUE;

Exit0:

     return bResult;
}