1 /* 2 * (c) 2008-2009 Alexander Warg <warg@os.inf.tu-dresden.de> 3 * economic rights: Technische Universität Dresden (Germany) 4 * 5 * This file is part of TUD:OS and distributed under the terms of the 6 * GNU General Public License 2. 7 * Please see the COPYING-GPL-2 file for details. 8 */ 9 #pragma once 10 11 #include <l4/cxx/string> 12 #include <l4/cxx/pair> 13 14 #include <cctype> 15 16 static next_arg(cxx::String const & cmdline)17cxx::Pair<cxx::String, cxx::String> next_arg(cxx::String const &cmdline) 18 { 19 cxx::String cp = cmdline; 20 char quote = 0; 21 22 //char const *arg = 0; 23 24 while (!cp.empty() && isspace(cp[0])) 25 cp = cp.substr(1); 26 27 if (cp.empty()) 28 return cxx::pair(cp, cp); 29 30 if (cp[0] == '"' || cp[0] == '\'') 31 { 32 quote = cp[0]; 33 cp = cp.substr(1); 34 } 35 36 cxx::String::Index e; 37 if (quote) 38 e = cp.find(quote); 39 else 40 e = cp.find_match([](int c) { return isspace(c); }); 41 42 // missing end quote 43 if (quote && cp.eof(e)) 44 return cxx::pair(cxx::String(), cxx::String()); 45 46 return cxx::pair(cp.head(e), cp.substr(e+1)); 47 } 48 49