source: dev/trunk/ab5.0/jenga/src/common/CmdLine.cpp@ 826

Last change on this file since 826 was 518, checked in by dai_9181, 17 years ago

jengaプロジェクトにプリコンパイル済みヘッダを適用した。

File size: 2.5 KB
Line 
1#include "stdafx.h"
2
3using namespace Jenga::Common;
4
5CmdLines::CmdLines( const std::string &strCmdLine )
6{
7 char temporary[8192];
8 int i = 0;
9 while( i<(int)strCmdLine.size() )
10 {
11 while( strCmdLine[i] == ' ' )
12 {
13 i ++;
14 }
15
16 if( strCmdLine[i] == '\0' )
17 {
18 break;
19 }
20
21 if( strCmdLine[i] == '/' )
22 {
23 i++;
24
25 // コマンド文字列(オプション名)を抽出
26 for( int j = 0; ; j++, i++ )
27 {
28 if( isalpha( strCmdLine[i] ) || isdigit( strCmdLine[i] ) || strCmdLine[i] == '_' )
29 {
30 temporary[j] = strCmdLine[i];
31 }
32 else
33 {
34 temporary[j] = 0;
35 break;
36 }
37 }
38 while( strCmdLine[i] == ' ' ) i++;
39
40 std::string command = temporary;
41 std::string parameter = "";
42
43 if( (int)strCmdLine.size() > i && strCmdLine[i] != '/' )
44 {
45 if( strCmdLine[i] == ':' )
46 {
47 // ':'はコマンドとパラメータの区切り文字として認識する
48 i++;
49 }
50
51 // パラメータを抽出
52 if( strCmdLine[i] == '\"' )
53 {
54 i++;
55 //ダブルクォートの中身を取り出す
56 for( int j=0; ; j++, i++ )
57 {
58 if( strCmdLine[i] == '\"' || strCmdLine[i] == '\0' )
59 {
60 temporary[j] = 0;
61
62 if( strCmdLine[i] == '\"' ) i++;
63 break;
64 }
65 temporary[j] = strCmdLine[i];
66 }
67 }
68 else
69 {
70 //空白またはヌル文字以前を取り出す
71 for( int j=0; ; j++, i++ )
72 {
73 if( strCmdLine[i] == ' ' || strCmdLine[i] == '\0' )
74 {
75 temporary[j] = 0;
76 break;
77 }
78 temporary[j] = strCmdLine[i];
79 }
80 }
81 parameter = temporary;
82 }
83
84 this->push_back( CmdLine( command, parameter ) );
85 }
86 else if( strCmdLine[i] == '\"' )
87 {
88 i++;
89 //ダブルクォートの中身を取り出す
90 for( int j=0; ; j++, i++ )
91 {
92 if( strCmdLine[i] == '\"' || strCmdLine[i] == '\0' )
93 {
94 temporary[j] = 0;
95
96 if( strCmdLine[i] == '\"' ) i++;
97 break;
98 }
99 temporary[j] = strCmdLine[i];
100 }
101
102 this->push_back( CmdLine( "", temporary ) );
103 }
104 else
105 {
106 //空白またはヌル文字以前を取り出す
107 for( int j=0; ; j++, i++ )
108 {
109 if( strCmdLine[i] == ' ' || strCmdLine[i] == '\0' )
110 {
111 temporary[j] = 0;
112 break;
113 }
114 temporary[j] = strCmdLine[i];
115 }
116
117 this->push_back( CmdLine( "", temporary ) );
118 }
119 }
120}
121
122bool CmdLines::IsExist( const std::string &commandString ) const
123{
124 const CmdLines &cmdLines = *this;
125 BOOST_FOREACH( const CmdLine &cmdLine, cmdLines )
126 {
127 if( cmdLine.GetCommand() == commandString )
128 {
129 return true;
130 }
131 }
132 return false;
133}
Note: See TracBrowser for help on using the repository browser.