/usr/include/gtextutils/string_tokenize.h is in libgtextutils-dev 0.7-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | /*
Gordon's Text-Utilities Library
Copyright (C) 2009-2013 Assaf Gordon (assafgordon@gmail.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef __STRING_TOKENIZE_H__
#define __STRING_TOKENIZE_H__
#include <string>
#include <iterator>
/*
Splits a string into tokens, based on delimiter
Heavily based on code from:
C++ Programming HOW-TO
Al Dev (Alavoor Vasudevan) alavoor[AT]yahoo.com
http://oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html
(Distributed under GPL)
Usage Example:
string input = "Hello|Token|World";
vector<string> tokens;
String_Tokenize ( input, back_inserter<string>(tokens), "|" );
*/
template <typename OutputIterator>
void String_Tokenize(const std::string& str,
OutputIterator output_iter,
const std::string& delimiters = " ")
{
// Skip delimiters at beginning.
std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
// Find first "non-delimiter".
std::string::size_type pos = str.find_first_of(delimiters, lastPos);
while (std::string::npos != pos || std::string::npos != lastPos)
{
*output_iter = str.substr(lastPos, pos - lastPos);
++output_iter;
// Skip delimiters. Note the "not_of"
lastPos = str.find_first_not_of(delimiters, pos);
// Find next "non-delimiter"
pos = str.find_first_of(delimiters, lastPos);
}
}
#endif
|