From 54c64b887fb9af6cff1203e085c0464c25743cb5 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Sat, 5 May 2018 18:04:02 +0200 Subject: Fix split() --- main.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/main.cpp b/main.cpp index fec1ba0..29263cd 100644 --- a/main.cpp +++ b/main.cpp @@ -37,7 +37,7 @@ std::vector split(const std::string& str, const char sep) size_t next = 0; while ((next = str.find(sep, last)) != std::string::npos) { - v.push_back(str.substr(next, next +1)); + v.push_back(str.substr(last, next-last)); last = next + 1; } @@ -87,19 +87,16 @@ int main(int argc, char** argv) // write prompt uart::write<1>("> "); - - while (uart::rx_buffer<1>().empty()); + do { - input += uart::read_wait<1>(); - } while (uart::rx_buffer<1>().front() != '\r'); - // remove '\r' from the RX buffer - uart::rx_buffer<1>().pop(); + input += uart::read_wait<1>(); + } while (input.back() != '\r'); #ifdef DEBUG uart::write<1>("\n\rinput: "); uart::print<1>(input); #endif - + // remove weird symbols strip(input); @@ -107,8 +104,9 @@ int main(int argc, char** argv) const std::vector command = split(input, ' '); #ifdef DEBUG - for (const std::string &s : command) { - uart::print<1>(s); + uart::print<1>("parsed commmands:"); + for (int i = 0; i < command.size(); i++) { + uart::print<1>(command[i]); } #endif -- cgit v1.2.1