mesh_conv::MC_string_tokenizer Class Reference

Helper class to tokenize easily a string. More...

#include <MC_string_helper.hpp>

List of all members.

Static Public Member Functions

static std::vector< std::string > tokenize (const std::string &str, const std::string &delimiters=" ")
 tokenize a given string

Detailed Description

Helper class to tokenize easily a string.

Definition at line 133 of file MC_string_helper.hpp.


Member Function Documentation

std::vector< std::string > mesh_conv::MC_string_tokenizer::tokenize ( const std::string &  str,
const std::string &  delimiters = " " 
) [static]

tokenize a given string

Returns:
the vector of string tokenized
Parameters:
str the input string
delimiters the delimiter between the string ("," ";" " " ...), default is empty space

exemple std::vector <std::string> mesh_conv::MC_string_tokenizer.tokenize(std::string("4.5,87.1,10"),",");

Definition at line 13 of file MC_string_helper.cpp.

Referenced by mesh_conv::MC_matrix::analyse_string(), mesh_conv::MC_mesh_index_vector_draw::load_mesh_file(), mesh_conv::MC_mesh_index_vector::load_mesh_file(), mesh_conv::MC_double_vector::MC_double_vector(), mesh_conv::MC_int_vector::MC_int_vector(), mesh_conv::MC_v3d::MC_v3d(), mesh_conv::MC_v4d::MC_v4d(), mesh_conv::operator>>(), mesh_conv::MC_io_obj::read_obj(), mesh_conv::MC_io_obj::read_obj_texture(), mesh_conv::MC_io_off::read_off(), mesh_conv::MC_curve::read_vect(), and mesh_conv::MC_matrix::transformation().

00014   {
00015     std::vector<std::string> tokens;
00016     std::string::size_type delimPos = 0, tokenPos = 0, pos = 0;
00017     
00018     if(str.length()<1)  return tokens;
00019     while(1){
00020       delimPos = str.find_first_of(delimiters, pos);
00021       tokenPos = str.find_first_not_of(delimiters, pos);
00022       
00023       if(std::string::npos != delimPos){
00024         if(std::string::npos != tokenPos){
00025           if(tokenPos<delimPos){
00026             tokens.push_back(str.substr(pos,delimPos-pos));
00027           }else{
00028             tokens.push_back("");
00029           }
00030         }else{
00031           tokens.push_back("");
00032         }
00033         pos = delimPos+1;
00034       } else {
00035         if(std::string::npos != tokenPos){
00036           tokens.push_back(str.substr(pos));
00037         } else {
00038           tokens.push_back("");
00039         }
00040         break;
00041       }
00042     }
00043     return tokens;
00044   }


The documentation for this class was generated from the following files:

Generated on Sun Apr 18 20:24:48 2010 by  doxygen 1.6.1