BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
StringParse.cxx
Go to the documentation of this file.
1// --------------------------------------------------
2//
3// File: GeneratorUtil/StringParse.cxx
4// Description:
5// This code is used to parse a string .
6// it breaks it into components which are seperated by spaces
7// in the original. The components can be accessed and converted to doubles or ints
8// AuthorList:
9// Ian Hinchliffe April 2000
11#include <string>
12#include <vector>
13#include <iostream>
14#include <math.h>
15#include <stdlib.h>
16
17StringParse::StringParse(std::string input) {
18 m_past_end="?!?";
19 m_lstring=input;
20 m_nword=0;
21 std::string::size_type pos=0;
22 std::string::size_type prev_pos=0;
23 while((pos=input.find_first_of(' ',pos)) != std::string::npos){
24 m_lsubstring.push_back(input.substr(prev_pos,pos-prev_pos));
25 prev_pos=++pos;
26 }
27 // special handling for last substring
28 m_lsubstring.push_back(input.substr(prev_pos,pos-prev_pos));
29 m_nword=m_lsubstring.size();
30}
31std::string StringParse::piece(const int &num){
32 if(num <= m_nword){
33 return m_lsubstring[num-1];
34 }
35 else {
36 return m_past_end;
37 }
38}
39int StringParse::intpiece(const int & num){
40if(num <= m_nword){
41 int i= atoi(m_lsubstring[num-1].c_str());
42 return i;
43 }
44 else {
45 return -1;
46 }
47}
48long StringParse::longpiece(const int & num){
49if(num <= m_nword){
50 int i= atol(m_lsubstring[num-1].c_str());
51 return i;
52 }
53 else {
54 return -1;
55 }
56}
57float StringParse::numpiece(const int & num){
58if(num <= m_nword){
59 float x= atof(m_lsubstring[num-1].c_str());
60 return x;
61 }
62 else {
63 return -1.1;
64 }
65}
67}
68
69
Double_t x[10]
int intpiece(const int &num)
Definition: StringParse.cxx:39
float numpiece(const int &num)
Definition: StringParse.cxx:57
std::string piece(const int &num)
Definition: StringParse.cxx:31
long longpiece(const int &num)
Definition: StringParse.cxx:48
int num[96]
Definition: ranlxd.c:373