Changeset 2879


Ignore:
Timestamp:
Nov 16, 2012, 2:47:56 AM (9 years ago)
Author:
Peter
Message:

split function that splits on several chars

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/split.cc

    r2370 r2879  
    22
    33/*
    4   Copyright (C) 2010 Peter Johansson
     4  Copyright (C) 2010, 2012 Peter Johansson
    55
    66  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    2929using namespace theplu::yat;
    3030
     31template<typename T>
    3132void test_split(const std::vector<std::string>& correct, const std::string& str,
    32                 char delim, test::Suite& suite);
     33                T delim, test::Suite& suite);
    3334
    3435int main(int argc, char* argv[])
     
    5354  test_split(correct, "banan", 'n', suite);
    5455
     56  correct[0]="split";
     57  correct[1]="me";
     58  correct[2]="please";
     59  test_split(correct, "split,me;please", ";,", suite);
     60
     61
    5562  return suite.return_value();
    5663}
    5764
     65  template<typename T>
    5866void test_split(const std::vector<std::string>& correct, const std::string& str,
    59                 char delim, test::Suite& suite)
     67                T delim, test::Suite& suite)
    6068{
    6169  suite.out() << "split(vec, \"" << str << "\", '" << delim << "')\n";
  • trunk/yat/utility/split.cc

    r2434 r2879  
    22
    33/*
    4   Copyright (C) 2010 Peter Johansson
     4  Copyright (C) 2010, 2012 Peter Johansson
    55
    66  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    2929namespace utility {
    3030
    31   void split(std::vector<std::string>& vec, const std::string& str, char delim)
     31namespace detail {
     32
     33  /*
     34    implementation of split functions is declared in private namespace
     35    and only available in this file.
     36   */
     37  template<typename T>
     38  void split(std::vector<std::string>& vec, const std::string& str, T delim)
    3239  {
    3340    size_t pos=0;
     
    4047    }
    4148  }
     49} // end of namespace detail
     50
     51
     52  void split(std::vector<std::string>& vec, const std::string& str, char delim)
     53  {
     54    detail::split(vec, str, delim);
     55  }
     56
     57
     58  void split(std::vector<std::string>& vec, const std::string& str,
     59             const std::string& delim)
     60  {
     61    detail::split(vec, str, delim);
     62  }
    4263
    4364}}} // of namespace utility, yat, and theplu
  • trunk/yat/utility/split.h

    r2434 r2879  
    11#ifndef _theplu_yat_utility_split_
    2 #define _theplu_yat_utility_split_ 
     2#define _theplu_yat_utility_split_
    33
    44// $Id$
    55
    66/*
    7   Copyright (C) 2010 Peter Johansson
     7  Copyright (C) 2010, 2012 Peter Johansson
    88
    99  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    4141     \since New in yat 0.7
    4242   */
    43   void split(std::vector<std::string>& result, const std::string& str, 
     43  void split(std::vector<std::string>& result, const std::string& str,
    4444             char delim);
     45
     46  /**
     47     \brief split a string into substrings
     48
     49     Same as
     50     void split(std::vector<std::string>&, const std::string&,char delim);
     51     but split if character matches any in delims, i.e.,
     52     split(vec,"split,me;please", ",;") will be split into "split",
     53     "me", and "please".
     54
     55     \since New in yat 0.10
     56   */
     57  void split(std::vector<std::string>& result, const std::string& str,
     58             const std::string& delim);
    4559
    4660}}} // of namespace utility, yat, and theplu
Note: See TracChangeset for help on using the changeset viewer.