mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-10 10:55:33 +00:00
56 lines
1.7 KiB
C++
56 lines
1.7 KiB
C++
/*
|
|
* KMFL Input Method for SCIM (Smart Common Input Method)
|
|
*
|
|
* Copyright (C) 2005 SIL International
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This library 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
|
|
* General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
*
|
|
*/
|
|
|
|
#ifndef __STRINGTOK_H__
|
|
#define __STRINGTOK_H__
|
|
|
|
#include <string>
|
|
|
|
template <typename Container>
|
|
void
|
|
stringtok (Container &container, std::string const &in,
|
|
const char * const delimiters = " \t\n")
|
|
{
|
|
const std::string::size_type len = in.length();
|
|
std::string::size_type i = 0;
|
|
|
|
while ( i < len )
|
|
{
|
|
// eat leading whitespace
|
|
i = in.find_first_not_of (delimiters, i);
|
|
if (i == std::string::npos)
|
|
return; // nothing left but white space
|
|
|
|
// find the end of the token
|
|
std::string::size_type j = in.find_first_of (delimiters, i);
|
|
|
|
// push token
|
|
if (j == std::string::npos) {
|
|
container.push_back (in.substr(i));
|
|
return;
|
|
} else
|
|
container.push_back (in.substr(i, j-i));
|
|
|
|
// set up for next loop
|
|
i = j + 1;
|
|
}
|
|
}
|
|
#endif
|