/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Generator/GeneratorUtil/GeneratorUtil-00-00-03/src/StringParse.cxx

Go to the documentation of this file.
00001 // --------------------------------------------------
00002 // 
00003 // File:  GeneratorUtil/StringParse.cxx
00004 // Description:
00005 //    This code is used to parse a string .
00006 //    it breaks it into components which are seperated by spaces 
00007 //    in the original. The components can be accessed and converted to doubles or ints
00008 // AuthorList:
00009 //         Ian Hinchliffe April 2000
00010 #include "GeneratorUtil/StringParse.h"
00011 #include <string>
00012 #include <vector>
00013 #include <iostream>
00014 #include <math.h>
00015 #include <stdlib.h>
00016 
00017 StringParse::StringParse(std::string input) {
00018   m_past_end="?!?";
00019   m_lstring=input;
00020   m_nword=0;
00021   std::string::size_type pos=0;
00022   std::string::size_type prev_pos=0;
00023   while((pos=input.find_first_of(' ',pos)) != std::string::npos){
00024       m_lsubstring.push_back(input.substr(prev_pos,pos-prev_pos));
00025       prev_pos=++pos;
00026     }
00027     // special handling for last substring
00028     m_lsubstring.push_back(input.substr(prev_pos,pos-prev_pos));
00029   m_nword=m_lsubstring.size();
00030 }
00031 std::string StringParse::piece(const int &num){
00032   if(num <= m_nword){
00033     return m_lsubstring[num-1];
00034   }
00035   else { 
00036     return m_past_end;
00037   }
00038 }
00039 int StringParse::intpiece(const int & num){  
00040 if(num <= m_nword){
00041      int i= atoi(m_lsubstring[num-1].c_str());
00042      return i;
00043   }
00044   else { 
00045     return -1;
00046   }
00047 }
00048 long StringParse::longpiece(const int & num){  
00049 if(num <= m_nword){
00050      int i= atol(m_lsubstring[num-1].c_str());
00051      return i;
00052   }
00053   else { 
00054     return -1;
00055   }
00056 }
00057 float StringParse::numpiece(const int & num){  
00058 if(num <= m_nword){
00059      float x= atof(m_lsubstring[num-1].c_str());
00060      return x;
00061   }
00062   else { 
00063     return -1.1;
00064   }
00065 }
00066 StringParse::~StringParse(){
00067 }
00068 
00069 

Generated on Tue Nov 29 23:12:39 2016 for BOSS_7.0.2 by  doxygen 1.4.7