environment_iterator.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright Vladimir Prus 2004.
  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. #ifndef BOOST_ENVIRONMENT_ITERATOR_VP_2004_05_14
  6. #define BOOST_ENVIRONMENT_ITERATOR_VP_2004_05_14
  7. #include "eof_iterator.hpp"
  8. #include <utility>
  9. #include <string>
  10. #include <cassert>
  11. namespace boost {
  12. class environment_iterator
  13. : public eof_iterator<environment_iterator,
  14. std::pair<std::string, std::string> >
  15. {
  16. public:
  17. environment_iterator(char** environment)
  18. : m_environment(environment)
  19. {
  20. get();
  21. }
  22. environment_iterator()
  23. {
  24. found_eof();
  25. }
  26. void get()
  27. {
  28. if (*m_environment == 0)
  29. found_eof();
  30. else {
  31. std::string s(*m_environment);
  32. std::string::size_type n = s.find('=');
  33. assert(n != s.npos);
  34. value().first = s.substr(0, n);
  35. value().second = s.substr(n+1);
  36. ++m_environment;
  37. }
  38. }
  39. private:
  40. char** m_environment;
  41. };
  42. }
  43. #endif