ソースを参照

made tokenizing code nicer

Denys 5 年 前
コミット
00a0cfe624
1 ファイル変更8 行追加5 行削除
  1. 8 5
      cli/src/ioman.cpp

+ 8 - 5
cli/src/ioman.cpp

@@ -227,6 +227,7 @@ void IoMan::inputMain() {
 		for(string cmd : toprocess) {
 			args = vector<string>();
 			
+			/* tokenize string into command and arguments vector*/
 			if((index = cmd.find(" ")) == string::npos) {
 				// only command no args
 				command = cmd;
@@ -234,14 +235,17 @@ void IoMan::inputMain() {
 			else {
 				command = cmd.substr(0, index);
 				//~ index++;
-				while(true) {
+				
+				bool end_tokenizing = false;
+				while(!end_tokenizing) {
 					// find first char thats not a space
 					while(cmd[index] == ' ') {
 						index++;
 						
 						// bounds check
-						if(index == cmd.size()) goto end_tokenizing;
+						if(index == cmd.size()) end_tokenizing = true;
 					}
+					if(end_tokenizing) break;
 					
 					cmd = cmd.substr(index);
 					
@@ -256,21 +260,20 @@ void IoMan::inputMain() {
 						*/
 						
 						// char after closing quote should be space while within bounds
-						if(index == cmd.size()) goto end_tokenizing;
+						if(index == cmd.size()) end_tokenizing = true;
 					}
 					else {
 						// non-quoted string
 						index = cmd.find(" ");
 						if(index == string::npos) { // no spaces, last arg
 							args.push_back(cmd);
-							goto end_tokenizing;
+							end_tokenizing = true;
 						}
 						else {
 							args.push_back(cmd.substr(0, index));
 						}
 					}
 				}
-				end_tokenizing: ;
 			}
 			
 			cmdret = cmdman.execute(command, args);