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