StringList.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "anki/util/StringList.h"
  2. #include <iostream> ///XXX
  3. #include <boost/tokenizer.hpp>
  4. #include <boost/foreach.hpp>
  5. namespace anki {
  6. //==============================================================================
  7. StringList::String StringList::join(const Char* sep) const
  8. {
  9. String out;
  10. Base::const_iterator it = begin();
  11. for(; it != end(); it++)
  12. {
  13. out += *it;
  14. if(it != end() - 1)
  15. {
  16. out += sep;
  17. }
  18. }
  19. return out;
  20. }
  21. //==============================================================================
  22. int StringList::getIndexOf(const Char* value) const
  23. {
  24. size_t pos = 0;
  25. for(const_iterator it = begin(); it != end(); ++it)
  26. {
  27. if(*it == value)
  28. {
  29. break;
  30. }
  31. ++ pos;
  32. }
  33. return (pos == size()) ? -1 : pos;
  34. }
  35. //==============================================================================
  36. StringList StringList::splitString(const Char* s, const Char* seperators)
  37. {
  38. typedef boost::char_separator<Char> Sep;
  39. typedef boost::tokenizer<Sep> Tok;
  40. Sep sep(seperators);
  41. StringList out;
  42. String str(s);
  43. Tok tok(str, sep);
  44. BOOST_FOREACH(const String& s_, tok)
  45. {
  46. out.push_back(s_);
  47. }
  48. return out;
  49. }
  50. //==============================================================================
  51. std::ostream& operator<<(std::ostream& s, const StringList& a)
  52. {
  53. s << a.join(", ");
  54. return s;
  55. }
  56. } // end namespace