1 #include <cpPlugins/OS/String.h>
4 // -------------------------------------------------------------------------
5 #ifdef cpPlugins_OS_Windows
6 # define cpPlugins_STRTOK( A, B, N ) strtok_s( A, B, N )
7 #else // cpPlugins_OS_Windows
8 # define cpPlugins_STRTOK( A, B, N ) std::strtok( A, B )
9 #endif // cpPlugins_OS_Windows
11 // -------------------------------------------------------------------------
12 std::vector< std::string > cpPlugins::OS::String::
13 Tokenize( const std::string& str, const std::string& delims )
15 std::vector< std::string > tokens;
18 auto ssize = str.size( );
19 char* buffer = new char[ ssize + 1 ];
20 for( unsigned long i = 0; i < ssize; ++i )
21 buffer[ i ] = str[ i ];
22 buffer[ ssize ] = '\0';
24 char* it = cpPlugins_STRTOK( buffer, delims.c_str( ), &next );
27 tokens.push_back( std::string( it ) );
28 it = cpPlugins_STRTOK( NULL, delims.c_str( ), &next );