Ignore:
Timestamp:
Mar 23, 2008, 1:24:09 AM (16 years ago)
Author:
dai_9181
Message:

コマンドライン解析モジュールをリファクタリング。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ab5.0/jenga/src/common/CmdLine.cpp

    r291 r457  
    77CmdLines::CmdLines( const std::string &strCmdLine )
    88{
    9     for( int i=0; i<(int)strCmdLine.size() ; i++ )
     9    char temporary[8192];
     10    int i = 0;
     11    while( i<(int)strCmdLine.size() )
    1012    {
     13        while( strCmdLine[i] == ' ' )
     14        {
     15            i ++;
     16        }
     17
     18        if( strCmdLine[i] == '\0' )
     19        {
     20            break;
     21        }
     22
    1123        if( strCmdLine[i] == '/' )
    1224        {
    1325            i++;
    14 
    15             char temporary[255];
    1626
    1727            // コマンド文字列(オプション名)を抽出
     
    3545            if( (int)strCmdLine.size() > i && strCmdLine[i] != '/' )
    3646            {
     47                if( strCmdLine[i] == ':' )
     48                {
     49                    // ':'はコマンドとパラメータの区切り文字として認識する
     50                    i++;
     51                }
     52
    3753                // パラメータを抽出
    3854                if( strCmdLine[i] == '\"' )
     
    7086            this->push_back( CmdLine( command, parameter ) );
    7187        }
     88        else if( strCmdLine[i] == '\"' )
     89        {
     90            i++;
     91            //ダブルクォートの中身を取り出す
     92            for( int j=0; ; j++, i++ )
     93            {
     94                if( strCmdLine[i] == '\"' || strCmdLine[i] == '\0' )
     95                {
     96                    temporary[j] = 0;
     97
     98                    if( strCmdLine[i] == '\"' ) i++;
     99                    break;
     100                }
     101                temporary[j] = strCmdLine[i];
     102            }
     103
     104            this->push_back( CmdLine( "", temporary ) );
     105        }
     106        else
     107        {
     108            //空白またはヌル文字以前を取り出す
     109            for( int j=0; ; j++, i++ )
     110            {
     111                if( strCmdLine[i] == ' ' || strCmdLine[i] == '\0' )
     112                {
     113                    temporary[j] = 0;
     114                    break;
     115                }
     116                temporary[j] = strCmdLine[i];
     117            }
     118
     119            this->push_back( CmdLine( "", temporary ) );
     120        }
    72121    }
    73122}
Note: See TracChangeset for help on using the changeset viewer.