Kaydet (Commit) ede82878 authored tarafından Zolnai Tamás's avatar Zolnai Tamás

Use OString in xmlparse.cxx to avoid numerous srting conversion

Plus:
- Use macros instead of members.
- Use const where it is usefull.

Change-Id: I960f5dec29b5c17655055e1884bc4e7983359318
üst db45382b
...@@ -30,8 +30,8 @@ ...@@ -30,8 +30,8 @@
#include <libxml/xmlexports.h> // define XMLCALL so expat.h does not redefine it #include <libxml/xmlexports.h> // define XMLCALL so expat.h does not redefine it
#include <expat.h> #include <expat.h>
#include <rtl/ustring.hxx> #include <rtl/string.hxx>
#include <rtl/ustrbuf.hxx> #include <rtl/strbuf.hxx>
#include "boost/unordered_map.hpp" #include "boost/unordered_map.hpp"
#include "export.hxx" #include "export.hxx"
...@@ -56,21 +56,21 @@ using namespace std; ...@@ -56,21 +56,21 @@ using namespace std;
class XMLAttribute class XMLAttribute
{ {
private: private:
OUString sName; OString sName;
OUString sValue; OString sValue;
public: public:
/// creates an attribute /// creates an attribute
XMLAttribute( XMLAttribute(
const OUString &rName, // attributes name const OString &rName, // attributes name
const OUString &rValue // attributes data const OString &rValue // attributes data
) )
: sName( rName ), sValue( rValue ) {} : sName( rName ), sValue( rValue ) {}
OUString GetName() const { return sName; } OString GetName() const { return sName; }
OUString GetValue() const { return sValue; } OString GetValue() const { return sValue; }
void setValue(const OUString &rValue){sValue=rValue;} void setValue(const OString &rValue){sValue=rValue;}
/// returns true if two attributes are equal and have the same value /// returns true if two attributes are equal and have the same value
sal_Bool IsEqual( sal_Bool IsEqual(
...@@ -183,7 +183,7 @@ class XMLFile : public XMLParentNode ...@@ -183,7 +183,7 @@ class XMLFile : public XMLParentNode
{ {
public: public:
XMLFile( XMLFile(
const OUString &rFileName // the file name, empty if created from memory stream const OString &rFileName // the file name, empty if created from memory stream
); );
XMLFile( const XMLFile& obj ) ; XMLFile( const XMLFile& obj ) ;
~XMLFile(); ~XMLFile();
...@@ -203,20 +203,16 @@ public: ...@@ -203,20 +203,16 @@ public:
virtual sal_uInt16 GetNodeType(); virtual sal_uInt16 GetNodeType();
/// returns file name /// returns file name
OUString GetName() { return sFileName; } OString GetName() const { return sFileName; }
void SetName( const OUString &rFilename ) { sFileName = rFilename; } void SetName( const OString &rFilename ) { sFileName = rFilename; }
const std::vector<OString> getOrder(){ return order; } const std::vector<OString>& getOrder() const { return order; }
protected: protected:
/// writes a string as UTF8 with dos line ends to a given stream
void WriteString( ofstream &rStream, const OUString &sString );
void InsertL10NElement( XMLElement* pElement); void InsertL10NElement( XMLElement* pElement);
// DATA // DATA
OUString sFileName; OString sFileName;
const OString ID, OLDREF, XML_LANG;
TagMap nodes_localize; TagMap nodes_localize;
XMLHashMap* XMLStrings; XMLHashMap* XMLStrings;
...@@ -229,10 +225,7 @@ class XMLUtil{ ...@@ -229,10 +225,7 @@ class XMLUtil{
public: public:
/// Quot the XML characters /// Quot the XML characters
static OUString QuotHTML( const OUString& rString ); static OString QuotHTML( const OString& rString );
/// UnQuot the XML characters
static OUString UnQuotHTML( const OUString &rString );
}; };
...@@ -243,7 +236,7 @@ public: ...@@ -243,7 +236,7 @@ public:
class XMLElement : public XMLParentNode class XMLElement : public XMLParentNode
{ {
private: private:
OUString sElementName; OString sElementName;
XMLAttributeList *pAttributes; XMLAttributeList *pAttributes;
OString project, OString project,
filename, filename,
...@@ -254,12 +247,12 @@ private: ...@@ -254,12 +247,12 @@ private:
int nPos; int nPos;
protected: protected:
void Print(XMLNode *pCur, OUStringBuffer& buffer , bool rootelement); void Print(XMLNode *pCur, OStringBuffer& buffer , bool rootelement);
public: public:
/// create an element node /// create an element node
XMLElement(){} XMLElement(){}
XMLElement( XMLElement(
const OUString &rName, // the element name const OString &rName, // the element name
XMLParentNode *Parent // parent node of this element XMLParentNode *Parent // parent node of this element
): XMLParentNode( Parent ), ): XMLParentNode( Parent ),
sElementName( rName ), sElementName( rName ),
...@@ -281,18 +274,18 @@ public: ...@@ -281,18 +274,18 @@ public:
virtual sal_uInt16 GetNodeType(); virtual sal_uInt16 GetNodeType();
/// returns element name /// returns element name
OUString GetName() { return sElementName; } OString GetName() const { return sElementName; }
/// returns list of attributes of this element /// returns list of attributes of this element
XMLAttributeList *GetAttributeList() { return pAttributes; } XMLAttributeList *GetAttributeList() { return pAttributes; }
/// adds a new attribute to this element, typically used by parser /// adds a new attribute to this element, typically used by parser
void AddAttribute( const OUString &rAttribute, const OUString &rValue ); void AddAttribute( const OString &rAttribute, const OString &rValue );
void ChangeLanguageTag( const OUString &rValue ); void ChangeLanguageTag( const OString &rValue );
/// Return a Unicode String representation of this object /// Return a Unicode String representation of this object
OUString ToOUString(); OString ToOString();
void SetProject ( OString const & prj ){ project = prj; } void SetProject ( OString const & prj ){ project = prj; }
void SetFileName ( OString const & fn ){ filename = fn; } void SetFileName ( OString const & fn ){ filename = fn; }
...@@ -303,12 +296,12 @@ public: ...@@ -303,12 +296,12 @@ public:
void SetOldRef ( OString const & sOldRef_in ){ sOldRef = sOldRef_in; } void SetOldRef ( OString const & sOldRef_in ){ sOldRef = sOldRef_in; }
virtual int GetPos() { return nPos; } virtual int GetPos() { return nPos; }
OString GetProject() { return project; } OString GetProject() const { return project; }
OString GetFileName() { return filename; } OString GetFileName() const { return filename; }
OString GetId() { return id; } OString GetId() const { return id; }
OString GetOldref() { return sOldRef; } OString GetOldref() const { return sOldRef; }
OString GetResourceType(){ return resourceType; } OString GetResourceType() const { return resourceType; }
OString GetLanguageId() { return languageId; } OString GetLanguageId() const { return languageId; }
}; };
...@@ -320,18 +313,18 @@ public: ...@@ -320,18 +313,18 @@ public:
class XMLData : public XMLChildNode class XMLData : public XMLChildNode
{ {
private: private:
OUString sData; OString sData;
bool isNewCreated; bool isNewCreated;
public: public:
/// create a data node /// create a data node
XMLData( XMLData(
const OUString &rData, // the initial data const OString &rData, // the initial data
XMLParentNode *Parent // the parent node of this data, typically a element node XMLParentNode *Parent // the parent node of this data, typically a element node
) )
: XMLChildNode( Parent ), sData( rData ) , isNewCreated ( false ){} : XMLChildNode( Parent ), sData( rData ) , isNewCreated ( false ){}
XMLData( XMLData(
const OUString &rData, // the initial data const OString &rData, // the initial data
XMLParentNode *Parent, // the parent node of this data, typically a element node XMLParentNode *Parent, // the parent node of this data, typically a element node
bool newCreated bool newCreated
) )
...@@ -343,12 +336,12 @@ public: ...@@ -343,12 +336,12 @@ public:
virtual sal_uInt16 GetNodeType(); virtual sal_uInt16 GetNodeType();
/// returns the data /// returns the data
OUString GetData() { return sData; } OString GetData() const { return sData; }
bool isNew() { return isNewCreated; } bool isNew() { return isNewCreated; }
/// adds new character data to the existing one /// adds new character data to the existing one
void AddData( void AddData(
const OUString &rData // the new data const OString &rData // the new data
); );
...@@ -362,12 +355,12 @@ public: ...@@ -362,12 +355,12 @@ public:
class XMLComment : public XMLChildNode class XMLComment : public XMLChildNode
{ {
private: private:
OUString sComment; OString sComment;
public: public:
/// create a comment node /// create a comment node
XMLComment( XMLComment(
const OUString &rComment, // the comment const OString &rComment, // the comment
XMLParentNode *Parent // the parent node of this comemnt, typically a element node XMLParentNode *Parent // the parent node of this comemnt, typically a element node
) )
: XMLChildNode( Parent ), sComment( rComment ) {} : XMLChildNode( Parent ), sComment( rComment ) {}
...@@ -379,7 +372,7 @@ public: ...@@ -379,7 +372,7 @@ public:
XMLComment& operator=(const XMLComment& obj); XMLComment& operator=(const XMLComment& obj);
/// returns the comment /// returns the comment
OUString GetComment() { return sComment; } OString GetComment() const { return sComment; }
}; };
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
...@@ -389,12 +382,12 @@ public: ...@@ -389,12 +382,12 @@ public:
class XMLDefault : public XMLChildNode class XMLDefault : public XMLChildNode
{ {
private: private:
OUString sDefault; OString sDefault;
public: public:
/// create a comment node /// create a comment node
XMLDefault( XMLDefault(
const OUString &rDefault, // the comment const OString &rDefault, // the comment
XMLParentNode *Parent // the parent node of this comemnt, typically a element node XMLParentNode *Parent // the parent node of this comemnt, typically a element node
) )
: XMLChildNode( Parent ), sDefault( rDefault ) {} : XMLChildNode( Parent ), sDefault( rDefault ) {}
...@@ -407,7 +400,7 @@ public: ...@@ -407,7 +400,7 @@ public:
virtual sal_uInt16 GetNodeType(); virtual sal_uInt16 GetNodeType();
/// returns the comment /// returns the comment
OUString GetDefault() { return sDefault; } OString GetDefault() const { return sDefault; }
}; };
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
...@@ -418,7 +411,7 @@ struct XMLError { ...@@ -418,7 +411,7 @@ struct XMLError {
XML_Error eCode; ///< the error code XML_Error eCode; ///< the error code
std::size_t nLine; ///< error line number std::size_t nLine; ///< error line number
std::size_t nColumn; ///< error column number std::size_t nColumn; ///< error column number
OUString sMessage; ///< readable error message OString sMessage; ///< readable error message
}; };
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
...@@ -457,7 +450,7 @@ public: ...@@ -457,7 +450,7 @@ public:
/// parse a file, returns NULL on criticall errors /// parse a file, returns NULL on criticall errors
XMLFile *Execute( XMLFile *Execute(
const OUString &rFileName, // the file name const OString &rFileName, // the file name
XMLFile *pXMLFileIn // the XMLFile XMLFile *pXMLFileIn // the XMLFile
); );
......
...@@ -124,7 +124,7 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { ...@@ -124,7 +124,7 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
hasNoError = hasNoError =
aParser.CreatePO( aParser.CreatePO(
aArgs.m_sOutputFile, aArgs.m_sInputFile, aArgs.m_sOutputFile, aArgs.m_sInputFile,
new XMLFile( OUString('0') ), "help" ); new XMLFile( OString('0') ), "help" );
} }
if( hasNoError ) if( hasNoError )
......
...@@ -79,20 +79,16 @@ bool HelpParser::CreatePO( ...@@ -79,20 +79,16 @@ bool HelpParser::CreatePO(
const OString &rPOFile_in, const OString &sHelpFile, const OString &rPOFile_in, const OString &sHelpFile,
XMLFile *pXmlFile, const OString &rGsi1){ XMLFile *pXmlFile, const OString &rGsi1){
SimpleXMLParser aParser; SimpleXMLParser aParser;
OUString sXmlFile(
OStringToOUString(sHelpFile, RTL_TEXTENCODING_ASCII_US));
//TODO: explicit BOM handling? //TODO: explicit BOM handling?
std::auto_ptr <XMLFile> file ( aParser.Execute( sXmlFile, pXmlFile ) ); std::auto_ptr <XMLFile> file ( aParser.Execute( sHelpFile, pXmlFile ) );
if(file.get() == NULL) if(file.get() == NULL)
{ {
printf( printf(
"%s: %s\n", "%s: %s\n",
sHelpFile.getStr(), sHelpFile.getStr(),
(OUStringToOString( aParser.GetError().sMessage.getStr());
aParser.GetError().sMessage, RTL_TEXTENCODING_ASCII_US).
getStr()));
exit(-1); exit(-1);
} }
file->Extract(); file->Extract();
...@@ -125,7 +121,7 @@ bool HelpParser::CreatePO( ...@@ -125,7 +121,7 @@ bool HelpParser::CreatePO(
if( pXMLElement != NULL ) if( pXMLElement != NULL )
{ {
OString data( OString data(
OUStringToOString( pXMLElement->ToOUString(), RTL_TEXTENCODING_UTF8 ). pXMLElement->ToOString().
replaceAll("\n",OString()). replaceAll("\n",OString()).
replaceAll("\t",OString()).trim()); replaceAll("\t",OString()).trim());
...@@ -153,11 +149,9 @@ bool HelpParser::Merge( const OString &rPOFile, const OString &rDestinationFile, ...@@ -153,11 +149,9 @@ bool HelpParser::Merge( const OString &rPOFile, const OString &rDestinationFile,
SimpleXMLParser aParser; SimpleXMLParser aParser;
OUString sXmlFile(
OStringToOUString(sHelpFile, RTL_TEXTENCODING_ASCII_US));
//TODO: explicit BOM handling? //TODO: explicit BOM handling?
XMLFile* xmlfile = ( aParser.Execute( sXmlFile, new XMLFile( OUString('0') ) ) ); XMLFile* xmlfile = ( aParser.Execute( sHelpFile, new XMLFile( OString('0') ) ) );
bool hasNoError = MergeSingleFile( xmlfile , pMergeDataFile , rLanguage , rDestinationFile ); bool hasNoError = MergeSingleFile( xmlfile , pMergeDataFile , rLanguage , rDestinationFile );
delete xmlfile; delete xmlfile;
return hasNoError; return hasNoError;
...@@ -207,7 +201,7 @@ void HelpParser::ProcessHelp( LangHashMap* aLangHM , const OString& sCur , ResDa ...@@ -207,7 +201,7 @@ void HelpParser::ProcessHelp( LangHashMap* aLangHM , const OString& sCur , ResDa
pEntrys = NULL; pEntrys = NULL;
if( !sCur.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("en-US")) ){ if( !sCur.equalsIgnoreAsciiCase("en-US") ){
pXMLElement = (*aLangHM)[ "en-US" ]; pXMLElement = (*aLangHM)[ "en-US" ];
if( pXMLElement == NULL ) if( pXMLElement == NULL )
{ {
...@@ -219,15 +213,15 @@ void HelpParser::ProcessHelp( LangHashMap* aLangHM , const OString& sCur , ResDa ...@@ -219,15 +213,15 @@ void HelpParser::ProcessHelp( LangHashMap* aLangHM , const OString& sCur , ResDa
pResData->sId = sLId; pResData->sId = sLId;
OString sNewText; OString sNewText;
OUString sNewdata; OString sNewdata;
OUString sSourceText( OString sSourceText(
pXMLElement->ToOUString(). pXMLElement->ToOString().
replaceAll( replaceAll(
OUString("\n"), OString("\n"),
OUString()). OString()).
replaceAll( replaceAll(
OUString("\t"), OString("\t"),
OUString())); OString()));
// re-add spaces to the beginning of translated string, // re-add spaces to the beginning of translated string,
// important for indentation of Basic code examples // important for indentation of Basic code examples
sal_Int32 nPreSpaces = 0; sal_Int32 nPreSpaces = 0;
...@@ -236,20 +230,18 @@ void HelpParser::ProcessHelp( LangHashMap* aLangHM , const OString& sCur , ResDa ...@@ -236,20 +230,18 @@ void HelpParser::ProcessHelp( LangHashMap* aLangHM , const OString& sCur , ResDa
nPreSpaces++; nPreSpaces++;
if( sCur == "qtz" ) if( sCur == "qtz" )
{ {
const OString sOriginText = OUStringToOString(sSourceText, RTL_TEXTENCODING_UTF8); sNewText = MergeEntrys::GetQTZText(*pResData, sSourceText);
sNewText = MergeEntrys::GetQTZText(*pResData, sOriginText); sNewdata = sNewText;
sNewdata = OStringToOUString(sNewText, RTL_TEXTENCODING_UTF8);
} }
else if( pMergeDataFile ) else if( pMergeDataFile )
{ {
pEntrys = pMergeDataFile->GetMergeEntrys( pResData ); pEntrys = pMergeDataFile->GetMergeEntrys( pResData );
if( pEntrys != NULL) if( pEntrys != NULL)
{ {
pEntrys->GetText( sNewText, STRING_TYP_TEXT, sCur , true ); pEntrys->GetText( sNewText, STRING_TYP_TEXT, sCur, true );
OUString sTemp = OStringToOUString(sNewText, RTL_TEXTENCODING_UTF8); if (helper::isWellFormedXML(XMLUtil::QuotHTML(sNewText)))
if (helper::isWellFormedXML(OUStringToOString(XMLUtil::QuotHTML(sTemp),RTL_TEXTENCODING_UTF8)))
{ {
sNewdata = sSourceText.copy(0,nPreSpaces) + sTemp; sNewdata = sSourceText.copy(0,nPreSpaces) + sNewText;
} }
} }
} }
...@@ -270,8 +262,7 @@ void HelpParser::ProcessHelp( LangHashMap* aLangHM , const OString& sCur , ResDa ...@@ -270,8 +262,7 @@ void HelpParser::ProcessHelp( LangHashMap* aLangHM , const OString& sCur , ResDa
"Can't find GID=" << pResData->sGId.getStr() << " LID=" "Can't find GID=" << pResData->sGId.getStr() << " LID="
<< pResData->sId.getStr() << " TYP=" << pResData->sResTyp.getStr() << "\n"); << pResData->sId.getStr() << " TYP=" << pResData->sResTyp.getStr() << "\n");
} }
pXMLElement->ChangeLanguageTag( pXMLElement->ChangeLanguageTag(sCur);
OStringToOUString(sCur, RTL_TEXTENCODING_ASCII_US));
} }
} }
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment