From c370a092f297448a42238ce3a42240fbc7c5be29 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Tue, 28 Feb 2012 19:02:06 +0200 Subject: [PATCH] Refactor memory watch commands --- src/core/memorywatch.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/core/memorywatch.cpp b/src/core/memorywatch.cpp index a1780dda..5a454a93 100644 --- a/src/core/memorywatch.cpp +++ b/src/core/memorywatch.cpp @@ -3,6 +3,7 @@ #include "core/memorymanip.hpp" #include "core/memorywatch.hpp" #include "core/window.hpp" +#include #include #include @@ -269,23 +270,17 @@ void do_watch_memory() namespace { - function_ptr_command add_watch("add-watch", "Add a memory watch", + function_ptr_command add_watch("add-watch", "Add a memory watch", "Syntax: add-watch \nAdds a new memory watch\n", - [](tokensplitter& t) throw(std::bad_alloc, std::runtime_error) { - std::string name = t; - if(name == "" || t.tail() == "") - throw std::runtime_error("syntax: add-watch "); - set_watchexpr_for(name, t.tail()); + [](const std::string& t) throw(std::bad_alloc, std::runtime_error) { + auto r = regex("([^ \t]+)[ \t]+(|[^ \t].*)", t, "Name and expression required."); + set_watchexpr_for(r[1], r[2]); }); - function_ptr_command remove_watch("remove-watch", "Remove a memory watch", + function_ptr_command remove_watch("remove-watch", "Remove a memory watch", "Syntax: remove-watch \nRemoves a memory watch\n", - [](tokensplitter& t) throw(std::bad_alloc, std::runtime_error) { - std::string name = t; - if(name == "" || t.tail() != "") { - throw std::runtime_error("syntax: remove-watch "); - return; - } - set_watchexpr_for(name, ""); + [](const std::string& t) throw(std::bad_alloc, std::runtime_error) { + auto r = regex("([^ \t]+)[ \t]*", t, "Name required."); + set_watchexpr_for(r[1], ""); }); -} \ No newline at end of file +}