@@ -94,25 +94,25 @@ void Terminal::Impl::executeCdCmd(SessionContext *s, const Args &args)
9494    if  (args.size () >= 2 )
9595        path_str = args[1 ];
9696
97-     stringstream ss ;
97+     ostringstream oss ;
9898
9999    auto  node_path = s->path ;
100100    bool  is_found = findNode (path_str, node_path);
101101    if  (is_found) {
102102        auto  top_node_token = node_path.empty () ? root_token_ : node_path.back ().second ;
103103        auto  top_node = nodes_.at (top_node_token);
104104        if  (top_node == nullptr ) {
105-             ss  << " Error: '" " ' node has been deleted." " \r\n " 
105+             oss  << " Error: '" " ' node has been deleted." " \r\n " 
106106        } else  if  (top_node->type () == NodeType::kDir ) {
107107            s->path  = node_path;
108108        } else  {
109-             ss  << " Error: '" " ' not directory." " \r\n " 
109+             oss  << " Error: '" " ' not directory." " \r\n " 
110110        }
111111    } else  {
112-         ss  << " Error: cannot access '" " '.\r\n " 
112+         oss  << " Error: cannot access '" " '.\r\n " 
113113    }
114114
115-     s->wp_conn ->send (s->token , ss .str ());
115+     s->wp_conn ->send (s->token , oss .str ());
116116}
117117
118118void  Terminal::Impl::executeHelpCmd (SessionContext *s, const  Args &args)
@@ -122,7 +122,7 @@ void Terminal::Impl::executeHelpCmd(SessionContext *s, const Args &args)
122122        return ;
123123    }
124124
125-     stringstream ss ;
125+     ostringstream oss ;
126126
127127    string path_str = args[1 ];
128128    auto  node_path = s->path ;
@@ -131,15 +131,15 @@ void Terminal::Impl::executeHelpCmd(SessionContext *s, const Args &args)
131131        auto  top_node_token = node_path.empty () ? root_token_ : node_path.back ().second ;
132132        auto  top_node = nodes_.at (top_node_token);
133133        if  (top_node != nullptr ) {
134-             ss  << top_node->help () << " \r\n " 
134+             oss  << top_node->help () << " \r\n " 
135135        } else  {
136-             ss  << " Error: '" " ' node has been deleted.\r\n " 
136+             oss  << " Error: '" " ' node has been deleted.\r\n " 
137137        }
138138    } else  {
139-         ss  << " Error: cannot access '" " '.\r\n " 
139+         oss  << " Error: cannot access '" " '.\r\n " 
140140    }
141141
142-     s->wp_conn ->send (s->token , ss .str ());
142+     s->wp_conn ->send (s->token , oss .str ());
143143}
144144
145145void  Terminal::Impl::executeLsCmd (SessionContext *s, const  Args &args)
@@ -148,48 +148,48 @@ void Terminal::Impl::executeLsCmd(SessionContext *s, const Args &args)
148148    if  (args.size () >= 2 )
149149        path_str = args[1 ];
150150
151-     stringstream ss ;
151+     ostringstream oss ;
152152
153153    auto  node_path = s->path ;
154154    bool  is_found = findNode (path_str, node_path);
155155    if  (is_found) {
156156        auto  top_node_token = node_path.empty () ? root_token_ : node_path.back ().second ;
157157        auto  top_node = nodes_.at (top_node_token);
158158        if  (top_node == nullptr ) {
159-             ss  << " Error: '" " ' node has been deleted.\r\n " 
159+             oss  << " Error: '" " ' node has been deleted.\r\n " 
160160        } else  if  (top_node->type () == NodeType::kDir ) {
161161            auto  top_dir_node = static_cast <DirNode*>(top_node);
162162            vector<NodeInfo> node_info_vec;
163163            top_dir_node->children (node_info_vec);
164164
165165            for  (auto  item : node_info_vec) {
166-                 ss  << " - " name ;
166+                 oss  << " - " name ;
167167                auto  node = nodes_.at (item.token );
168168                if  (node == nullptr ) {
169-                     ss  << " (X)" 
169+                     oss  << " (X)" 
170170                } else  if  (node->type () == NodeType::kDir )
171-                     ss  << ' /' 
172-                 ss  << " \r\n " 
171+                     oss  << ' /' 
172+                 oss  << " \r\n " 
173173            }
174-             ss  << " \r\n " 
174+             oss  << " \r\n " 
175175        } else  {
176-             ss  << path_str << "  is function" " .\r\n " 
176+             oss  << path_str << "  is function" " .\r\n " 
177177        }
178178    } else  {
179-         ss  << " Error: cannot access '" " '.\r\n " 
179+         oss  << " Error: cannot access '" " '.\r\n " 
180180    }
181181
182-     s->wp_conn ->send (s->token , ss .str ());
182+     s->wp_conn ->send (s->token , oss .str ());
183183}
184184
185185void  Terminal::Impl::executeHistoryCmd (SessionContext *s, const  Args &)
186186{
187-     stringstream ss ;
187+     ostringstream oss ;
188188    for  (size_t  i = 0 ; i < s->history .size (); ++i) {
189189        const  auto  &cmd = s->history .at (i);
190-         ss  << setw (2 ) << i << "   " " \r\n " 
190+         oss  << setw (2 ) << i << "   " " \r\n " 
191191    }
192-     s->wp_conn ->send (s->token , ss .str ());
192+     s->wp_conn ->send (s->token , oss .str ());
193193}
194194
195195void  Terminal::Impl::executeExitCmd (SessionContext *s, const  Args &)
@@ -212,7 +212,7 @@ void Terminal::Impl::executeTreeCmd(SessionContext *s, const Args &args)
212212    if  (args.size () >= 2 )
213213        path_str = args[1 ];
214214
215-     stringstream ss ;
215+     ostringstream oss ;
216216
217217    auto  node_path = s->path ;
218218    bool  is_found = findNode (path_str, node_path);
@@ -221,7 +221,7 @@ void Terminal::Impl::executeTreeCmd(SessionContext *s, const Args &args)
221221        auto  top_node_token = node_path.empty () ? root_token_ : node_path.back ().second ;
222222        auto  top_node = nodes_.at (top_node_token);
223223        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 " 
225225        } else  if  (top_node->type () == NodeType::kDir ) {
226226            vector<vector<NodeInfo>> node_token_stack;    // !< 遍历栈
227227            string indent_str;  // !< 缩进字串
@@ -257,15 +257,15 @@ void Terminal::Impl::executeTreeCmd(SessionContext *s, const Args &args)
257257                    const  char  *curr_indent_str = is_last_node ? " `-- " " |-- " 
258258
259259                    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 ;
261261
262262                    auto  curr_node = nodes_.at (curr_node_info.token );
263263                    if  (curr_node == nullptr ) {
264264                        // ! 如果已被删除了的结点,显示(X)
265-                         ss  << " (X)\r\n " 
265+                         oss  << " (X)\r\n " 
266266                    } else  if  (curr_node->type () == NodeType::kFunc ) {
267267                        // ! 如果是Func,就打印一下名称就可以了
268-                         ss  << " \r\n " 
268+                         oss  << " \r\n " 
269269                    } else  if  (curr_node->type () == NodeType::kDir ) {
270270                        // ! 如果是Dir,则需要再深入地遍历其子Node
271271                        // ! 首先需要查重,防止循环路径引起的死循环
@@ -276,9 +276,9 @@ void Terminal::Impl::executeTreeCmd(SessionContext *s, const Args &args)
276276                        }
277277
278278                        if  (is_repeat)
279-                             ss  << " (R)" 
279+                             oss  << " (R)" 
280280
281-                         ss  << " \r\n " 
281+                         oss  << " \r\n " 
282282
283283                        if  (!is_repeat) {
284284                            // ! 找出该Dir下所有的子Node。
@@ -307,26 +307,26 @@ void Terminal::Impl::executeTreeCmd(SessionContext *s, const Args &args)
307307                }
308308            }
309309        } else  {
310-             ss  << node_path.back ().first  << "  is a function.\r\n " 
310+             oss  << node_path.back ().first  << "  is a function.\r\n " 
311311        }
312312    } else  {
313-         ss  << " Error: cannot access '" " '.\r\n " 
313+         oss  << " Error: cannot access '" " '.\r\n " 
314314    }
315315
316-     s->wp_conn ->send (s->token , ss .str ());
316+     s->wp_conn ->send (s->token , oss .str ());
317317}
318318
319319void  Terminal::Impl::executePwdCmd (SessionContext *s, const  Args &)
320320{
321-     stringstream ss ;
322-     ss  << ' /' 
321+     ostringstream oss ;
322+     oss  << ' /' 
323323    for  (size_t  i = 0 ; i < s->path .size (); ++i) {
324-         ss  << s->path .at (i).first ;
324+         oss  << s->path .at (i).first ;
325325        if  ((i + 1 ) != s->path .size ())
326-             ss  << ' /' 
326+             oss  << ' /' 
327327    }
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 ());
330330}
331331
332332bool  Terminal::Impl::executeRunHistoryCmd (SessionContext *s, const  Args &args)
@@ -368,7 +368,7 @@ bool Terminal::Impl::executeRunHistoryCmd(SessionContext *s, const Args &args)
368368
369369void  Terminal::Impl::executeUserCmd (SessionContext *s, const  Args &args)
370370{
371-     stringstream ss ;
371+     ostringstream oss ;
372372
373373    const  auto  &cmd = args[0 ];
374374    auto  node_path = s->path ;
@@ -378,7 +378,7 @@ void Terminal::Impl::executeUserCmd(SessionContext *s, const Args &args)
378378        auto  top_node_token = node_path.empty () ? root_token_ : node_path.back ().second ;
379379        auto  top_node = nodes_.at (top_node_token);
380380        if  (top_node == nullptr ) {
381-             ss  << " Error: '" " ' node has been deleted.\r\n " 
381+             oss  << " Error: '" " ' node has been deleted.\r\n " 
382382        } else  if  (top_node->type () == NodeType::kFunc ) {
383383            auto  top_func_node = static_cast <FuncNode*>(top_node);
384384            Session session (s->wp_conn , s->token );
@@ -387,10 +387,10 @@ void Terminal::Impl::executeUserCmd(SessionContext *s, const Args &args)
387387            s->path  = node_path;
388388        }
389389    } else  {
390-         ss  << " Error: '" " ' not found.\r\n " 
390+         oss  << " Error: '" " ' not found.\r\n " 
391391    }
392392
393-     s->wp_conn ->send (s->token , ss .str ());
393+     s->wp_conn ->send (s->token , oss .str ());
394394}
395395
396396}
0 commit comments