[nemiver/console: 6/11] Use std::istringstream instead of a custom tokenizer



commit 1dfa43077cbfb77d3ea7967a173431ca8c9ca93e
Author: Fabien Parent <parent f gmail com>
Date:   Fri Mar 2 17:10:49 2012 +0100

    Use std::istringstream instead of a custom tokenizer

 src/common/nmv-console.cc |   26 ++++++++------------------
 1 files changed, 8 insertions(+), 18 deletions(-)
---
diff --git a/src/common/nmv-console.cc b/src/common/nmv-console.cc
index 320244d..a67054f 100644
--- a/src/common/nmv-console.cc
+++ b/src/common/nmv-console.cc
@@ -297,24 +297,14 @@ struct Console::Priv {
         std::string command_name;
         std::vector<std::string> cmd_argv;
 
-        int size = std::strlen (a_buffer);
-        for (int i = 0, local_index = 0; i <= size; ++i, ++local_index) {
-            if (!std::isspace (a_buffer[local_index]) && i != size) {
-                continue;
-            }
-
-            a_buffer[local_index] = '\0';
-            std::string token (a_buffer);
-            if (!token.empty ())
-            {
-                if (command_name.empty ()) {
-                    command_name = token;
-                } else {
-                    cmd_argv.push_back (token);
-                }
-            }
-            a_buffer += local_index + 1;
-            local_index = -1;
+        std::istringstream is (a_buffer);
+        is >> command_name;
+
+        while (is.good ())
+        {
+            std::string arg;
+            is >> arg;
+            cmd_argv.push_back (arg);
         }
 
         if (command_name.empty ()) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]