zawiecha klasa boost::escaped_list_separator<char>

0

Problem jest taki że klasa

 boost::escaped_list_separator 

gdy jest używana jest zawiecha programu. Jest to problem kiedy używam znaku #.

inline size_t ReadSectionMap( string line, vector<string> &elem )
{
    boost::escaped_list_separator<char> separator( "#", ",", "\"" );
    boost::tokenizer< boost::escaped_list_separator<char> > tokens(line, separator);
    for( boost::tokenizer< boost::escaped_list_separator<char> >::iterator it = tokens.begin(); it != tokens.end(); it++ )
        elem.push_back( *it );
    return elem.size();
}
0

Debugger?

0

ale może byś podał przykład danych, na których kod się zawiesza?
i wersję BOOSTa.
i kompilatora.

poza tym zamiast tego fora lepiej użyj copy.

0

Dla

boost::char_separator<char>

działa poprawnie

inline size_t ReadSectionMap( string line, vector<string> &elem )
{
    char_separator<char> separator( "#,\\\"" );
    boost::tokenizer< char_separator<char> > tokens(line, separator);
    for( auto it = tokens.begin(); it != tokens.end(); ++it )
        elem.push_back( *it );

    return elem.size();
}

Chociaż rozumiem że nie o taką funkcjonalność Ci chodziło

0

A ten kod jest poprawny?

inline size_t ReadSectionMap( string line, vector<string> &vec, size_t reserve = 0 )
{
    bool b = 0; string str;
    vec.reserve(reserve);
    BOOST_FOREACH( char c, line )
    {
        if( c == '#' && b == 0 ) break;
        if( c == ',' && b == 0 ) { vec.push_back(str); str.clear(); continue; }
        if( c == '\"' ) { if( b == 0 ) b = 1; else b = 0; }
        str.push_back(c);
    }
    vec.push_back(str);
    return vec.size();
}
0

<quote="999241">Dla

boost::char_separator<char>

działa poprawnie

inline size_t ReadSectionMap( string line, vector<string> &elem )
{
    char_separator<char> separator( "#,\\\"" );
    boost::tokenizer< char_separator<char> > tokens(line, separator);
    for( auto it = tokens.begin(); it != tokens.end(); ++it )
        elem.push_back( *it );

    return elem.size();
}
   **źle działa**
1

Pokaż dane na których testujesz.

Kod przez ciebie podany w pierwszym poście działa prawidłowo, tak jak powinien – choć niekoniecznie tak jak się tego spodziewasz.

co do tej pętli for:

    for( auto it = tokens.begin(); it != tokens.end(); ++it )
        elem.push_back( *it );

jak już mówiłem, można skrócić do copy:

copy(tokens.begin(), tokens.end(), back_inserter(elem));

1 użytkowników online, w tym zalogowanych: 0, gości: 1