Skip to content
Snippets Groups Projects
Commit 419172e5 authored by Andy Heninger's avatar Andy Heninger
Browse files

Removed transcoding stuff, replaced with DOMString::transcode.

Tweaked xml encoding= declaration to say ISO-8859-1.  Still wrong,
but not as wrong as utf-8


git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@171457 13f79535-47bb-0310-9956-ffa450edef68
parent 2d85e5f9
No related branches found
No related tags found
No related merge requests found
...@@ -56,6 +56,12 @@ ...@@ -56,6 +56,12 @@
/** /**
* $Log$ * $Log$
* Revision 1.3 1999/12/03 00:14:52 andyh
* Removed transcoding stuff, replaced with DOMString::transcode.
*
* Tweaked xml encoding= declaration to say ISO-8859-1. Still wrong,
* but not as wrong as utf-8
*
* Revision 1.2 1999/11/12 02:14:05 rahulj * Revision 1.2 1999/11/12 02:14:05 rahulj
* It now validates when the -v option is specified. * It now validates when the -v option is specified.
* *
...@@ -81,6 +87,13 @@ ...@@ -81,6 +87,13 @@
// filename - The path to the XML file to parse // filename - The path to the XML file to parse
// //
// These are non-case sensitive // These are non-case sensitive
//
// Limitations:
// 1. The encoding="xxx" clause in the XML header should reflect
// the system local code page, but does not.
// 2. Cases where the XML data contains characters that can not
// be represented in the system local code page are not handled.
//
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -141,9 +154,9 @@ int main(int argC, char* argV[]) ...@@ -141,9 +154,9 @@ int main(int argC, char* argV[])
catch(const XMLException& toCatch) catch(const XMLException& toCatch)
{ {
cerr << "Error during XML4C2 Initialization.\n" cerr << "Error during Xerces-c Initialization.\n"
<< " Exception message:" << " Exception message:"
<< StrX(toCatch.getMessage()) << endl; << DOMString(toCatch.getMessage()) << endl;
return 1; return 1;
} }
...@@ -219,7 +232,8 @@ int main(int argC, char* argV[]) ...@@ -219,7 +232,8 @@ int main(int argC, char* argV[])
catch (const XMLException& e) catch (const XMLException& e)
{ {
cerr << "An error occured during parsing\n Message: " cerr << "An error occured during parsing\n Message: "
<< StrX(e.getMessage()) << endl; << DOMString(e.getMessage()) << endl;
// << StrX(e.getMessage()) << endl;
errorsOccured = true; errorsOccured = true;
} }
...@@ -302,7 +316,11 @@ ostream& operator<<(ostream& target, DOM_Node& toWrite) ...@@ -302,7 +316,11 @@ ostream& operator<<(ostream& target, DOM_Node& toWrite)
case DOM_Node::DOCUMENT_NODE : case DOM_Node::DOCUMENT_NODE :
{ {
target << "<?xml version='1.0' encoding='utf-8' ?>\n"; // Bug here: we need to find a way to get the encoding name
// for the default code page on the system where the
// program is running, and plug that in for the encoding
// name.
target << "<?xml version='1.0' encoding='ISO-8859-1' ?>\n";
DOM_Node child = toWrite.getFirstChild(); DOM_Node child = toWrite.getFirstChild();
while( child != 0) while( child != 0)
{ {
...@@ -431,7 +449,8 @@ void outputContent(ostream& target, const DOMString &toWrite) ...@@ -431,7 +449,8 @@ void outputContent(ostream& target, const DOMString &toWrite)
default: default:
// If it is none of the special characters, print it as such // If it is none of the special characters, print it as such
target << StrX(&chars[index], 1); // target << StrX(&chars[index], 1);
target << toWrite.substringData(index, 1);
break; break;
} }
} }
...@@ -443,12 +462,18 @@ void outputContent(ostream& target, const DOMString &toWrite) ...@@ -443,12 +462,18 @@ void outputContent(ostream& target, const DOMString &toWrite)
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// //
// ostream << DOMString Stream out a DOM string. // ostream << DOMString Stream out a DOM string.
// Doing this requires that we first transcode
// to char * form in the default code page
// for the system
// //
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
ostream& operator<<(ostream& target, const DOMString& s) ostream& operator<<(ostream& target, const DOMString& s)
{ {
if (s.length() > 0) //if (s.length() > 0)
target << StrX(s.rawBuffer(), s.length()); // target << StrX(s.rawBuffer(), s.length());
char *p = s.transcode();
target << p;
delete p;
return target; return target;
} }
...@@ -56,8 +56,14 @@ ...@@ -56,8 +56,14 @@
/** /**
* $Log$ * $Log$
* Revision 1.1 1999/11/09 01:09:51 twl * Revision 1.2 1999/12/03 00:14:53 andyh
* Initial revision * Removed transcoding stuff, replaced with DOMString::transcode.
*
* Tweaked xml encoding= declaration to say ISO-8859-1. Still wrong,
* but not as wrong as utf-8
*
* Revision 1.1.1.1 1999/11/09 01:09:51 twl
* Initial checkin
* *
* Revision 1.6 1999/11/08 20:43:35 rahul * Revision 1.6 1999/11/08 20:43:35 rahul
* Swat for adding in Product name and CVS comment log variable. * Swat for adding in Product name and CVS comment log variable.
...@@ -72,6 +78,10 @@ ...@@ -72,6 +78,10 @@
#include <iostream.h> #include <iostream.h>
#include <stdlib.h> #include <stdlib.h>
#include <memory.h> #include <memory.h>
#include <dom/DOMString.hpp>
// Global streaming operator for DOMString is defined in DOMPrint.cpp
extern ostream& operator<<(ostream& target, const DOMString& s);
void DOMTreeErrorReporter::warning(const SAXParseException&) void DOMTreeErrorReporter::warning(const SAXParseException&)
...@@ -83,18 +93,18 @@ void DOMTreeErrorReporter::warning(const SAXParseException&) ...@@ -83,18 +93,18 @@ void DOMTreeErrorReporter::warning(const SAXParseException&)
void DOMTreeErrorReporter::error(const SAXParseException& toCatch) void DOMTreeErrorReporter::error(const SAXParseException& toCatch)
{ {
cerr << "Error at file \"" << StrX(toCatch.getSystemId()) cerr << "Error at file \"" << DOMString(toCatch.getSystemId())
<< "\", line " << toCatch.getLineNumber() << "\", line " << toCatch.getLineNumber()
<< ", column " << toCatch.getColumnNumber() << ", column " << toCatch.getColumnNumber()
<< "\n Message: " << StrX(toCatch.getMessage()) << endl; << "\n Message: " << DOMString(toCatch.getMessage()) << endl;
} }
void DOMTreeErrorReporter::fatalError(const SAXParseException& toCatch) void DOMTreeErrorReporter::fatalError(const SAXParseException& toCatch)
{ {
cerr << "Fatal Error at file \"" << StrX(toCatch.getSystemId()) cerr << "Fatal Error at file \"" << DOMString(toCatch.getSystemId())
<< "\", line " << toCatch.getLineNumber() << "\", line " << toCatch.getLineNumber()
<< ", column " << toCatch.getColumnNumber() << ", column " << toCatch.getColumnNumber()
<< "\n Message: " << StrX(toCatch.getMessage()) << endl; << "\n Message: " << DOMString(toCatch.getMessage()) << endl;
} }
void DOMTreeErrorReporter::resetErrors() void DOMTreeErrorReporter::resetErrors()
...@@ -103,70 +113,3 @@ void DOMTreeErrorReporter::resetErrors() ...@@ -103,70 +113,3 @@ void DOMTreeErrorReporter::resetErrors()
} }
// ---------------------------------------------------------------------------
// StrX: Private helper methods
// ---------------------------------------------------------------------------
void StrX::transcode(const XMLCh* const toTranscode, const unsigned int len)
{
// Short circuit if its a null pointer
if (!toTranscode || (!toTranscode[0]))
{
fLocalForm = new char[1];
fLocalForm[0] = 0;
return;
}
// See if our XMLCh and wchar_t as the same on this platform
const bool isSameSize = (sizeof(XMLCh) == sizeof(wchar_t));
//
// Get the actual number of chars. If the passed len is zero, its null
// terminated. Else we have to use the len.
//
wchar_t realLen = (wchar_t)len;
if (!realLen)
{
//
// We cannot just assume we can use wcslen() because we don't know
// if our XMLCh is the same as wchar_t on this platform.
//
const XMLCh* tmpPtr = toTranscode;
while (*(tmpPtr++))
realLen++;
}
//
// If either the passed length was non-zero or our char sizes are not
// same, we have to use a temp buffer. Since this is common in these
// samples, we just do it anyway.
//
wchar_t* tmpSource = new wchar_t[realLen + 1];
if (isSameSize)
{
memcpy(tmpSource, toTranscode, realLen * sizeof(wchar_t));
}
else
{
for (unsigned int index = 0; index < realLen; index++)
tmpSource[index] = (wchar_t)toTranscode[index];
}
tmpSource[realLen] = 0;
// See now many chars we need to transcode this guy
const unsigned int targetLen = ::wcstombs(0, tmpSource, 0);
// Allocate out storage member
fLocalForm = new char[targetLen + 1];
//
// And transcode our temp source buffer to the local buffer. Cap it
// off since the converter won't do it (because the null is beyond
// where the target will fill up.)
//
::wcstombs(fLocalForm, tmpSource, targetLen);
fLocalForm[targetLen] = 0;
// Don't forget to delete our temp buffer
delete [] tmpSource;
}
...@@ -56,8 +56,14 @@ ...@@ -56,8 +56,14 @@
/** /**
* $Log$ * $Log$
* Revision 1.1 1999/11/09 01:09:51 twl * Revision 1.2 1999/12/03 00:14:53 andyh
* Initial revision * Removed transcoding stuff, replaced with DOMString::transcode.
*
* Tweaked xml encoding= declaration to say ISO-8859-1. Still wrong,
* but not as wrong as utf-8
*
* Revision 1.1.1.1 1999/11/09 01:09:51 twl
* Initial checkin
* *
* Revision 1.4 1999/11/08 20:43:36 rahul * Revision 1.4 1999/11/08 20:43:36 rahul
* Swat for adding in Product name and CVS comment log variable. * Swat for adding in Product name and CVS comment log variable.
...@@ -92,58 +98,3 @@ public: ...@@ -92,58 +98,3 @@ public:
void resetErrors(); void resetErrors();
}; };
// ---------------------------------------------------------------------------
// This is a simple class that lets us do easy (though not terribly efficient)
// trancoding of XMLCh data to local code page for display.
// ---------------------------------------------------------------------------
class StrX
{
public :
// -----------------------------------------------------------------------
// Constructors and Destructor
// -----------------------------------------------------------------------
StrX(const XMLCh* const toTranscode, const unsigned int len = 0) :
fLocalForm(0)
{
// Call the private transcoding method
transcode(toTranscode, len);
}
~StrX()
{
delete [] fLocalForm;
}
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
const char* localForm() const
{
return fLocalForm;
}
private :
// -----------------------------------------------------------------------
// Private helper methods
// -----------------------------------------------------------------------
void transcode (const XMLCh* const toTranscode, const unsigned int len);
// -----------------------------------------------------------------------
// Private data members
//
// fLocalForm
// This is the local code page form of the string.
// -----------------------------------------------------------------------
char* fLocalForm;
};
inline ostream& operator<<(ostream& target, const StrX& toDump)
{
target << toDump.localForm();
return target;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment