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 @@
#include <libxml/xmlexports.h> // define XMLCALL so expat.h does not redefine it
#include <expat.h>
#include <rtl/ustring.hxx>
#include <rtl/ustrbuf.hxx>
#include <rtl/string.hxx>
#include <rtl/strbuf.hxx>
#include "boost/unordered_map.hpp"
#include "export.hxx"
......@@ -56,21 +56,21 @@ using namespace std;
class XMLAttribute
{
private:
OUString sName;
OUString sValue;
OString sName;
OString sValue;
public:
/// creates an attribute
XMLAttribute(
const OUString &rName, // attributes name
const OUString &rValue // attributes data
const OString &rName, // attributes name
const OString &rValue // attributes data
)
: sName( rName ), sValue( rValue ) {}
: sName( rName ), sValue( rValue ) {}
OUString GetName() const { return sName; }
OUString GetValue() const { return sValue; }
OString GetName() const { return sName; }
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
sal_Bool IsEqual(
......@@ -183,7 +183,7 @@ class XMLFile : public XMLParentNode
{
public:
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();
......@@ -203,20 +203,16 @@ public:
virtual sal_uInt16 GetNodeType();
/// returns file name
OUString GetName() { return sFileName; }
void SetName( const OUString &rFilename ) { sFileName = rFilename; }
const std::vector<OString> getOrder(){ return order; }
OString GetName() const { return sFileName; }
void SetName( const OString &rFilename ) { sFileName = rFilename; }
const std::vector<OString>& getOrder() const { return order; }
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);
// DATA
OUString sFileName;
const OString ID, OLDREF, XML_LANG;
OString sFileName;
TagMap nodes_localize;
XMLHashMap* XMLStrings;
......@@ -229,10 +225,7 @@ class XMLUtil{
public:
/// Quot the XML characters
static OUString QuotHTML( const OUString& rString );
/// UnQuot the XML characters
static OUString UnQuotHTML( const OUString &rString );
static OString QuotHTML( const OString& rString );
};
......@@ -243,7 +236,7 @@ public:
class XMLElement : public XMLParentNode
{
private:
OUString sElementName;
OString sElementName;
XMLAttributeList *pAttributes;
OString project,
filename,
......@@ -254,12 +247,12 @@ private:
int nPos;
protected:
void Print(XMLNode *pCur, OUStringBuffer& buffer , bool rootelement);
void Print(XMLNode *pCur, OStringBuffer& buffer , bool rootelement);
public:
/// create an element node
XMLElement(){}
XMLElement(
const OUString &rName, // the element name
const OString &rName, // the element name
XMLParentNode *Parent // parent node of this element
): XMLParentNode( Parent ),
sElementName( rName ),
......@@ -281,18 +274,18 @@ public:
virtual sal_uInt16 GetNodeType();
/// returns element name
OUString GetName() { return sElementName; }
OString GetName() const { return sElementName; }
/// returns list of attributes of this element
XMLAttributeList *GetAttributeList() { return pAttributes; }
/// 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
OUString ToOUString();
OString ToOString();
void SetProject ( OString const & prj ){ project = prj; }
void SetFileName ( OString const & fn ){ filename = fn; }
......@@ -302,13 +295,13 @@ public:
void SetPos ( int nPos_in ){ nPos = nPos_in; }
void SetOldRef ( OString const & sOldRef_in ){ sOldRef = sOldRef_in; }
virtual int GetPos() { return nPos; }
OString GetProject() { return project; }
OString GetFileName() { return filename; }
OString GetId() { return id; }
OString GetOldref() { return sOldRef; }
OString GetResourceType(){ return resourceType; }
OString GetLanguageId() { return languageId; }
virtual int GetPos() { return nPos; }
OString GetProject() const { return project; }
OString GetFileName() const { return filename; }
OString GetId() const { return id; }
OString GetOldref() const { return sOldRef; }
OString GetResourceType() const { return resourceType; }
OString GetLanguageId() const { return languageId; }
};
......@@ -320,18 +313,18 @@ public:
class XMLData : public XMLChildNode
{
private:
OUString sData;
OString sData;
bool isNewCreated;
public:
/// create a data node
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
)
: XMLChildNode( Parent ), sData( rData ) , isNewCreated ( false ){}
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
bool newCreated
)
......@@ -343,12 +336,12 @@ public:
virtual sal_uInt16 GetNodeType();
/// returns the data
OUString GetData() { return sData; }
OString GetData() const { return sData; }
bool isNew() { return isNewCreated; }
/// adds new character data to the existing one
void AddData(
const OUString &rData // the new data
const OString &rData // the new data
);
......@@ -362,12 +355,12 @@ public:
class XMLComment : public XMLChildNode
{
private:
OUString sComment;
OString sComment;
public:
/// create a comment node
XMLComment(
const OUString &rComment, // the comment
const OString &rComment, // the comment
XMLParentNode *Parent // the parent node of this comemnt, typically a element node
)
: XMLChildNode( Parent ), sComment( rComment ) {}
......@@ -379,7 +372,7 @@ public:
XMLComment& operator=(const XMLComment& obj);
/// returns the comment
OUString GetComment() { return sComment; }
OString GetComment() const { return sComment; }
};
//-------------------------------------------------------------------------
......@@ -389,12 +382,12 @@ public:
class XMLDefault : public XMLChildNode
{
private:
OUString sDefault;
OString sDefault;
public:
/// create a comment node
XMLDefault(
const OUString &rDefault, // the comment
const OString &rDefault, // the comment
XMLParentNode *Parent // the parent node of this comemnt, typically a element node
)
: XMLChildNode( Parent ), sDefault( rDefault ) {}
......@@ -407,7 +400,7 @@ public:
virtual sal_uInt16 GetNodeType();
/// returns the comment
OUString GetDefault() { return sDefault; }
OString GetDefault() const { return sDefault; }
};
//-------------------------------------------------------------------------
......@@ -418,7 +411,7 @@ struct XMLError {
XML_Error eCode; ///< the error code
std::size_t nLine; ///< error line number
std::size_t nColumn; ///< error column number
OUString sMessage; ///< readable error message
OString sMessage; ///< readable error message
};
//-------------------------------------------------------------------------
......@@ -457,7 +450,7 @@ public:
/// parse a file, returns NULL on criticall errors
XMLFile *Execute(
const OUString &rFileName, // the file name
const OString &rFileName, // the file name
XMLFile *pXMLFileIn // the XMLFile
);
......
......@@ -124,7 +124,7 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) {
hasNoError =
aParser.CreatePO(
aArgs.m_sOutputFile, aArgs.m_sInputFile,
new XMLFile( OUString('0') ), "help" );
new XMLFile( OString('0') ), "help" );
}
if( hasNoError )
......
......@@ -79,20 +79,16 @@ bool HelpParser::CreatePO(
const OString &rPOFile_in, const OString &sHelpFile,
XMLFile *pXmlFile, const OString &rGsi1){
SimpleXMLParser aParser;
OUString sXmlFile(
OStringToOUString(sHelpFile, RTL_TEXTENCODING_ASCII_US));
//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)
{
printf(
"%s: %s\n",
sHelpFile.getStr(),
(OUStringToOString(
aParser.GetError().sMessage, RTL_TEXTENCODING_ASCII_US).
getStr()));
aParser.GetError().sMessage.getStr());
exit(-1);
}
file->Extract();
......@@ -125,7 +121,7 @@ bool HelpParser::CreatePO(
if( pXMLElement != NULL )
{
OString data(
OUStringToOString( pXMLElement->ToOUString(), RTL_TEXTENCODING_UTF8 ).
pXMLElement->ToOString().
replaceAll("\n",OString()).
replaceAll("\t",OString()).trim());
......@@ -153,11 +149,9 @@ bool HelpParser::Merge( const OString &rPOFile, const OString &rDestinationFile,
SimpleXMLParser aParser;
OUString sXmlFile(
OStringToOUString(sHelpFile, RTL_TEXTENCODING_ASCII_US));
//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 );
delete xmlfile;
return hasNoError;
......@@ -207,7 +201,7 @@ void HelpParser::ProcessHelp( LangHashMap* aLangHM , const OString& sCur , ResDa
pEntrys = NULL;
if( !sCur.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("en-US")) ){
if( !sCur.equalsIgnoreAsciiCase("en-US") ){
pXMLElement = (*aLangHM)[ "en-US" ];
if( pXMLElement == NULL )
{
......@@ -219,15 +213,15 @@ void HelpParser::ProcessHelp( LangHashMap* aLangHM , const OString& sCur , ResDa
pResData->sId = sLId;
OString sNewText;
OUString sNewdata;
OUString sSourceText(
pXMLElement->ToOUString().
OString sNewdata;
OString sSourceText(
pXMLElement->ToOString().
replaceAll(
OUString("\n"),
OUString()).
OString("\n"),
OString()).
replaceAll(
OUString("\t"),
OUString()));
OString("\t"),
OString()));
// re-add spaces to the beginning of translated string,
// important for indentation of Basic code examples
sal_Int32 nPreSpaces = 0;
......@@ -236,20 +230,18 @@ void HelpParser::ProcessHelp( LangHashMap* aLangHM , const OString& sCur , ResDa
nPreSpaces++;
if( sCur == "qtz" )
{
const OString sOriginText = OUStringToOString(sSourceText, RTL_TEXTENCODING_UTF8);
sNewText = MergeEntrys::GetQTZText(*pResData, sOriginText);
sNewdata = OStringToOUString(sNewText, RTL_TEXTENCODING_UTF8);
sNewText = MergeEntrys::GetQTZText(*pResData, sSourceText);
sNewdata = sNewText;
}
else if( pMergeDataFile )
{
pEntrys = pMergeDataFile->GetMergeEntrys( pResData );
if( pEntrys != NULL)
{
pEntrys->GetText( sNewText, STRING_TYP_TEXT, sCur , true );
OUString sTemp = OStringToOUString(sNewText, RTL_TEXTENCODING_UTF8);
if (helper::isWellFormedXML(OUStringToOString(XMLUtil::QuotHTML(sTemp),RTL_TEXTENCODING_UTF8)))
pEntrys->GetText( sNewText, STRING_TYP_TEXT, sCur, true );
if (helper::isWellFormedXML(XMLUtil::QuotHTML(sNewText)))
{
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
"Can't find GID=" << pResData->sGId.getStr() << " LID="
<< pResData->sId.getStr() << " TYP=" << pResData->sResTyp.getStr() << "\n");
}
pXMLElement->ChangeLanguageTag(
OStringToOUString(sCur, RTL_TEXTENCODING_ASCII_US));
pXMLElement->ChangeLanguageTag(sCur);
}
}
......
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