void val(const adstring& s, int& v, int& code) { int z; if ( (s.size() > 2) && (s(1,2) == adstring("0x") )) z = sscanf((const char*)s,"%x",&v); else z = sscanf((const char*)s,"%d",&v); if (z != 1) code = 1; else code = 0; }
/** * Parse the string str1 as an index block. * String str1 must start with "[" and end with "]". * Individual ranges are separated using a semi-colon (";"). * Individual ranges have the form "x:y" or "x". * * An example is "[1962:2000;2005;-1:1959]". In this example, the * "-1" would be replaced by the specified minimum range for the block. * * @param str1 - adstring to parse */ void IndexBlock::parse(adstring str1){ if (debug) cout<<"Parsing '"<<str1<<"'"<<endl; if (!(str1(1,1)=="[")) { cout<<"Error parsing index block '"<<str1<<"'."<<endl; cout<<"Expected 1st character to be '[' but got '"<<str1(1,1)<<endl; cout<<"Aborting..."<<endl; exit(-1); } adstring str2 = str1(2,str1.size()-1); int k = 0; int p=str2.pos(";"); if (debug) cout<<"k,p,str = "<<k<<tb<<p<<tb<<str2<<endl; while(p){ k++; str2 = str2(p+1,str2.size()); p = str2.pos(";"); if (debug) cout<<"k,p,str = "<<k<<tb<<p<<tb<<str2<<endl; } k++; if (debug) cout<<"Found "<<k<<" intervals"<<endl; nRCs = k; str2 = str1(2,str1.size()-1); ppIRs = new IndexRange*[nRCs]; for (k=1;k<nRCs;k++){ p = str2.pos(";"); ppIRs[k-1] = new IndexRange(modMin,modMax); ppIRs[k-1]->parse(str2(1,p-1)); str2 = str2(p+1,str2.size()); } ppIRs[nRCs-1] = new IndexRange(modMin,modMax); ppIRs[nRCs-1]->parse(str2); if (debug) { cout<<"IndexBlock = "<<(*this)<<endl; cout<<"Enter 1 to contiinue > "; cin>>debug; } createIndexVectors(); }
int val(const adstring& s) { int code; int v; int z; if ( (s.size() > 2) && (s(1,2) == adstring("0x") )) z = sscanf((const char*)s,"%x",&v); else z = sscanf((const char*)s,"%d",&v); if (z != 1) code = 1; else code = 0; return v; }
/** * Parse a range string ("x:y" or "y") to obtain actual min, max for range. * If result finds x (y) < 0, then x (y) will be substituted using * if x<0, x = modMin+1+x (so x=-1->x=modMin, x=-2->x=modMin-1, etc) * if y<0, y = modMax-1-y (so y=-1->y=modMax, y=-2->y=modMax+1, etc) * @param str */ void IndexRange::parse(adstring str){ if (debug) cout<<"IndexRange parse("<<str<<")"<<endl; int i = str.pos(":"); if (debug) cout<<"':' located at position "<<i<<endl; if (i){ mn = ::atoi(str(1,i-1)); if (mn<0){mn=modMin+1+mn;} else if (mn<modMin){mn=modMin;} else if (mn>modMax){mn=modMax;} mx = ::atoi(str(i+1,str.size())); if (mx<0){mx=modMax-1-mx;} else if (mx<modMin){mx=modMin;} else if (mx>modMax){mx=modMax;} } else { mx = ::atoi(str); if (mx<0){mx=modMax-1-mx;} else if (mx<modMin){mx=modMin;} else if (mx>modMax){mx=modMax;} mn=mx; } if (debug) cout<<"mn,mx = "<<mn<<cc<<mx<<endl; createRangeVector(mn,mx); }