#include <iostream>
#include <algorithm>
-#include <cctype>
#include <cstring>
#include <map>
#include <vector>
#include <sstream>
+#if defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ )
+# define cpPlugins_STRTOK( A, B, N ) strtok_s( A, B, N )
+#else // defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ )
+# define cpPlugins_STRTOK( A, B, N ) std::strtok( A, B )
+#endif // defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ )
+
// -------------------------------------------------------------------------
typedef std::vector< std::string > TLines;
typedef std::map< char, TLines > TParsedLines;
typedef std::map< std::string, TLines > TVariables;
// -------------------------------------------------------------------------
+bool cpPlugins_ISBLANK( const char& value );
TLines Tokenize( const std::string& str, const std::string& delims );
std::string Replace(
const std::string& str, const std::string& sub, const std::string& nsub
return( 0 );
}
+// -------------------------------------------------------------------------
+bool cpPlugins_ISBLANK( const char& value )
+{
+ return( value == ' ' || value == '\t' || value == '\n' || value == '\r' );
+}
+
// -------------------------------------------------------------------------
TLines Tokenize( const std::string& str, const std::string& delims )
{
TLines tokens;
if( str.size( ) > 0 )
{
- char* buffer = new char[ str.size( ) + 1 ];
- std::strcpy( buffer, str.c_str( ) );
- buffer[ str.size( ) ] = '\0';
- char* it = std::strtok( buffer, delims.c_str( ) );
+ auto ssize = str.size( );
+ char* buffer = new char[ ssize + 1 ];
+ for( unsigned long i = 0; i < ssize; ++i )
+ buffer[ i ] = str[ i ];
+ buffer[ ssize ] = '\0';
+ char* next;
+ char* it = cpPlugins_STRTOK( buffer, delims.c_str( ), &next );
while( it != NULL )
{
tokens.push_back( std::string( it ) );
- it = std::strtok( NULL, delims.c_str( ) );
+ it = cpPlugins_STRTOK( NULL, delims.c_str( ), &next );
} // elihw
delete buffer;
return( false );
std::string buffer;
file_stream.seekg( 0, std::ios::end );
- buffer.reserve( file_stream.tellg( ) );
+ buffer.reserve( ( unsigned int )( file_stream.tellg( ) ) );
file_stream.seekg( 0, std::ios::beg );
buffer.assign(
( std::istreambuf_iterator< char >( file_stream ) ),
auto lIt = line.begin( );
while( lIt != line.end( ) )
{
- if( !std::isblank( *lIt ) )
+ if( !cpPlugins_ISBLANK( *lIt ) )
{
if( cmd_pos == line.end( ) )
{