#include "common.h"

void stripstr( std::string &str )
{
  unsigned int start;
  unsigned int end;
  start = 0;
  end = str.size();
  for( unsigned i = 0; i < str.size() && 
         ( str[i] == ' ' || str[i] == '\n' ||str[i] == '\t' ); i++ )
    start ++;
  for( unsigned i = str.size()-1; i >= start && 
         ( str[i] == ' ' || str[i] == '\n' ||str[i] == '\t' ); i-- )
    end--;
  std::string p;
  p = str.substr( start, end-start );
  str = p;
}

int converttoint( std::string str, std::vector<int> &v )
{
  char *tt;
  char *buffer;
  v.clear();
  buffer = new char[str.size()+1];
  memcpy( buffer, str.c_str(), str.size() );
  buffer[ str.size() ] = 0;
  tt = strtok( buffer, " " );
  while( tt != NULL )
    {
      int num;
      num = strtol( tt, NULL, 10 );
      v.push_back(num);
      tt = strtok( NULL, " ");
    }
  delete [] buffer;
  return 0;
}

int converttodouble( std::string str, std::vector<double> &v )
{
  char *tt;
  char *buffer;
  v.clear();
  buffer = new char[str.size()+1];
  memcpy( buffer, str.c_str(), str.size() );
  buffer[ str.size() ] = 0;
  tt = strtok( buffer, " " );
  while( tt != NULL )
    {
      double num;
      num = strtod( tt, NULL );
      v.push_back(num);
      tt = strtok( NULL, " ");
    }
  delete [] buffer;
  return 0;
}
