Example #1
0
int readCha(string &res, stringstream &strIn) {
    res = "";
    char ch;
    while (~(ch = strIn.get()) &&
            (ch == ' ' || ch == '\n' || ch == '\t')) {
        ;
    }
    if (strIn.eof()) return END;
    if (ch == '\'') {
        res += ch;
        strIn >> ch;
        if (strIn.eof()) {
            strIn.putback(ch);
            return ERR;
        }
        if (ch == '\\') {
            res += ch;
            if ((ch = strIn.get()) == -1) return ERR;
            res += ch;
            if ((ch = strIn.get()) == -1 || ch != '\'') {
                return ERR;
            }
            res += ch;
        } else {
            res += ch;
//            cout << ch << endl;
            if ((ch = strIn.get()) == -1 || ch != '\'') {
                return ERR;
            }
            res += ch;
        }
    } else {
Example #2
0
//checked
int readInt(string &fres, stringstream &strIn, bool can = true) {
    if (can)
        fres = "";
    string res = "";
    char ch;
    while (~(ch = strIn.get()) &&
            (ch == ' ' || ch == '\n' || ch == '\t')) {
        ;
    }

    if (strIn.eof()) return END;
    if (ch == '+' || ch == '-' || (ch >= '0' && ch <= '9')) {
        res += ch, fres += ch;
    } else {
        strIn.putback(ch);
        return ERR;
    }
    while (~(ch = strIn.get()) &&
            (ch >= '0' && ch <= '9')) {
        res += ch, fres += ch;
    }
    int st = strIn.eof();

    if (st) {
        if (isdigit(res[0]) || (int)res.size() > 1)
            return OKAY;
        else return ERR;
    }
    strIn.putback(ch);
    if ((int)res.size() == 1 && !isdigit(res[0])) {
        strIn.putback(res[0]);
    }
    return isdigit(res[0]) || (int)res.size() > 1 ? OKAY : ERR;
}
Example #3
0
	int TablePaser::GetColumn(stringstream& ss_str, std::basic_istream<char>& in_put, string& column)
	{
		column = "";
		if (ss_str.eof())
			return -1;
		char cur_char[2];
		cur_char[1] = 0;
		char separator = '	';

		if (ss_str.get(cur_char[0]).eof())
			return 1;
		if (cur_char[0] == '	')
			return 1;
		else if (cur_char[0] == '"')
			separator = '"';
		else
			column += string(cur_char);


		while (1)
		{
			if (ss_str.eof())
			{
				if (separator == '"')
				{
					if (in_put.eof())
						return 0;

					column += string("\n\0");
					ss_str.clear();
					in_put.getline(LineData, LINE_DATA_MAX);
					ss_str << LineData;
				}
				else
					return 0;
			}
			ss_str.getline(LineData, 4096, separator);
			column += LineData;
			//column.append(LineData);
			if (ss_str.eof())
				continue;
			if (separator == '	')
				return 1;
			else if (separator == '"')
			{
				if (ss_str.eof())
					return 0;
				ss_str.get(cur_char[0]);
				if (ss_str.eof())
					return 1;
				else if (cur_char[0] == '	')
					return 1;
				else if (cur_char[0] != separator)
					separator = '	';
				//column.push_back(cur_char);
				column += string(cur_char);
			}
		}
		return -1;
	}
Example #4
0
	Arbin<Pieza> leeArbol(stringstream& ss) {
		Arbin<Pieza> r;		
		if(ss.peek() == 'T') {
			ss.get();
			r = Arbin<Pieza>(leeArbol(ss), Pieza(), leeArbol(ss));
		} else {
			r = Arbin<Pieza>(Arbin<Pieza>(), tablaPiezas.consulta(ss.get()), Arbin<Pieza>());	
		}
	}
Example #5
0
int Util::trim(stringstream &ss)
{
	while(ss.peek()==' ')
		ss.get();
	
	return 0;
}
Example #6
0
int parse_char(stringstream& ss, char& cvar) {
	char c;
	if (!ss.get(c))					// read
		return 1;
	else if (c == '\\') { 			// check for escaped chars
		if (!ss.get(c)) 			// read control char
			return 2;
		switch (c) {
			case '0': 	cvar = '\0'; 		break;
			case 'n': 	cvar = '\n'; 		break;
			case 't': 	cvar = '\t'; 		break;
			case 'b': 	cvar = '\b'; 		break; 		// backspace
			case 'a': 	cvar = '\a'; 		break; 		// beep!
			default: 	cvar = c; 					// just return the character
		}
	}
	else
		cvar = c;
	return 0;
}
Example #7
0
void NetworkRenderer::parse_network_result_output(stringstream &recv_ss) {
    int packet_number;
    recv_ss>>packet_number;
    recv_ss.get();
    std::vector<Color> result;
    while(recv_ss.good()) {

        int ir,ig,ib;
        ir=recv_ss.get();
        ig=recv_ss.get();
        ib=recv_ss.get();

        float r,g,b;
        r=(float)ir/(float)255;
        g=(float)ig/(float)255;
        b=(float)ib/(float)255;
        if(recv_ss.good()) {
            Color c(r,g,b);
            result.push_back(c);
        }

    }
    int height;
    int act_height=CLIENT_TASK_LINES*packet_number;
    if(act_height+CLIENT_TASK_LINES>rendering_height) {
        height=rendering_height-act_height;
    } else {
        height=CLIENT_TASK_LINES;
    }
//    display.add_surface(0,act_height,rendering_width,height,result);
    std::vector<Color> realresult;
    for(int i=0;i<Settings::getAsInt("window_width")*5;i++) {
        realresult.push_back(Color(1,0,0));

    }
    display.add_line_group(0,act_height,realresult);

    Logger::log()<<"Received "<<packet_number<<" of "<<result.size()<<" (height="<<act_height<<")"<<std::endl;
//    display.refresh_part_display_timecheck();
}
Example #8
0
 /// Read one value, whether it is numeric, string or text
 string CIFReadValue(stringstream &in,char &lastc)
 {
   bool vv=false;//very verbose ?
   string value("");
   while(!isgraph(in.peek())) in.get(lastc);
   while(in.peek()=='#')
     {//discard these comments for now
       string tmp;
       getline(in,tmp);
       lastc='\r';
       while(!isgraph(in.peek())) in.get(lastc);
     }
   if(in.peek()=='_') {
     if (vv)
       cout << "WARNING: Trying to read a value but found a new tag !" << endl;
     return value;
   }
   if(in.peek()==';')
     {//SemiColonTextField
       bool warning=!iseol(lastc);
       if(warning)
         cout<<"WARNING: Trying to read a SemiColonTextField but last char is not an end-of-line char !"<<endl;
       value="";
       in.get(lastc);
       while(in.peek()!=';')
         {
           if (in.peek() == '_') {
             cout << "WARNING: Trying to read a SemiColonTextField but found a new tag !" << endl;
             warning = true;
             break;
           }
           string tmp;
           getline(in,tmp);
           value+=tmp+" ";
         }
       if (!warning)
         in.get(lastc);
       if(vv) cout<<"SemiColonTextField:"<<value<<endl;
       if(warning && !vv) cout<<"SemiColonTextField:"<<value<<endl;
       return value;
     }
   if((in.peek()=='\'') || (in.peek()=='\"'))
     {//QuotedString
       char delim;
       in.get(delim);
       value="";
       while(!((lastc==delim)&&(!isgraph(in.peek()))) )
         {
           in.get(lastc);
           value+=lastc;
         }
       if(vv) cout<<"QuotedString:"<<value<<endl;
       return value.substr(0,value.size()-1);
     }
   // If we got here, we have an ordinary value, numeric or unquoted string
   in>>value;
   if(vv) cout<<"NormalValue:"<<value<<endl;
   return value;
 }
Example #9
0
void CIF::Parse(stringstream &in)
{
   bool vv=false;//very verbose ?
   char lastc=' ';
   string block="";// Current block data
   while(!in.eof())
   {
      stringstream mess;
      mess<<"CIF: Parsing:"<<in.tellg();
      (*fpObjCrystInformUser)(mess.str());
      while(!isgraph(in.peek()) && !in.eof()) in.get(lastc);
      if(in.eof()) break;
      if(vv) cout<<endl;
      if(in.peek()=='#')
      {//Comment
         string tmp;
         getline(in,tmp);
         if(block=="") mvComment.push_back(tmp);
         else mvData[block].mvComment.push_back(tmp);
         lastc='\r';
         if(vv)cout<<"Comment:"<<tmp<<endl;
         continue;
      }
      if(in.peek()=='_')
      {//Tag
         string tag,value;
         in>>tag;
         // Convert all dots to underscores to cover much of DDL2 with this DDL1 parser.
         for (string::size_type pos = tag.find('.'); pos != string::npos; pos = tag.find('.', ++ pos))
            tag.replace(pos, 1, 1, '_');
         value=CIFReadValue(in,lastc);
         if(value==string("?")) continue;//useless
         mvData[block].mvItem[ci_string(tag.c_str())]=value;
         if(vv)cout<<"New Tag:"<<tag<<" ("<<value.size()<<"):"<<value<<endl;
         continue;
      }
      if((in.peek()=='d') || (in.peek()=='D'))
      {// Data
         string tmp;
         in>>tmp;
         block=tmp.substr(5);
         if(vv) cout<<endl<<endl<<"NEW BLOCK DATA: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ->"<<block<<endl<<endl<<endl;
         mvData[block]=CIFData();
         continue;
      }
Example #10
0
void readElement(string& readed, stringstream &str) {

    int c;
    do {
        c = str.get();
        if (c != ';') {
            if ((readed.length() != 0) || ((c != 13) && (c != 10))) {
                if (str.good()) {
                    char str[2];
                    str[0] = c;
                    str[1] = '\0';
                    readed += str;
                } else {
                    break;
                }
            }
        }
    } while (c != ';');
}
//Convert a stringstream into a set of words.
void getWords(stringstream& ss) {

	stringstream temp;
	char* word = new char [WORD_SIZE * 10];

	//Filter Chars
	for(int i=0; i<ss.str().length(); i++) {
		temp << filterChars(ss.get());
	}
	//Clear first stream.
	ss.str("");

	//Check words
	while(temp.getline(word, numeric_limits<streamsize>::max(), ' ')) {
		if(filterWords(word)) ss << word << " ";
	}

	delete word;
	return;
}
Example #12
0
int ResourceParser::ReadLine(stringstream& p_stream, vector<string>& p_tokens, int& p_line)
{
	p_tokens.clear();
	size_t i = 0;
	int result = READ_CHUNK;
	char buf[LINE_BUFFER_SIZE];

	for (; i < LINE_BUFFER_SIZE; ++i)
	{
		p_stream.get(buf[i]);

		if (!p_stream.good() || ('\n' == buf[i]))
		{
			buf[i] = '\0';
			++p_line;
			break;
		}

		if (BLOCK_OPENING_BRACES.c_str()[0] == buf[i])
		{
			result = READ_BLOCK_OPEN;
			buf[i + 1] = '\0';
			break;
		}

		if (BLOCK_CLOSING_BRACES.c_str()[0] == buf[i])
		{
			result = READ_BLOCK_CLOSE;
			buf[i + 1] = '\0';
			break;
		}
	}

	char* line = (char*)stringUtils::Trim(buf);

	if ((nullptr == line) || (strlen(line) == 0) || (LINE_COMMENT == line[0]))
		return READ_EMPTY;

	stringUtils::Tokens(line, DELIMITERS, p_tokens);
	return result;
}
Example #13
0
    unsigned int getRule(stringstream& ss, S2Setmap& pt2base, V2Imap& goodman) {
        char c;
        ss >> c;
        assert(c == '(');

        string sym = "";
        ss >> sym;
        unsigned int symI = sym2base[sym];
        //        printf("got symbol %s (%u)\n",sym.c_str(),symI);
        
        vector<unsigned int> kSyms;
        kSyms.push_back(symI);
        
        while(true) {
            c = ss.peek();
            if(c == ' ') { //it's a space
                ss.ignore(1); //ignore that space
            } else if(c == '(') { //nonterminal
                //get child node index
                unsigned int index = getRule(ss,pt2base,goodman);
                kSyms.push_back(index);                
            } else if (c == ')') {
                ss.ignore(1); //burn closing paren
                //      printf("Finished Rule with sym %s and %lu kids\n",sym.c_str(),kSyms.size()-1);
                unsigned int index = 0; 
                
                while(kSyms.size() > 3) { //try to add glue rule
                    //  printf("K = %lu\n",kSyms.size());
                    unsigned int r = kSyms.back();
                    kSyms.pop_back();
                    unsigned int l = kSyms.back();
                    kSyms.pop_back();

                    unsigned int glueI = nSym*2;
                    
                    vector<unsigned int> gluerule;
                    gluerule.push_back(glueI);//glue symbol
                    gluerule.push_back(l);
                    gluerule.push_back(r);

                    unsigned int glueindex = 0; 
                    V2Imap::iterator fter = goodman.find(gluerule);
                    if(fter == goodman.end()) { //new node
                        goodman[gluerule] = goodmanIndex;
                        baseSym.push_back(glueI);
                        glueindex = goodmanIndex;

                        canL.push_back(false);
                        canR.push_back(false);
                        
                        canL[l] = true;
                        canR[r] = true;

                        leftlook[l].push_back(make_pair(r,goodmanIndex));
                        
                        bmap[make_pair(l,r)].insert(goodmanIndex);
                        
                        goodmanIndex++;
                    } else { //seen it
                        glueindex = fter->second;
                    }
                    kSyms.push_back(glueindex);
                }

                V2Imap::iterator fter = goodman.find(kSyms);
                if(fter == goodman.end()) { //new node
                    goodman[kSyms] = goodmanIndex;
                    baseSym.push_back(symI);
                    index = goodmanIndex;

                    canL.push_back(false);
                    canR.push_back(false);
                    
                    goodmanIndex++;

                    if(kSyms.size() == 3) {
                        //add index -> l r
                        //    printf("BR : %u -> %u %u\n",index,kSyms[1],kSyms[2]);
                        canL[kSyms[1]] = true;
                        canR[kSyms[2]] = true;
                        leftlook[kSyms[1]].push_back(make_pair(kSyms[2],index));
                        bmap[make_pair(kSyms[1],kSyms[2])].insert(index);
                    } else { //one child
                        //add index -> k
                        umap[kSyms[1]].insert(index);
                        //printf("UR : %u -> %u\n",index,kSyms[1]);
                    }
                    
                } else { //seen it
                    index = fter->second;
                }
                                
                return index;
            } else { //terminal
                string term = "";
                while(ss.peek() != ')') {
                    term += ss.get();
                }
                //                printf("got terminal %s\n",term.c_str());
                ss.ignore(1); //burn closing paren

                unsigned int index = 0;
                if(term == "<>") { //nonterminal leaf
                    index = sym2base[sym];
                } else { //preterminal node
                    //get index and add
                    //printf("T:%s\n",term.c_str());
                    S2Setmap::iterator fter = pt2base.find(term);

                    ptsyms.insert(symI);
                    
                    if(fter != pt2base.end()) {//seen this terminal before
                        set<unsigned int>& bsymset = fter->second; //the base syms that have been seen to parse this terminal
                        
                        if(bsymset.find(symI) == bsymset.end()) { //never found this pterm rule before
                            preterms[term].insert(goodmanIndex);
                            index = goodmanIndex;
                            baseSym.push_back(symI);
                            ++goodmanIndex;
                            canL.push_back(false);
                            canR.push_back(false);
                        
                            bsymset.insert(symI);
                        } else {
                            //this is a small set...maybe an unideal implementation tho
                            set<unsigned int>& symset = preterms[term];
                            for(set<unsigned int>::iterator iter = symset.begin();iter != symset.end();++iter) {
                                if(baseSym[*iter] == symI)
                                    index = *iter;
                            }
                        }
                    } else {
                        preterms[term].insert(goodmanIndex);
                        index = goodmanIndex;
                        baseSym.push_back(symI);
                        canL.push_back(false);
                        canR.push_back(false);
                        ++goodmanIndex;
                 
                        set<unsigned int> bsymset;
                        bsymset.insert(symI);
                        pt2base[term] = bsymset;
                    }
                }
                //                printf("returning %u - %u\n",index,goodmanIndex);
                return index;
            }
        }
        
        return 1;
    }
Example #14
0
int readFloat(string &res, stringstream &strIn) {
//    cout << strIn.str() << endl;
    res = "";
    char ch;
    while (~(ch = strIn.get()) &&
            (ch == ' ' || ch == '\n' || ch == '\t')) {
        ;
    }
    if (strIn.eof()) return END;
    if (ch != '.' && ch != '+' && ch != '-' && !(ch <= '9' && ch >= '0')) {
        return ERR;
    }
    if (ch == '.') {
        res += ch;
        if ((ch = strIn.get()) == -1 || !isdigit(ch)) {

            if (!strIn.eof()) {
                strIn.putback(ch);
            }
            strIn.putback(res[0]);
            return ERR;
        } else {
//        cout << res << endl;
            strIn.putback(ch);
//            cout << ch << endl;
            readInt(res, strIn, false);
//            cout << res << endl;
            if ((ch = strIn.get()) == -1 || ch != 'e') {
                if (!strIn.eof()) {
                    strIn.putback(ch);
                }
                return OKAY;
            } else {
                res += ch;
                if ((ch = strIn.get()) == -1 || !(ch == '+' || ch == '-' || isdigit(ch))) {
                    return ERR;
                } else {
                    strIn.putback(ch);
                    if (readInt(res, strIn, false) == ERR) return ERR;
                }
            }
        }
    } else if (isdigit(ch)) {
        strIn.putback(ch);
        readInt(res, strIn, false);

        if ((ch = strIn.get()) == -1 || ch != '.') {

            if (ch != 'e') {

                if (ch != -1)
                    strIn.putback(ch);
                Revc(res, strIn);
                return ERR;
            } else {
                res += ch;
                if ((ch = strIn.get()) == -1 || !(ch == '+' || ch == '-' || isdigit(ch))) {
                    return ERR;
                } else {
                    strIn.putback(ch);
                    if (readInt(res, strIn, false) == ERR) return ERR;
                }
            }

        } else {
            res += ch;
            if ((ch = strIn.get()) == -1) {
                return OKAY;
            } else if (isdigit(ch)) {
                strIn.putback(ch);
                readInt(res, strIn, false);
                if ((ch = strIn.get()) == -1 || ch != 'e') {
                    if (!strIn.eof())strIn.putback(ch);
                    return OKAY;
                } else {
                    res += ch;
                    if ((ch = strIn.get()) == -1 || !(ch == '+' || ch == '-' || isdigit(ch))) {
                        return ERR;
                    } else {
                        strIn.putback(ch);
                        if (readInt(res, strIn, false) == ERR) return ERR;
                    }
                }
            } else if (ch == 'e') {
                res += ch;
                if ((ch = strIn.get()) == -1 || !(ch == '+' || ch == '-' || isdigit(ch))) {
                    return ERR;
                } else {
                    strIn.putback(ch);
                    if (readInt(res, strIn, false) == ERR) return ERR;
                }
            } else {
                strIn.putback(ch);
                return OKAY;
            }
        }
    } else {

    }
    return OKAY;
}