@@ -94,25 +94,25 @@ void Terminal::Impl::executeCdCmd(SessionContext *s, const Args &args)
94
94
if (args.size () >= 2 )
95
95
path_str = args[1 ];
96
96
97
- stringstream ss ;
97
+ ostringstream oss ;
98
98
99
99
auto node_path = s->path ;
100
100
bool is_found = findNode (path_str, node_path);
101
101
if (is_found) {
102
102
auto top_node_token = node_path.empty () ? root_token_ : node_path.back ().second ;
103
103
auto top_node = nodes_.at (top_node_token);
104
104
if (top_node == nullptr ) {
105
- ss << " Error: '" << path_str << " ' node has been deleted." << " \r\n " ;
105
+ oss << " Error: '" << path_str << " ' node has been deleted." << " \r\n " ;
106
106
} else if (top_node->type () == NodeType::kDir ) {
107
107
s->path = node_path;
108
108
} else {
109
- ss << " Error: '" << path_str << " ' not directory." << " \r\n " ;
109
+ oss << " Error: '" << path_str << " ' not directory." << " \r\n " ;
110
110
}
111
111
} else {
112
- ss << " Error: cannot access '" << path_str << " '.\r\n " ;
112
+ oss << " Error: cannot access '" << path_str << " '.\r\n " ;
113
113
}
114
114
115
- s->wp_conn ->send (s->token , ss .str ());
115
+ s->wp_conn ->send (s->token , oss .str ());
116
116
}
117
117
118
118
void Terminal::Impl::executeHelpCmd (SessionContext *s, const Args &args)
@@ -122,7 +122,7 @@ void Terminal::Impl::executeHelpCmd(SessionContext *s, const Args &args)
122
122
return ;
123
123
}
124
124
125
- stringstream ss ;
125
+ ostringstream oss ;
126
126
127
127
string path_str = args[1 ];
128
128
auto node_path = s->path ;
@@ -131,15 +131,15 @@ void Terminal::Impl::executeHelpCmd(SessionContext *s, const Args &args)
131
131
auto top_node_token = node_path.empty () ? root_token_ : node_path.back ().second ;
132
132
auto top_node = nodes_.at (top_node_token);
133
133
if (top_node != nullptr ) {
134
- ss << top_node->help () << " \r\n " ;
134
+ oss << top_node->help () << " \r\n " ;
135
135
} else {
136
- ss << " Error: '" << path_str << " ' node has been deleted.\r\n " ;
136
+ oss << " Error: '" << path_str << " ' node has been deleted.\r\n " ;
137
137
}
138
138
} else {
139
- ss << " Error: cannot access '" << path_str << " '.\r\n " ;
139
+ oss << " Error: cannot access '" << path_str << " '.\r\n " ;
140
140
}
141
141
142
- s->wp_conn ->send (s->token , ss .str ());
142
+ s->wp_conn ->send (s->token , oss .str ());
143
143
}
144
144
145
145
void Terminal::Impl::executeLsCmd (SessionContext *s, const Args &args)
@@ -148,48 +148,48 @@ void Terminal::Impl::executeLsCmd(SessionContext *s, const Args &args)
148
148
if (args.size () >= 2 )
149
149
path_str = args[1 ];
150
150
151
- stringstream ss ;
151
+ ostringstream oss ;
152
152
153
153
auto node_path = s->path ;
154
154
bool is_found = findNode (path_str, node_path);
155
155
if (is_found) {
156
156
auto top_node_token = node_path.empty () ? root_token_ : node_path.back ().second ;
157
157
auto top_node = nodes_.at (top_node_token);
158
158
if (top_node == nullptr ) {
159
- ss << " Error: '" << path_str << " ' node has been deleted.\r\n " ;
159
+ oss << " Error: '" << path_str << " ' node has been deleted.\r\n " ;
160
160
} else if (top_node->type () == NodeType::kDir ) {
161
161
auto top_dir_node = static_cast <DirNode*>(top_node);
162
162
vector<NodeInfo> node_info_vec;
163
163
top_dir_node->children (node_info_vec);
164
164
165
165
for (auto item : node_info_vec) {
166
- ss << " - " << item.name ;
166
+ oss << " - " << item.name ;
167
167
auto node = nodes_.at (item.token );
168
168
if (node == nullptr ) {
169
- ss << " (X)" ;
169
+ oss << " (X)" ;
170
170
} else if (node->type () == NodeType::kDir )
171
- ss << ' /' ;
172
- ss << " \r\n " ;
171
+ oss << ' /' ;
172
+ oss << " \r\n " ;
173
173
}
174
- ss << " \r\n " ;
174
+ oss << " \r\n " ;
175
175
} else {
176
- ss << path_str << " is function" << " .\r\n " ;
176
+ oss << path_str << " is function" << " .\r\n " ;
177
177
}
178
178
} else {
179
- ss << " Error: cannot access '" << path_str << " '.\r\n " ;
179
+ oss << " Error: cannot access '" << path_str << " '.\r\n " ;
180
180
}
181
181
182
- s->wp_conn ->send (s->token , ss .str ());
182
+ s->wp_conn ->send (s->token , oss .str ());
183
183
}
184
184
185
185
void Terminal::Impl::executeHistoryCmd (SessionContext *s, const Args &)
186
186
{
187
- stringstream ss ;
187
+ ostringstream oss ;
188
188
for (size_t i = 0 ; i < s->history .size (); ++i) {
189
189
const auto &cmd = s->history .at (i);
190
- ss << setw (2 ) << i << " " << cmd << " \r\n " ;
190
+ oss << setw (2 ) << i << " " << cmd << " \r\n " ;
191
191
}
192
- s->wp_conn ->send (s->token , ss .str ());
192
+ s->wp_conn ->send (s->token , oss .str ());
193
193
}
194
194
195
195
void Terminal::Impl::executeExitCmd (SessionContext *s, const Args &)
@@ -212,7 +212,7 @@ void Terminal::Impl::executeTreeCmd(SessionContext *s, const Args &args)
212
212
if (args.size () >= 2 )
213
213
path_str = args[1 ];
214
214
215
- stringstream ss ;
215
+ ostringstream oss ;
216
216
217
217
auto node_path = s->path ;
218
218
bool is_found = findNode (path_str, node_path);
@@ -221,7 +221,7 @@ void Terminal::Impl::executeTreeCmd(SessionContext *s, const Args &args)
221
221
auto top_node_token = node_path.empty () ? root_token_ : node_path.back ().second ;
222
222
auto top_node = nodes_.at (top_node_token);
223
223
if (top_node == nullptr ) {
224
- ss << node_path.back ().first << " node has been deleted.\r\n " ;
224
+ oss << node_path.back ().first << " node has been deleted.\r\n " ;
225
225
} else if (top_node->type () == NodeType::kDir ) {
226
226
vector<vector<NodeInfo>> node_token_stack; // !< 遍历栈
227
227
string indent_str; // !< 缩进字串
@@ -257,15 +257,15 @@ void Terminal::Impl::executeTreeCmd(SessionContext *s, const Args &args)
257
257
const char *curr_indent_str = is_last_node ? " `-- " : " |-- " ;
258
258
259
259
auto &curr_node_info = last_level.front ();
260
- ss << indent_str << curr_indent_str << curr_node_info.name ;
260
+ oss << indent_str << curr_indent_str << curr_node_info.name ;
261
261
262
262
auto curr_node = nodes_.at (curr_node_info.token );
263
263
if (curr_node == nullptr ) {
264
264
// ! 如果已被删除了的结点,显示(X)
265
- ss << " (X)\r\n " ;
265
+ oss << " (X)\r\n " ;
266
266
} else if (curr_node->type () == NodeType::kFunc ) {
267
267
// ! 如果是Func,就打印一下名称就可以了
268
- ss << " \r\n " ;
268
+ oss << " \r\n " ;
269
269
} else if (curr_node->type () == NodeType::kDir ) {
270
270
// ! 如果是Dir,则需要再深入地遍历其子Node
271
271
// ! 首先需要查重,防止循环路径引起的死循环
@@ -276,9 +276,9 @@ void Terminal::Impl::executeTreeCmd(SessionContext *s, const Args &args)
276
276
}
277
277
278
278
if (is_repeat)
279
- ss << " (R)" ;
279
+ oss << " (R)" ;
280
280
281
- ss << " \r\n " ;
281
+ oss << " \r\n " ;
282
282
283
283
if (!is_repeat) {
284
284
// ! 找出该Dir下所有的子Node。
@@ -307,26 +307,26 @@ void Terminal::Impl::executeTreeCmd(SessionContext *s, const Args &args)
307
307
}
308
308
}
309
309
} else {
310
- ss << node_path.back ().first << " is a function.\r\n " ;
310
+ oss << node_path.back ().first << " is a function.\r\n " ;
311
311
}
312
312
} else {
313
- ss << " Error: cannot access '" << path_str << " '.\r\n " ;
313
+ oss << " Error: cannot access '" << path_str << " '.\r\n " ;
314
314
}
315
315
316
- s->wp_conn ->send (s->token , ss .str ());
316
+ s->wp_conn ->send (s->token , oss .str ());
317
317
}
318
318
319
319
void Terminal::Impl::executePwdCmd (SessionContext *s, const Args &)
320
320
{
321
- stringstream ss ;
322
- ss << ' /' ;
321
+ ostringstream oss ;
322
+ oss << ' /' ;
323
323
for (size_t i = 0 ; i < s->path .size (); ++i) {
324
- ss << s->path .at (i).first ;
324
+ oss << s->path .at (i).first ;
325
325
if ((i + 1 ) != s->path .size ())
326
- ss << ' /' ;
326
+ oss << ' /' ;
327
327
}
328
- ss << " \r\n " ;
329
- s->wp_conn ->send (s->token , ss .str ());
328
+ oss << " \r\n " ;
329
+ s->wp_conn ->send (s->token , oss .str ());
330
330
}
331
331
332
332
bool Terminal::Impl::executeRunHistoryCmd (SessionContext *s, const Args &args)
@@ -368,7 +368,7 @@ bool Terminal::Impl::executeRunHistoryCmd(SessionContext *s, const Args &args)
368
368
369
369
void Terminal::Impl::executeUserCmd (SessionContext *s, const Args &args)
370
370
{
371
- stringstream ss ;
371
+ ostringstream oss ;
372
372
373
373
const auto &cmd = args[0 ];
374
374
auto node_path = s->path ;
@@ -378,7 +378,7 @@ void Terminal::Impl::executeUserCmd(SessionContext *s, const Args &args)
378
378
auto top_node_token = node_path.empty () ? root_token_ : node_path.back ().second ;
379
379
auto top_node = nodes_.at (top_node_token);
380
380
if (top_node == nullptr ) {
381
- ss << " Error: '" << cmd << " ' node has been deleted.\r\n " ;
381
+ oss << " Error: '" << cmd << " ' node has been deleted.\r\n " ;
382
382
} else if (top_node->type () == NodeType::kFunc ) {
383
383
auto top_func_node = static_cast <FuncNode*>(top_node);
384
384
Session session (s->wp_conn , s->token );
@@ -387,10 +387,10 @@ void Terminal::Impl::executeUserCmd(SessionContext *s, const Args &args)
387
387
s->path = node_path;
388
388
}
389
389
} else {
390
- ss << " Error: '" << cmd << " ' not found.\r\n " ;
390
+ oss << " Error: '" << cmd << " ' not found.\r\n " ;
391
391
}
392
392
393
- s->wp_conn ->send (s->token , ss .str ());
393
+ s->wp_conn ->send (s->token , oss .str ());
394
394
}
395
395
396
396
}
0 commit comments