Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
StringUtils.hxx
Go to the documentation of this file.
1/// \file ROOT/StringUtils.hxx
2/// \ingroup Base StdExt
3/// \author Jonas Rembser <jonas.rembser@cern.ch>
4/// \date 2021-08-09
5
6/*************************************************************************
7 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
8 * All rights reserved. *
9 * *
10 * For the licensing terms see $ROOTSYS/LICENSE. *
11 * For the list of contributors see $ROOTSYS/README/CREDITS. *
12 *************************************************************************/
13
14#ifndef ROOT_StringUtils
15#define ROOT_StringUtils
16
17#include <string_view>
18
19#include <string>
20#include <vector>
21#include <numeric>
22
23namespace ROOT {
24
25std::vector<std::string> Split(std::string_view str, std::string_view delims, bool skipEmpty = false);
26
27/**
28 * \brief Concatenate a list of strings with a separator
29 * \tparm Any container of strings (vector, initializer_list, ...)
30 * \param[in] sep Separator inbetween the strings.
31 * \param[in] strings container of strings
32 * \return the sep-delimited concatenation of strings
33 */
34template <class StringCollection_t>
35std::string Join(const std::string &sep, StringCollection_t &&strings)
36{
37 if (strings.empty())
38 return "";
39 return std::accumulate(std::next(std::begin(strings)), std::end(strings), strings[0],
40 [&sep](auto const &a, auto const &b) { return a + sep + b; });
41}
42
43} // namespace ROOT
44
45#endif
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
std::string Join(const std::string &sep, StringCollection_t &&strings)
Concatenate a list of strings with a separator \tparm Any container of strings (vector,...
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.