Jump to content
  • Advertisement
Sign in to follow this  
VI2

Boost::algorithm::replace_all help?

This topic is 4283 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, I've got an ethernet device that duplicates 0xFF values when being sent though it. So when I recieve data from it I needs to remove duplicate 0xFF values. I know I could right a crude string manipulation algo to do this but I was hoping to accomplish this with the boost algorithm replace_all. I've been trying to play around with it and it does let me do what I want. Any suggestions on what I might try? CommWinsock2::readLine(buff,length); boost::algorithm::replace_all(buff,0xFF+0xFF,(unsigned char)0xFF); Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
After a moment's reflection, I find it interesting that this comes up so soon after that big C vs C++ thread that included some discussions about what was considered intuitive or unintuitive in using character arrays and std::string.

0xFF+0xFF == 0x1FE

And besides this, boost::algorithm::replace_all is expecting strings for its second and third arguments, not chars.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
First - can you safely treat this data as a string? Could it contain zeros?

If you can, I suppose you could do something like:


string data = buff;
replace_all(data, "\xFF\xFF", "\xFF");


but this seems to be the result of an over-enthusiasm for boost :) replace_all is designed for string manipulation, don't try to twist it to do something else.

How about just:


vector newData;
for(unsigned int i=0; i<

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Sorry, not sure why the code tag didn't work there :S


vector<unsigned char> newData;
for(unsigned int i=0; i<length; ++i)
{
if(buff==0xFF && ++i==length) break;
newData.push_back(buff);
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!