CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2009
    Posts
    118

    Question tokenizing a string made of "only" seperator characters

    Hi All,

    Following function utilizing boost's string tokenizer class crashes as might be expected:

    Code:
    bool CheckCommand(const string& cmd, const string& line)
    {
    	if (line.length() == 0)
    		return false;
    
    	typedef tokenizer< char_separator<char> > StrTokenizer;
    	char_separator<char> sep(":");
    	StrTokenizer tokens(line, sep);
    	StrTokenizer::iterator it = tokens.begin();
    
    	if (*it == cmd) { <<<<--------------- Crash takes place at this line
    	    ++it;
    	    if (it != tokens.end()) {
    	        return true;
            }
        }
    
    	return false;
    }
    when line is "::::::::::::::::::::", i.e. made of merely separator characters (":").

    How can I check
    Code:
    StrTokenizer::iterator it
    actually points to something meaningful to prevent this crash ?

    Thanks.

  2. #2
    Join Date
    Oct 2008
    Posts
    1,456

    Re: tokenizing a string made of "only" seperator characters

    Code:
    if ( it != tokens.end() && *it == cmd )
    bye!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured