Add Grouped behaviour.
[command.git] / include / multiValue.h
index 90de29a9787d5f229de0935674dc0f9fb4a2e528..26738b5c54e6a7c2461d9a8e88edb4355365aee9 100644 (file)
@@ -2,6 +2,7 @@
 #define __COMMAND_MULTIVALUE_H
 
 #include <iostream>
+#include <vector>
 
 #include "parameter.h"
 
@@ -67,11 +68,17 @@ namespace command {
          * \inheritdoc
          */
         virtual bool understand(const std::string & value) {
-            size_t start = parameter->valuePosition(value);
+            size_t start = 0;
             size_t pos = 0;
             bool _understand = true;
             std::string prefix = "";
 
+            start = parameter->valuePosition(value);
+
+            if (start > value.size()) {
+                return false;
+            }
+
             if (start > 0) {
                 prefix = value.substr(0, ++start);// always count: "="
             }
@@ -81,8 +88,12 @@ namespace command {
                 values.push_back(prefix + value.substr(start, pos-start));
                 _understand &= parameter->understand(values.back());
                 start = pos + 1;
-            } while ((pos != std::string::npos) && (start < value.size()));
 
+                if (!_understand) {
+                    values.clear();
+                    break;
+                }
+            } while ((pos != std::string::npos) && (start < value.size()));
             return _understand;
         }
 
@@ -116,4 +127,4 @@ namespace command {
     };
 }
 
-#endif /* __COMMAND_PARAMETER_H */
+#endif /* __COMMAND_MULTIVALUE_H */