| 1 | // Copyright Sascha Ochsenknecht 2009. |
| 2 | // Distributed under the Boost Software License, Version 1.0. |
| 3 | // (See accompanying file LICENSE_1_0.txt |
| 4 | // or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | #define BOOST_PROGRAM_OPTIONS_SOURCE |
| 7 | |
| 8 | #include <boost/program_options/parsers.hpp> |
| 9 | #include <boost/tokenizer.hpp> |
| 10 | |
| 11 | #include <string> |
| 12 | #include <vector> |
| 13 | |
| 14 | namespace boost { namespace program_options { namespace detail { |
| 15 | |
| 16 | template< class charT > |
| 17 | std::vector<std::basic_string<charT> > |
| 18 | split_unix( |
| 19 | const std::basic_string<charT>& cmdline, |
| 20 | const std::basic_string<charT>& seperator, |
| 21 | const std::basic_string<charT>& quote, |
| 22 | const std::basic_string<charT>& escape) |
| 23 | { |
| 24 | typedef boost::tokenizer< boost::escaped_list_separator<charT>, |
| 25 | typename std::basic_string<charT>::const_iterator, |
| 26 | std::basic_string<charT> > tokenizerT; |
| 27 | |
| 28 | tokenizerT tok(cmdline.begin(), cmdline.end(), |
| 29 | boost::escaped_list_separator< charT >(escape, seperator, quote)); |
| 30 | |
| 31 | std::vector< std::basic_string<charT> > result; |
| 32 | for (typename tokenizerT::iterator cur_token(tok.begin()), end_token(tok.end()); cur_token != end_token; ++cur_token) { |
| 33 | if (!cur_token->empty()) |
| 34 | result.push_back(*cur_token); |
| 35 | } |
| 36 | return result; |
| 37 | } |
| 38 | |
| 39 | }}} // namespace |
| 40 | |
| 41 | namespace boost { namespace program_options { |
| 42 | |
| 43 | // Take a command line string and splits in into tokens, according |
| 44 | // to the given collection of seperators chars. |
| 45 | BOOST_PROGRAM_OPTIONS_DECL std::vector<std::string> |
| 46 | split_unix(const std::string& cmdline, const std::string& seperator, |
| 47 | const std::string& quote, const std::string& escape) |
| 48 | { |
| 49 | return detail::split_unix< char >(cmdline, seperator, quote, escape); |
| 50 | } |
| 51 | |
| 52 | #ifndef BOOST_NO_STD_WSTRING |
| 53 | BOOST_PROGRAM_OPTIONS_DECL std::vector<std::wstring> |
| 54 | split_unix(const std::wstring& cmdline, const std::wstring& seperator, |
| 55 | const std::wstring& quote, const std::wstring& escape) |
| 56 | { |
| 57 | return detail::split_unix< wchar_t >(cmdline, seperator, quote, escape); |
| 58 | } |
| 59 | #endif |
| 60 | |
| 61 | }} // namespace |
| 62 | |
| 63 | |