Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/misc/Tokenizer.h @ 583

Last change on this file since 583 was 507, checked in by nicolape, 17 years ago
  • Skybox and ambient light load now from level file sample.oxw. Added objects to and methods to parse this tags. Added a tokenizer function to split strings into smaller strings (for reading out the light colours for examle). Moved Tokenizer and String2number into misc directory. deleted old unised xml class
File size: 1.1 KB
RevLine 
[507]1#ifndef __TOKEINZER_H__
2#define __TOKEINZER_H__
3
4#include <string>
5#include <iostream>
6
7/**
8* String tokenizer
9*
10* Splits a given string into several smaller strings
11* using a delmiter (default is the comma).
12* Returns the result as a vector<string> object
13*
14* @autor Nicolas Perrenoud<nicolape@ee.ethz.ch>
15*/
16
17inline std::vector<std::string> tokenize(const std::string& str, const std::string& delimiters = ",")
18{
19        vector<std::string> tokens;
20       
21  // Skip delimiters at beginning.
22  std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
23  // Find first "non-delimiter".
24  std::string::size_type pos     = str.find_first_of(delimiters, lastPos);
25
26  while (std::string::npos != pos || std::string::npos != lastPos)
27  {
28      // Found a token, add it to the vector.
29      tokens.push_back(str.substr(lastPos, pos - lastPos));
30      // Skip delimiters.  Note the "not_of"
31      lastPos = str.find_first_not_of(delimiters, pos);
32      // Find next "non-delimiter"
33      pos = str.find_first_of(delimiters, lastPos);
34  }     
35  return tokens;   
36}
37
38
39#endif
Note: See TracBrowser for help on using the repository browser.