replace string file

E

Eric Kaplan

I have a function that will take char buffer and dump all data into a
file.

How can I replace all
<givenname xsi:nil='true'/>

with

<givenname>.</givenname>


=============================
int my_block_reader(void *userdata, const char *buf, size_t len)
{

char *szBuffer = new char[len + 1];
memcpy(szBuffer, buf, len);
szBuffer[len] = 0;
dumpfile << szBuffer;
delete[] szBuffer;

return 0;
}
 
N

Nathan Mates

How can I replace all
<givenname xsi:nil='true'/>

with

<givenname>.</givenname>

The PCRE library from http://www.pcre.org/ makes it really easy to
replace a string based on regular expressions. Use PCRE as a
library/DLL, and the C++ wrappers turn the (somewhat obscure) API into
a rather trivial operation.

Nathan Mates
 
A

Alf P. Steinbach

* Eric Kaplan:
I have a function that will take char buffer and dump all data into a
file.

How can I replace all
<givenname xsi:nil='true'/>

with

<givenname>.</givenname>


=============================
int my_block_reader(void *userdata, const char *buf, size_t len)
{

char *szBuffer = new char[len + 1];
memcpy(szBuffer, buf, len);
szBuffer[len] = 0;
dumpfile << szBuffer;
delete[] szBuffer;

return 0;
}


It seems you're not using the 'userdata' argument. Why is it there, and why is
it a 'void*' rather than some reasonable type?

Why does the function have a non-'void' result type when it always returns the
same value?

And if it's meant to be a boolean, why is it 'int' instead of 'bool'?

Why is the function named 'reader' when its purpose is to write?

Why are you using C-style coding when you're posting to [comp.lang.c++]?

Why are you using Hungarian notation (that's the most silly about the whole
thing, it really beats me why anyone would willingly add warts)?

Why is this cross-posted to three groups, two of which are vendor-specific?


Cheers, & hth.,

- Alf
 
E

Eric Kaplan

It seems you're not using the 'userdata' argument. Why is it there, and why is
it a 'void*' rather than some reasonable type?

I think it's a mistake
Why does the function have a non-'void' result type when it always returns the
same value?

Yes, can be return void.
And if it's meant to be a boolean, why is it 'int' instead of 'bool'?

this can be changed too
Why is the function named 'reader' when its purpose is to write?

It's called by a function like - ne_add_response_body_reader(req,
ne_accept_always, my_block_reader, NULL);
Why are you using C-style coding when you're posting to [comp.lang.c++]?

I am new to C++ I don't know it's C only
Why are you using Hungarian notation (that's the most silly about the whole
thing, it really beats me why anyone would willingly add warts)?

Hungarian notation? never heard of this though
Why is this cross-posted to three groups, two of which are vendor-specific?

May be more people can see this question?
 
C

Carmen Sei

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::eek:stream& 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(),
* Eric Kaplan:
I have a function that will take char buffer and dump all data into a
file.

How can I replace all
<givenname xsi:nil='true'/>

with

<givenname>.</givenname>


=============================
int my_block_reader(void *userdata, const char *buf, size_t len)
{

char *szBuffer = new char[len + 1];
memcpy(szBuffer, buf, len);
szBuffer[len] = 0;
dumpfile << szBuffer;
delete[] szBuffer;

return 0;
}


It seems you're not using the 'userdata' argument. Why is it there, and why is
it a 'void*' rather than some reasonable type?

Why does the function have a non-'void' result type when it always returns the
same value?

And if it's meant to be a boolean, why is it 'int' instead of 'bool'?

Why is the function named 'reader' when its purpose is to write?

Why are you using C-style coding when you're posting to [comp.lang.c++]?

Why are you using Hungarian notation (that's the most silly about the whole
thing, it really beats me why anyone would willingly add warts)?

Why is this cross-posted to three groups, two of which are vendor-specific?


Cheers, & hth.,

- Alf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,498
Latest member
log5Sshell/alfa5

Latest Threads

Top