split.cpp 711 B

123456789101112131415161718192021222324
  1. #include "split.h"
  2. template <class TValue>
  3. inline size_t Split(const char* ptr, const char* delim, TVector<TValue>& values) {
  4. values.erase(values.begin(), values.end());
  5. while (ptr && *ptr) {
  6. ptr += strspn(ptr, delim);
  7. if (ptr && *ptr) {
  8. size_t epos = strcspn(ptr, delim);
  9. assert(epos);
  10. values.push_back(TValue(ptr, epos));
  11. ptr += epos;
  12. }
  13. }
  14. return values.size();
  15. }
  16. size_t Split(const char* ptr, const char* delim, TVector<TString>& values) {
  17. return Split<TString>(ptr, delim, values);
  18. }
  19. size_t Split(const TString& in, const TString& delim, TVector<TString>& res) {
  20. return Split(in.data(), delim.data(), res);
  21. }