Problem Description
I'm using Expat with a custom C++ wrapper, which I already tested on other projects. I'm running into problems, because the original data (c_str) is not converted to a std::string in the right way. This concers me, because I did not change the source of the wrapper.
It seems like the string gets null-terminated chars after this conversion:
onCharacterData( std::string( pszData, nLength ) ) // --> std::string( char* pszData)
How can I fix this?
Own expat wrapper
// Wrapper defines the class Expat and implements for example:
void XMLCALL Expat::CharacterDataHandler( void *pUserData, const XML_Char *pszData,
int nLength )
{
Expat* pThis = static_cast<Expat*>( pUserData );
// XML_Char is char, therefore this call contains i.e.: std::string("hello", 5)
pThis->onCharacterData( std::string( pszData, nLength ) );
}
Custom parser
// Parser is defined as: class Parser : Expat
void Parser::onCharacterData(const std::string& data )
{
// data is no longer char*, but a std::string.
// It seems to contain \0 after each character which is wrong!
// [...]
}
std::string(pszData)
; there's a constructor for null-terminated C-strings. – Kerrek SB