Ejemplo n.º 1
14
static bool extractEnd(std::istringstream &strm, std::string &end)
{
	std::stringbuf temp;
	strm.get(temp);
	end = temp.str();
	return !strm.fail();
}
Ejemplo n.º 2
3
/// directly sends the quoted text to oss
/// and returns if a quote was found
/// empties the given buffer in to oss if one is given
/// works only if a quote char is found where the iss cursor is.
bool JLDIO::skipOverQuotes(std::ostringstream& oss, std::istringstream& iss, std::list<char> *bufferToEmpty)
{
    char charBuffer = iss.peek();
    if(charBuffer == '\'' || charBuffer == '\"')
    {
        if(bufferToEmpty && !bufferToEmpty->empty())
        {
            oss << listToString(*bufferToEmpty);
            bufferToEmpty->clear();
        }
        // std::cout<<"Skipping: ";
        char matchedChar = charBuffer;
        iss.get(charBuffer);
        assert(matchedChar == charBuffer);
        do
        {
            oss << charBuffer;
            // std::cout<<charBuffer;
        } while(iss.get(charBuffer) && charBuffer != matchedChar);
        if(iss.good())
            oss << charBuffer;
        // std::cout<<charBuffer<<"\n";
        return true;
    }
    return false;
}
Ejemplo n.º 3
2
void factor( std::istringstream &ss, char &lookahead ) {
    if ( isDigit {}( lookahead ) ){
        int value = 0;
        do {
            value = value * 10 + ToDigit {}( lookahead );
            lookahead = ss.get();
        } while ( !ss.eof() && isDigit {} ( lookahead ) );
        print ( value );
    } else if ( lookahead == '(' ) {
        match ( ss, lookahead, '(' );
        expr( ss, lookahead );
        if( lookahead != ')' ){
            throw fail { "Expected a closing parenthesis before end of line." };
        }
        match ( ss, lookahead, ')' );
    } else if ( isWhiteSpace {} ( lookahead ) ) {
        for (;; lookahead = ss.get() ){
            if( isWhiteSpace {}( lookahead ) ) continue;
            else break;
        }
    } else {
        std::cerr << "Syntax Error: expecting a digit, got '" << lookahead << "' instead." << std::endl;
        abort();
    }
}
Ejemplo n.º 4
1
bool ossimWkt::parseObject( std::istringstream& is,
                            const std::string& prefix,
                            const std::string& object,
                            ossimKeywordlist& kwl )
{
    bool result = false;

    result = parseName( is, prefix, object, kwl );

    if ( result && is.good() )
    {
        char c;
        ossim_uint32 myObjectIndex = 0;
        ossim_uint32 paramIndex = 0;
        while ( is.good() )
        {
            is.get(c);
            if ( is.good() )
            {
                if ( c == ',' )
                {
                    parseParam( is, prefix, object, myObjectIndex, paramIndex, kwl );
                }
                else if ( (c == ']') || (c == ')') )
                {
                    break; // End of object.
                }
            }
        }

    }

    return result;
}
Ejemplo n.º 5
0
bool ossimWkt::parseName( std::istringstream& is,
                          const std::string& prefix,
                          const std::string& object,
                          ossimKeywordlist& kwl )
{
    bool result = false;
    char c;
    std::string name;

    // Find the first quote:
    while ( is.good() )
    {
        is.get(c);
        if ( is.good() )
        {
            if ( c == '"' )
            {
                break;
            }
        }
    }

    // Get the name:
    while ( is.good() )
    {
        is.get(c);
        if ( is.good() )
        {
            if ( c != '"' )
            {
                name.push_back(c);
            }
            else
            {
                break; // End quote:
            }
        }
    }

    if ( name.size() )
    {
        // Add to keyword list.
        std::string key;
        if ( prefix.size() )
        {
            key += prefix;
        }
        key += object;
        key += ".name";
        kwl.addPair( key, name );
        result = true;
    }

    return result;
}
Ejemplo n.º 6
0
void match ( std::istringstream &ss, char &lookahead, const char &currToken ) noexcept
{
    if ( lookahead == currToken ){
        lookahead = ss.get();
        if( isWhiteSpace {}( lookahead ) ){
            for(;; lookahead = ss.get() ){
                if(isWhiteSpace {}( lookahead ) ) continue;
                else break;
            }
        }
    }
    //otherwise we have an epsilon production
}
void LoadArray(std::istringstream &buf, pnlVector<Type> &array, char delim = ' ')
{
    char ch;
    int ich;
    Type val;

    buf >> ch;
    ASSERT(ch == '[' || !buf.good());
    array.reserve(16);
    array.resize(0);
    for(;buf.good();)
    {
        do
        {
            ich = buf.peek();
            if(ich == ']')
            {
                buf >> ch;
                return;
            }
            else if(ich == delim || (delim == ' ' && isspace(ich)))
            {
                buf.get(ch);
            }
        } while(buf.good() && (ich == delim || (delim == ' ' && isspace(ich))));

	if(!buf.good())
	{
	    break;
	}

        buf >> val;
        array.push_back(val);
    }
Ejemplo n.º 8
0
/**
 * Read from input title and insert spaces into the title vector
 * @param iss       input stream
 * @param word      space word to insert
 * @param title     vector where to store the words
 */
void insert_spaces( std::istringstream& iss, std::string& word, std::vector<std::string>& title ){
  while( iss.peek() == ' ' ){
    iss.get();
    word += ' ';
  }
  if ( !word.empty() )
    title.push_back( std::move(word) );
}
Ejemplo n.º 9
0
/// moves the iss's cursor to the next non-WS char
bool JLDIO::ignoreWhiteSpace(std::istringstream& iss)
{
    char charBuffer = iss.peek();
    bool output = false;
    while(std::isspace(charBuffer))
    {
        iss.get(charBuffer);
        charBuffer = iss.peek();
        output = true;
    }
    return output;
}
void skipCharacter(std::istringstream& is, char char_to_skip)
{
    for (;;) {
        int c = is.get();
        if ( !is.good() ) {
            break;
        } else {
            if (c != char_to_skip) {
                is.unget();
                break;
            }
        }
    }
}
Ejemplo n.º 11
0
bool JLDIO::moreItems(std::istringstream& iss, char delim)
{
    char charBuffer;
    ignoreWhiteSpace(iss);
    if(iss.peek() == ',')
    {
        iss.get(charBuffer);
        return true;
    }
    else if(iss.peek() != delim)
    {
        std::cout<<"Expected '"<<delim<<"' but found '"<<(char)iss.peek()<<"'\n";
        assert(0 && "Unexpected char");
    }
    return false;
}
Ejemplo n.º 12
0
void rest_2( std::istringstream &ss, char &lookahead )
{
    while( !ss.eof() ){
        char tempToken = lookahead;
        if( lookahead == '*' ) {
            match( ss, lookahead, '*' );
            factor( ss, lookahead );
            print( tempToken );
        } else if ( lookahead == '/' ) {
            match ( ss, lookahead, '/' );
            factor( ss, lookahead );
            print( '/' );
        } else if ( isWhiteSpace {}( lookahead ) ) {
            for(;; lookahead = ss.get() ){
                if( isWhiteSpace {}( lookahead ) ) continue;
                else break;
            }
        } else {
            break;
        }
    }
}
Ejemplo n.º 13
0
void rest( std::istringstream &ss, char &lookahead )
{
    while( !ss.eof() ) {
        char tempToken = lookahead;
        if ( lookahead == '+' ) {
            match( ss, lookahead, '+' );
            term ( ss, lookahead );
            print( tempToken );
            rest( ss, lookahead );
        } else if ( lookahead == '-' ) {
            match( ss, lookahead, '-' );
            term( ss, lookahead );
            print( tempToken );
            rest( ss, lookahead );
        } else if ( isWhiteSpace {} ( lookahead ) ) {
            for(;; lookahead = ss.get() ){
                if( isWhiteSpace {}( lookahead ) ) continue;
                else break;
            }
        } else {
            break; //we have an epsilon production
        }
    }
}
Ejemplo n.º 14
0
bool ossimWkt::parseWktGroup( std::istringstream& is, ossimKeywordlist& kwl )
{
    bool result = false;

    if ( is.good() )
    {
        char c;

        // Get the wkt group name up to '[', e.g. "PROJCS[".
        std::string prefix = "";
        std::string object;
        // std::string v;
        while ( is.good() )
        {
            is.get(c);
            if ( is.good() )
            {
                // Look for parens or square brackets.
                if ( (c != '[') && (c != '(') )
                {
                    object.push_back(c);
                }
                else
                {
                    result = parseObject( is, prefix, object, kwl );
                }
            }
            else
            {
                break;
            }
        }
    }

    return result;
}
Ejemplo n.º 15
0
bool HttpResponse::parse_header_content(std::istringstream &istr)
{
		static const int eof = std::char_traits<char>::eof();
		int ch = istr.get();

		while (ch != eof && ch != '\r' && ch != '\n')
		{
				std::string name;
				std::string value;
				while (ch != eof && ch != ':' && name.length() < MAX_NAME_LENGTH) 
				{ 
						name += ch; 
						ch = istr.get(); 
				}

				if (ch != ':') return false;

				if (ch != eof) ch = istr.get(); // ':'

				while (isspace(ch)) ch = istr.get();

				while (ch != eof && ch != '\r' && ch != '\n' && value.length() < MAX_VALUE_LENGTH)
				{ 
						value += ch; 
						ch = istr.get(); 
				}

				if (ch == '\r') ch = istr.get();

				if (ch == '\n') 
				{
						ch = istr.get();
				}else if(ch != eof)
				{
						return false;
				}

				while (ch == ' ' || ch == '\t') // folding
				{
						while (ch != eof && ch != '\r' && ch != '\n' && value.length() < MAX_VALUE_LENGTH)
						{ 
								value += ch; 
								ch = istr.get(); 
						}

						if (ch == '\r')
						{
								ch = istr.get();
						}

						if (ch == '\n')
						{
								ch = istr.get();

						}else if (ch != eof)
						{
								return false;
						}
				}
				m_nv_map[name] =  value;
		}
		istr.putback(ch);

		return true;
}
Ejemplo n.º 16
0
bool ossimWkt::parseParam( std::istringstream& is,
                           const std::string& prefix,
                           const std::string& object,
                           ossim_uint32& objectIndex,
                           ossim_uint32& paramIndex,
                           ossimKeywordlist& kwl )
{
    bool result = false;
    char c;
    std::string name;

    // Get the name:
    while ( is.good() )
    {
        int i = is.peek(); // Don't gobble the trailing comma or bracket.

        if ( (i == ',') || (i == ']') || (i == ')') )
        {
            // End of param.
            if ( name.size() )
            {
                // Add to keyword list.
                std::string key;
                if ( prefix.size() )
                {
                    key += prefix;
                }
                key += object;
                key += ".param";
                key += ossimString::toString(paramIndex).string();
                kwl.addPair( key, name );
                name = "";
                ++paramIndex;
                result = true;
            }

            break; // Next param or at end of object.
        }

        is.get(c);
        if ( is.good() )
        {
            // Look nexted object.
            if ( (c == '[') || (c == '(') )
            {
                std::string myPrefix;
                if ( prefix.size() )
                {
                    myPrefix += prefix;
                }

                myPrefix += object;

                myPrefix += ".";

                //---
                // Special hack for duplicated keyword "PARAMETER"
                //---
                if ( name == "PARAMETER" )
                {
                    name += ossimString::toString(objectIndex).string();
                    ++objectIndex;
                }

                result = parseObject( is, myPrefix, name, kwl );

                name = "";
            }
            else
            {
                name.push_back(c);
            }
        }
    }

    return result;
}
Ejemplo n.º 17
0
 bool at_end()
 {
     int c = stream.get();
     stream.unget();
     return c == EOF;
 }
Ejemplo n.º 18
0
 int getc()
 {
     return stream.get();
 }
Ejemplo n.º 19
0
bool HttpResponse::Parse(std::istringstream &istr)
{
		static const int eof = std::char_traits<char>::eof();

		std::string version;
		std::string status;
		std::string reason;

		int ch =  istr.get();
		while (isspace(ch))
		{
				ch = istr.get();
		}

		if (ch == eof) return false;

		while (!isspace(ch) && ch != eof && version.length() < MAX_VERSION_LENGTH) 
		{
				version += (char) ch; 
				ch = istr.get(); 
		}

		if (!isspace(ch)) return false;


		while(isspace(ch))
		{
				ch = istr.get();
		}

		while (!isspace(ch) && ch != eof && status.length() < MAX_STATUS_LENGTH) 
		{ 
				status += (char) ch;
				ch = istr.get(); 
		}

		if (!isspace(ch)) return false;

		while (isspace(ch)) ch = istr.get();


		while (ch != '\r' && ch != '\n' && ch != eof && reason.length() < MAX_REASON_LENGTH) 
		{ 
				reason += (char) ch; 
				ch = istr.get(); 
		}

		if (!isspace(ch)) return false;

		if (ch == '\r')	ch = istr.get();


		if(!parse_header_content(istr)) return false;

		ch = istr.get();

		while (ch != '\n' && ch != eof)
		{
				ch = istr.get();
		}
		m_version = version;
		m_status = status;
		m_reason = reason;

		
		return true;

}
Ejemplo n.º 20
0
/// gets the next char from iss and places it in output
/// bypasses characters in quotes
/// empties the given buffer in to oss before hand if possible
/// returns false upon failure (i.e. returns iss.good())
bool JLDIO::getNextChar(char& output, std::ostringstream& oss, std::istringstream& iss, std::list<char> *bufferToEmpty)
{
    skipOverQuotes(oss, iss, bufferToEmpty);
    iss.get(output);
    return iss.good();
}