Пример #1
0
 std::string&
 POVRayParser::GetWholeObject(std::string& inputText, std::ifstream& file)
 {
    //check how many brackets we're dealing with from the input
    int nonMatchedBrackets = 0;
    std::string::const_iterator it(inputText.begin());
    for (; it != inputText.end(); ++it) {
       if (*it == '{') ++nonMatchedBrackets;
       else if (*it == '}') --nonMatchedBrackets;
    }
    BOOST_ASSERT(nonMatchedBrackets >= 0);
    //grab file text and store it in inputText until we get fully matched brackets
    std::string line;
    inputText += " "; //just to make sure we've got plenty white space
    while (nonMatchedBrackets > 0 && std::getline(file, line)) {
       RemoveComment(line);
       line += " "; //add white space where the \n was.
       it = line.begin();
       for (; it != line.end() && nonMatchedBrackets > 0; ++it) {
          inputText += *it;
          if (*it == '{') ++nonMatchedBrackets;
          else if (*it == '}') --nonMatchedBrackets;
          BOOST_ASSERT(nonMatchedBrackets >= 0);
       }
    }
    return inputText;
 }
Пример #2
0
bool DataFile::LoadDataFile(BString filename)
////////////////////////////////////////////////////////////////////////
{
	BString line;
	int	sign;		// itt van az '=' jel
	int len;
	BString key;
	BString value;

	if (Read(filename))
	{
		while (GetLine(line))
		{
			RemoveComment(line);
			sign = line.FindFirst('=');
			if (sign >= 1)
			{
				len = line.Length();
				line.CopyInto(key, 0, sign);
				line.CopyInto(value, sign+1, len-sign-1);
				Trim(key);
				Trim(value);
				AddEntry(key, value);
			}				
		}
	}
	else
		return false;
		
	return true;
}
// this function search and remove single lines comments: '//' and '#'
// the currentPos is required in order to avoid cases in which the comment start after the caret
bool PHPEditorContextMenu::RemoveSingleLineComment(wxStyledTextCtrl* sci, int& caret_pos)
{
    int currentPos = sci->GetCurrentPos();
    int line_number = sci->LineFromPosition(currentPos);
    int line_start_pos = sci->PositionFromLine(line_number);

    // search for a single line comment
    sci->SetTargetStart(line_start_pos);
    sci->SetTargetEnd(currentPos);
    int start_comment_pos = sci->SearchInTarget(m_comment_line_1);
    if(start_comment_pos != wxSTC_INVALID_POSITION) {
        caret_pos -= RemoveComment(sci, start_comment_pos, m_comment_line_1);
        return true;
    }

    start_comment_pos = sci->SearchInTarget(m_comment_line_2);
    if(start_comment_pos != wxSTC_INVALID_POSITION) {
        caret_pos -= RemoveComment(sci, start_comment_pos, m_comment_line_2);
        return true;
    }

    return false;
}
bool PHPEditorContextMenu::RemoveTokenFirstIteration(wxStyledTextCtrl* sci,
                                                     const wxString& token,
                                                     bool direction,
                                                     int& caret_pos)
{
    // initialization of start_pos & end_pos
    int line_number = sci->LineFromPosition(sci->GetCurrentPos());
    int start_pos, end_pos;
    if(direction) {
        start_pos = sci->GetCurrentPos() - token.length();
        end_pos = sci->GetLineEndPosition(line_number);
    } else {
        start_pos = sci->PositionFromLine(line_number);
        end_pos = sci->GetCurrentPos() + token.length();
    }

    // loop until the token is found
    int token_pos = wxSTC_INVALID_POSITION;
    while(token_pos == wxSTC_INVALID_POSITION) {
        sci->SetTargetStart(start_pos);
        sci->SetTargetEnd(end_pos);
        token_pos = sci->SearchInTarget(token);
        if(token_pos != wxSTC_INVALID_POSITION) { // match
            int res = RemoveComment(sci, token_pos, token);
            if(!direction) {
                caret_pos -= res;
                if(caret_pos < token_pos) caret_pos = token_pos;
            } else {
                if(caret_pos > token_pos) caret_pos = token_pos;
            }
            return true;
        }

        if(direction)
            line_number++;
        else
            line_number--;

        start_pos = sci->PositionFromLine(line_number);
        end_pos = sci->GetLineEndPosition(line_number);
    }

    return false;
}
Пример #5
0
void processMakeFile(const QFileInfo& file, bool assume_our)
{
    int offset(0);
    bool skipfile(false), modify_file(assume_our);
    QString text=fileToString(file.absoluteFilePath());
    QStringList output;
    while(offset<text.length())
    {
        //qDebug()<<"==========================";
        int off_ss=text.indexOf('#', offset);

        if(off_ss<0)
        {
            //qDebug()<<"tail="<<text.mid(offset);
            output<<text.mid(offset);
            break;
        }

        bool comment_from_newline(true);
        int newlinebefore=off_ss==0 ? 0 : text.lastIndexOf('\n', off_ss)+1;
        for(int i=newlinebefore+1; i<off_ss; ++i)
        {
            if(!text.at(i).isSpace()){
                comment_from_newline=false;
                break;
            }
        }
        int end=text.indexOf('\n', off_ss);
        if(end<0)end=text.length();else ++end;//end if after \n
        //grab more lines
        if(comment_from_newline)
        {
            int tabspace=off_ss-newlinebefore;
            //find more comments from newline
            while(end<text.length())
            {
                int nextss=text.indexOf('#',end);
                if(nextss<0)break;
                //check if there is \n between // and end
                int moreN=text.indexOf('\n', end);
                if(moreN>=0 && moreN<nextss)break;
                //check for [end]...spaces...//
                bool spaces_between(true);
                for(int i=end; i<nextss; ++i)
                {
                    if(!text.at(i).isSpace()){
                        spaces_between=false;
                        break;
                    }
                }
                if(!spaces_between || nextss-end!=tabspace)
                    break;
                end=text.indexOf('\n', nextss);
                if(end<0)end=text.length();else ++end;
            }
        }
        //qDebug()<<"... ... comment at "<<off_ss<<"--"<<end;
        //qDebug()<<text.mid(off_ss, end-off_ss);
        if(RemoveComment(file.absoluteFilePath(), text, off_ss, end, skipfile, modify_file))
        {
            if(offset<off_ss)
            {
                //qDebug()<<"output {"<<text.mid(offset, off_ss-offset)<<"}";
                output<<text.mid(offset,off_ss-offset);
            }
        }
        else
        {
            //qDebug()<<"output2{"<<text.mid(offset, end-offset)<<"}";
            output<<text.mid(offset, end-offset);
        }
        offset=end;
    }
    storeFile(text, file.absoluteFilePath(), output, skipfile, modify_file, true);
}
Пример #6
0
	//////////////////////////////////////////////////////////////////////////////
	/// @details    Constructor from configuration file name.
	///
	/// @param      cfg_filename  Configuration file name.
	///
	/// @post       Configuration has been loaded.
	///
	/// @exception  std::runtime_error  Configuration file could not be opened.
	///
	AppConfigReader::AppConfigReader(std::string const& cfg_filename)
		: m_cfg()
	{
		std::cout << "loading configuration from file \"" << cfg_filename << "\"" << std::endl;
		
		//  open file
		std::ifstream cfg_file(cfg_filename.c_str());
		if (! cfg_file.good())
		{
			throw std::runtime_error("failed to open config file");
		}
		
		//  process lines
		std::string line;
		unsigned int line_num = 0;
		while (std::getline(cfg_file, line))
		{
			++line_num;
			
			RemoveComment(line);
			
			std::istringstream splitter(line);
			
			//  read key (if any)
			std::string key;
			splitter >> key;
			if (0 == key.size())
			{
				continue;
			}

			//  read value (if any)
			std::string value;
			splitter >> value;

			if (0 == value.size())
			{
				std::cout << cfg_filename << ":" << line_num << ": warning: ignoring line with key but no value" << std::endl;
				std::cout << cfg_filename << ":" << line_num << ": " << line << std::endl;
				continue;				
			}
	
			//  identify which key we've just read
			if (key == "Nx")
			{
				m_cfg.m_Nx = StringToInt(value);
			}
			else if (key == "Ny")
			{
				m_cfg.m_Ny = StringToInt(value);
			}
			else if (key == "T")
			{
				m_cfg.m_T = StringToInt(value); 
			}
			else if (key == "TT")
			{
				m_cfg.m_TT = StringToInt(value);
			}
			else if (key == "r")
			{
				m_cfg.m_r = StringToDouble(value);
			}
			else if (key == "a")
			{
				m_cfg.m_a = StringToDouble(value);
			}
			else if (key == "b")
			{
				m_cfg.m_b = StringToDouble(value);
			}
			else if (key == "m")
			{
				m_cfg.m_m = StringToDouble(value);
			}
			else if (key == "k")
			{
				m_cfg.m_k = StringToDouble(value);
			}
			else if (key == "l")
			{
				m_cfg.m_l = StringToDouble(value);
			}
			else if (key == "dt")
			{
				m_cfg.m_dt = StringToDouble(value);
			}
			else
			{
				std::cout << cfg_filename << ":" << line_num << ": warning: unrecognised key name" << std::endl;
				std::cout << cfg_filename << ":" << line_num << ": " << line << std::endl;				
			}
		}
		
		m_cfg.Print();
	}