You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by Michele Laghi <mi...@attglobal.net> on 2000/06/08 22:02:28 UTC
Believed bug in XMLString::trim(...)
Hi,
I got some problems porting some code from java to c++ making use of the
trim function so I tested the following simple code:
// code starts here:
#include <iostream>
#include <util/PlatformUtils.hpp>
#include <util/XMLString.hpp>
int main() {
// Init the XML platform
try {
XMLPlatformUtils::Initialize();
}
catch(const XMLException& toCatch) {
cout << "Error during platform init! Message:\n"
<< endl;
return 1;
}
char *help = " simple test ";
char *help1;
cerr << "ORIGINAL STRING: ." << help << "." << XMLString::stringLen(help) << endl;
XMLCh *ptr = XMLString::transcode(help);
help1 = XMLString::transcode(ptr);
cerr << "XMLCh string : ." << help1 << "." << XMLString::stringLen(help1) << endl;;
delete help1;
XMLString::trim(ptr);
help1 = XMLString::transcode(ptr);
cerr << "Trimmed XMLCh : ." << help1 << "." << XMLString::stringLen(help1) << endl;
delete help1;
help1 = XMLString::replicate(help);
XMLString::trim(help1);
cerr << "Trim. original : ." << help1 << "." << XMLString::stringLen(help1) << endl;
delete help1;
return 0;
}
// code ends here
what I get is the following output:
ORIGINAL STRING: . simple test .17
XMLCh string : . simple test .17
Trimmed XMLCh : . simple test .17
Trim. original : .simple testest.14
What I believe is wrong (in both cases of the trim function).
According to the api doc of these functions, trim should "trim" any
extra character at the end of the string (I believe extra character
means as in the java String.trim() method whitespaces, newline and tab).
Is this a bug or did I missunderstand the meaning of trim, and if so,
why is there a difference between the XMLCh* version and the char*
version ?
The system I am running it is SuSE Linux 6.1 (kernel 2.2.7) and the
compiler is gcc 2.95.2
Greetings
Michele
--
-------------------------------------------------
Michele Laghi
Av. Benavides 163 dpto. 301
MIRAFLORES-LIMA (PERU)
tel. +51 1 4463956
e-mail: michele.laghi@attglobal.net
-------------------------------------------------
Re: Believed bug in XMLString::trim(...)
Posted by Andy Heninger <an...@jtcsv.com>.
You are right; there is a problem with the XMLCh * flavor of this function.
Also, the documentation is not clear, but the spaces are removed from both
ends of the string (like in Java).
Thanks for pointing out the problem,
Andy Heninger
IBM XML Technology Group, Cupertino, CA
heninger@us.ibm.com
----- Original Message -----
From: Michele Laghi
To: XERCES NAMELIST
Sent: Thursday, June 08, 2000 1:02 PM
Subject: Believed bug in XMLString::trim(...)
Hi,
I got some problems porting some code from java to c++ making use of the trim function so I tested the following simple code:
// code starts here:
#include <iostream>
#include <util/PlatformUtils.hpp>
#include <util/XMLString.hpp>
int main() {
// Init the XML platform
try {
XMLPlatformUtils::Initialize();
}
catch(const XMLException& toCatch) {
cout << "Error during platform init! Message:\n"
<< endl;
return 1;
}
char *help = " simple test ";
char *help1;
cerr << "ORIGINAL STRING: ." << help << "." << XMLString::stringLen(help) << endl;
XMLCh *ptr = XMLString::transcode(help);
help1 = XMLString::transcode(ptr);
cerr << "XMLCh string : ." << help1 << "." << XMLString::stringLen(help1) << endl;;
delete help1;
XMLString::trim(ptr);
help1 = XMLString::transcode(ptr);
cerr << "Trimmed XMLCh : ." << help1 << "." << XMLString::stringLen(help1) << endl;
delete help1;
help1 = XMLString::replicate(help);
XMLString::trim(help1);
cerr << "Trim. original : ." << help1 << "." << XMLString::stringLen(help1) << endl;
delete help1;
return 0;
}
// code ends here
what I get is the following output:
ORIGINAL STRING: . simple test .17
XMLCh string : . simple test .17
Trimmed XMLCh : . simple test .17
Trim. original : .simple testest.14
What I believe is wrong (in both cases of the trim function).
According to the api doc of these functions, trim should "trim" any extra character at the end of the string (I believe extra character means as in the java String.trim() method whitespaces, newline and tab).
Is this a bug or did I missunderstand the meaning of trim, and if so, why is there a difference between the XMLCh* version and the char* version ?
The system I am running it is SuSE Linux 6.1 (kernel 2.2.7) and the compiler is gcc 2.95.2
Greetings
Michele
--
-------------------------------------------------
Michele Laghi
Av. Benavides 163 dpto. 301
MIRAFLORES-LIMA (PERU)
tel. +51 1 4463956
e-mail: michele.laghi@attglobal.net
-------------------------------------------------