Performing RegEx on open file
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Performing RegEx on open file

Threaded View

  1. #1
    Join Date
    Mar 2011
    Posts
    144

    Performing RegEx on open file

    Hi, like the title says, I'm trying to open a file and perform a regex on it, then print the matches, but I'm not sure if I have it right. I think I need to remove the line -
    Code:
    [for ( std::vector<TCHAR>::iterator It = buffer.begin();It != buffer.end(); It++ )
    since I've already copied the file into the buffer, but how do I search the buffer?

    Code:
    std::ifstream in(TempFullPath, std::ios::in|std::ios::binary);
    
    if( in.fail() )
    {
    	std::cout << "File does not exist or could not open file";
    }
    
    
    std::vector<TCHAR> buffer;
    std::copy( 
    		std::istreambuf_iterator<TCHAR>( in ),
    		std::istreambuf_iterator<TCHAR>(),
    		std::back_inserter( buffer )
    		);
    for ( std::vector<TCHAR>::iterator It = buffer.begin();It != buffer.end(); It++ ) {
    	sbuf = (*It);
    	if( boost::regex_search(sbuf , matches, re ) )
    			{
    				std::string value( matches[1].first, matches[1].second );
    				StringCchCat(TextAreaBuffer, MAX_PATH, value.c_str());
    				StringCchCat(TextAreaBuffer, MAX_PATH, TEXT("\r\n"));
    				int ndx = GetWindowTextLength (textArea);
    				SetFocus (textArea);
    				#ifdef WIN32
    					SendMessage (textArea, EM_SETSEL, (WPARAM)ndx, (LPARAM)ndx);
    				#else
    					SendMessage (textArea, EM_SETSEL, 0, MAKELONG (ndx, ndx));
    				#endif
    					SendMessage (textArea, EM_REPLACESEL, 0, (LPARAM) (TextAreaBuffer));
    						
    		}
    }
    Last edited by drwbns; January 11th, 2013 at 12:45 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center