source: dev/trunk/jenga/src/common/CmdLine.cpp@ 362

Last change on this file since 362 was 291, checked in by dai_9181, 17 years ago
File size: 1.7 KB
Line 
1#include <jenga/include/common/CmdLine.h>
2
3#include <boost/foreach.hpp>
4
5using namespace Jenga::Common;
6
7CmdLines::CmdLines( const std::string &strCmdLine )
8{
9 for( int i=0; i<(int)strCmdLine.size() ; i++ )
10 {
11 if( strCmdLine[i] == '/' )
12 {
13 i++;
14
15 char temporary[255];
16
17 // コマンド文字列(オプション名)を抽出
18 for( int j = 0; ; j++, i++ )
19 {
20 if( isalpha( strCmdLine[i] ) || isdigit( strCmdLine[i] ) || strCmdLine[i] == '_' )
21 {
22 temporary[j] = strCmdLine[i];
23 }
24 else
25 {
26 temporary[j] = 0;
27 break;
28 }
29 }
30 while( strCmdLine[i] == ' ' ) i++;
31
32 std::string command = temporary;
33 std::string parameter = "";
34
35 if( (int)strCmdLine.size() > i && strCmdLine[i] != '/' )
36 {
37 // パラメータを抽出
38 if( strCmdLine[i] == '\"' )
39 {
40 i++;
41 //ダブルクォートの中身を取り出す
42 for( int j=0; ; j++, i++ )
43 {
44 if( strCmdLine[i] == '\"' || strCmdLine[i] == '\0' )
45 {
46 temporary[j] = 0;
47
48 if( strCmdLine[i] == '\"' ) i++;
49 break;
50 }
51 temporary[j] = strCmdLine[i];
52 }
53 }
54 else
55 {
56 //空白またはヌル文字以前を取り出す
57 for( int j=0; ; j++, i++ )
58 {
59 if( strCmdLine[i] == ' ' || strCmdLine[i] == '\0' )
60 {
61 temporary[j] = 0;
62 break;
63 }
64 temporary[j] = strCmdLine[i];
65 }
66 }
67 parameter = temporary;
68 }
69
70 this->push_back( CmdLine( command, parameter ) );
71 }
72 }
73}
74
75bool CmdLines::IsExist( const std::string &commandString ) const
76{
77 const CmdLines &cmdLines = *this;
78 BOOST_FOREACH( const CmdLine &cmdLine, cmdLines )
79 {
80 if( cmdLine.GetCommand() == commandString )
81 {
82 return true;
83 }
84 }
85 return false;
86}
Note: See TracBrowser for help on using the repository browser.