XRootD
Loading...
Searching...
No Matches
XrdOucTUtils.hh
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d O u c U t i l s . h h */
4/* */
5/* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* All Rights Reserved */
7/* Produced by Andrew Hanushevsky for Stanford University under contract */
8/* DE-AC02-76-SFO0515 with the Department of Energy */
9/* */
10/* This file is part of the XRootD software suite. */
11/* */
12/* XRootD is free software: you can redistribute it and/or modify it under */
13/* the terms of the GNU Lesser General Public License as published by the */
14/* Free Software Foundation, either version 3 of the License, or (at your */
15/* option) any later version. */
16/* */
17/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20/* License for more details. */
21/* */
22/* You should have received a copy of the GNU Lesser General Public License */
23/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25/* */
26/* The copyright holder's institutional names and contributor's names may not */
27/* be used to endorse or promote products derived from this software without */
28/* specific prior written permission of the institution or contributor. */
29/******************************************************************************/
30
31#ifndef XROOTD_XRDOUCTUTILS_HH
32#define XROOTD_XRDOUCTUTILS_HH
33
34#include <string>
35#include <map>
36#include <algorithm>
37
44
45public:
46
47//------------------------------------------------------------------------
49//------------------------------------------------------------------------
50template<class Container>
51static void splitString( Container &result, const std::string &input, const std::string &delimiter ) {
52 size_t start = 0;
53 size_t end = 0;
54 size_t length = 0;
55
56 do {
57 end = input.find(delimiter, start);
58
59 if (end != std::string::npos)
60 length = end - start;
61 else
62 length = input.length() - start;
63
64 if (length)
65 result.push_back(input.substr(start, length));
66
67 start = end + delimiter.size();
68 } while (end != std::string::npos);
69}
70
78template<typename T>
79static typename std::map<std::string, T>::const_iterator caseInsensitiveFind(const std::map<std::string, T> & m, const std::string & lowerCaseSearchKey) {
80 auto it = std::find_if(m.begin(),m.end(), [&lowerCaseSearchKey](const std::pair<std::string, T> & p){
81 return std::equal(
82 p.first.begin(), p.first.end(),
83 lowerCaseSearchKey.begin(), lowerCaseSearchKey.end(),
84 [](unsigned char a, unsigned char b) {
85 return (std::tolower(a) == b);
86 }
87 );
88 });
89 return it;
90}
91
92};
93
94#endif //XROOTD_XRDOUCTUTILS_HH
static void splitString(Container &result, const std::string &input, const std::string &delimiter)
Split a string.
static std::map< std::string, T >::const_iterator caseInsensitiveFind(const std::map< std::string, T > &m, const std::string &lowerCaseSearchKey)