Fixed an encoding problem
This commit is contained in:
parent
f39ac69e7b
commit
17f79c10c0
|
@ -23,9 +23,9 @@
|
|||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
WrapExpat::WrapExpat ( bool nameSpaceAware )
|
||||
WrapExpat::WrapExpat ( bool nameSpaceAware, const char *encoding )
|
||||
{
|
||||
p = ( nameSpaceAware ) ? XML_ParserCreateNS ( NULL, ( XML_Char ) ':' ) : XML_ParserCreate ( NULL );
|
||||
p = ( nameSpaceAware ) ? XML_ParserCreateNS ( encoding, ( XML_Char ) ':' ) : XML_ParserCreate ( encoding );
|
||||
if ( p == 0 )
|
||||
throw runtime_error ( "WrapExpat::WrapExpat" );
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ using namespace std;
|
|||
class WrapExpat
|
||||
{
|
||||
public:
|
||||
WrapExpat ( bool nameSpaceAware = false );
|
||||
WrapExpat ( bool nameSpaceAware = false, const char *encoding = NULL );
|
||||
virtual ~WrapExpat();
|
||||
bool parse ( const string &buffer, bool isFinal = true );
|
||||
bool parse ( const char *buffer, size_t size, bool isFinal = true );
|
||||
|
|
|
@ -5921,22 +5921,21 @@ void MyFrame::OnWordCount ( wxCommandEvent& event )
|
|||
XmlDoc *doc;
|
||||
if ( ( doc = getActiveDocument() ) == NULL )
|
||||
return;
|
||||
wxString wideBuffer;
|
||||
std::string buffer;
|
||||
wideBuffer = doc->GetText();
|
||||
buffer = wideBuffer.mb_str ( wxConvUTF8 );
|
||||
|
||||
auto_ptr<XmlWordCount> xwc ( new XmlWordCount() );
|
||||
std::string rawBufferUtf8;
|
||||
getRawText ( doc, rawBufferUtf8 );
|
||||
|
||||
XmlWordCount xwc ( "UTF-8" );
|
||||
wxString msg;
|
||||
if ( !xwc->parse ( buffer.c_str() ) )
|
||||
if ( !xwc.parse ( rawBufferUtf8 ) )
|
||||
{
|
||||
statusProgress ( wxEmptyString );
|
||||
msg.Printf ( _ ( "Cannot count words: %s" ), xwc->getLastError().c_str() );
|
||||
msg.Printf ( _ ( "Cannot count words: %s" ), xwc.getLastError().c_str() );
|
||||
messagePane ( msg, CONST_STOP );
|
||||
return;
|
||||
}
|
||||
|
||||
int count = xwc->getWordCount();
|
||||
int count = xwc.getWordCount();
|
||||
|
||||
msg.Printf (
|
||||
wxPLURAL ( "%s contains %i word", "%s contains %i words", count ),
|
||||
|
|
|
@ -22,7 +22,9 @@
|
|||
#include "xmlwordcount.h"
|
||||
#include "getword.h"
|
||||
|
||||
XmlWordCount::XmlWordCount() : wcd ( new WordCountData() )
|
||||
XmlWordCount::XmlWordCount ( const char *encoding )
|
||||
: WrapExpat ( false, encoding )
|
||||
, wcd ( new WordCountData() )
|
||||
{
|
||||
wcd->wordCount = 0;
|
||||
XML_SetUserData ( p, wcd.get() );
|
||||
|
|
|
@ -33,7 +33,7 @@ struct WordCountData : public ParserData
|
|||
class XmlWordCount : public WrapExpat
|
||||
{
|
||||
public:
|
||||
XmlWordCount();
|
||||
XmlWordCount ( const char *encoding = NULL );
|
||||
virtual ~XmlWordCount();
|
||||
|
||||
int getWordCount();
|
||||
|
|
Loading…
Reference in New Issue