summaryrefslogtreecommitdiffstats
path: root/Source/CPack/WiX/cmWIXSourceWriter.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/CPack/WiX/cmWIXSourceWriter.cxx')
-rw-r--r--Source/CPack/WiX/cmWIXSourceWriter.cxx176
1 files changed, 76 insertions, 100 deletions
diff --git a/Source/CPack/WiX/cmWIXSourceWriter.cxx b/Source/CPack/WiX/cmWIXSourceWriter.cxx
index 2e5194c..2c0384e 100644
--- a/Source/CPack/WiX/cmWIXSourceWriter.cxx
+++ b/Source/CPack/WiX/cmWIXSourceWriter.cxx
@@ -17,46 +17,41 @@
#include <windows.h>
cmWIXSourceWriter::cmWIXSourceWriter(cmCPackLog* logger,
- std::string const& filename,
- bool isIncludeFile):
- Logger(logger),
- File(filename.c_str()),
- State(DEFAULT),
- SourceFilename(filename)
+ std::string const& filename,
+ bool isIncludeFile)
+ : Logger(logger)
+ , File(filename.c_str())
+ , State(DEFAULT)
+ , SourceFilename(filename)
{
WriteXMLDeclaration();
- if(isIncludeFile)
- {
+ if (isIncludeFile) {
BeginElement("Include");
- }
- else
- {
+ } else {
BeginElement("Wix");
- }
+ }
AddAttribute("xmlns", "http://schemas.microsoft.com/wix/2006/wi");
}
cmWIXSourceWriter::~cmWIXSourceWriter()
{
- if(Elements.size() > 1)
- {
- cmCPackLogger(cmCPackLog::LOG_ERROR,
- Elements.size() - 1 << " WiX elements were still open when closing '" <<
- SourceFilename << "'" << std::endl);
+ if (Elements.size() > 1) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, Elements.size() - 1
+ << " WiX elements were still open when closing '"
+ << SourceFilename << "'" << std::endl);
return;
- }
+ }
EndElement(Elements.back());
}
void cmWIXSourceWriter::BeginElement(std::string const& name)
{
- if(State == BEGIN)
- {
+ if (State == BEGIN) {
File << ">";
- }
+ }
File << "\n";
Indent(Elements.size());
@@ -68,33 +63,27 @@ void cmWIXSourceWriter::BeginElement(std::string const& name)
void cmWIXSourceWriter::EndElement(std::string const& name)
{
- if(Elements.empty())
- {
+ if (Elements.empty()) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
- "can not end WiX element with no open elements in '" <<
- SourceFilename << "'" << std::endl);
+ "can not end WiX element with no open elements in '"
+ << SourceFilename << "'" << std::endl);
return;
- }
+ }
- if(Elements.back() != name)
- {
- cmCPackLogger(cmCPackLog::LOG_ERROR,
- "WiX element <" << Elements.back() <<
- "> can not be closed by </" << name << "> in '" <<
- SourceFilename << "'" << std::endl);
+ if (Elements.back() != name) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR, "WiX element <"
+ << Elements.back() << "> can not be closed by </" << name
+ << "> in '" << SourceFilename << "'" << std::endl);
return;
- }
+ }
- if(State == DEFAULT)
- {
+ if (State == DEFAULT) {
File << "\n";
- Indent(Elements.size()-1);
+ Indent(Elements.size() - 1);
File << "</" << Elements.back() << ">";
- }
- else
- {
+ } else {
File << "/>";
- }
+ }
Elements.pop_back();
State = DEFAULT;
@@ -102,30 +91,27 @@ void cmWIXSourceWriter::EndElement(std::string const& name)
void cmWIXSourceWriter::AddTextNode(std::string const& text)
{
- if(State == BEGIN)
- {
+ if (State == BEGIN) {
File << ">";
- }
+ }
- if(Elements.empty())
- {
+ if (Elements.empty()) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
- "can not add text without open WiX element in '" <<
- SourceFilename << "'" << std::endl);
+ "can not add text without open WiX element in '"
+ << SourceFilename << "'" << std::endl);
return;
- }
+ }
File << this->EscapeAttributeValue(text);
State = DEFAULT;
}
-void cmWIXSourceWriter::AddProcessingInstruction(
- std::string const& target, std::string const& content)
+void cmWIXSourceWriter::AddProcessingInstruction(std::string const& target,
+ std::string const& content)
{
- if(State == BEGIN)
- {
+ if (State == BEGIN) {
File << ">";
- }
+ }
File << "\n";
Indent(Elements.size());
@@ -134,21 +120,20 @@ void cmWIXSourceWriter::AddProcessingInstruction(
State = DEFAULT;
}
-void cmWIXSourceWriter::AddAttribute(
- std::string const& key, std::string const& value)
+void cmWIXSourceWriter::AddAttribute(std::string const& key,
+ std::string const& value)
{
std::string utf8 = CMakeEncodingToUtf8(value);
File << " " << key << "=\"" << EscapeAttributeValue(utf8) << '"';
}
-void cmWIXSourceWriter::AddAttributeUnlessEmpty(
- std::string const& key, std::string const& value)
+void cmWIXSourceWriter::AddAttributeUnlessEmpty(std::string const& key,
+ std::string const& value)
{
- if(!value.empty())
- {
+ if (!value.empty()) {
AddAttribute(key, value);
- }
+ }
}
std::string cmWIXSourceWriter::CMakeEncodingToUtf8(std::string const& value)
@@ -156,43 +141,38 @@ std::string cmWIXSourceWriter::CMakeEncodingToUtf8(std::string const& value)
#ifdef CMAKE_ENCODING_UTF8
return value;
#else
- if(value.empty())
- {
+ if (value.empty()) {
return std::string();
- }
+ }
int characterCount = MultiByteToWideChar(
CP_ACP, 0, value.c_str(), static_cast<int>(value.size()), 0, 0);
- if(characterCount == 0)
- {
+ if (characterCount == 0) {
return std::string();
- }
+ }
std::vector<wchar_t> utf16(characterCount);
- MultiByteToWideChar(
- CP_ACP, 0, value.c_str(), static_cast<int>(value.size()),
- &utf16[0], static_cast<int>(utf16.size()));
+ MultiByteToWideChar(CP_ACP, 0, value.c_str(), static_cast<int>(value.size()),
+ &utf16[0], static_cast<int>(utf16.size()));
int utf8ByteCount = WideCharToMultiByte(
CP_UTF8, 0, &utf16[0], static_cast<int>(utf16.size()), 0, 0, 0, 0);
- if(utf8ByteCount == 0)
- {
+ if (utf8ByteCount == 0) {
return std::string();
- }
+ }
std::vector<char> utf8(utf8ByteCount);
WideCharToMultiByte(CP_UTF8, 0, &utf16[0], static_cast<int>(utf16.size()),
- &utf8[0], static_cast<int>(utf8.size()), 0, 0);
+ &utf8[0], static_cast<int>(utf8.size()), 0, 0);
return std::string(&utf8[0], utf8.size());
#endif
}
-
void cmWIXSourceWriter::WriteXMLDeclaration()
{
File << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
@@ -200,41 +180,37 @@ void cmWIXSourceWriter::WriteXMLDeclaration()
void cmWIXSourceWriter::Indent(size_t count)
{
- for(size_t i = 0; i < count; ++i)
- {
+ for (size_t i = 0; i < count; ++i) {
File << " ";
- }
+ }
}
-std::string cmWIXSourceWriter::EscapeAttributeValue(
- std::string const& value)
+std::string cmWIXSourceWriter::EscapeAttributeValue(std::string const& value)
{
std::string result;
result.reserve(value.size());
char c = 0;
- for(size_t i = 0 ; i < value.size(); ++i)
- {
+ for (size_t i = 0; i < value.size(); ++i) {
c = value[i];
- switch(c)
- {
- case '<':
- result += "&lt;";
- break;
- case '>':
- result += "&gt;";
- break;
- case '&':
- result +="&amp;";
- break;
- case '"':
- result += "&quot;";
- break;
- default:
- result += c;
- break;
- }
- }
+ switch (c) {
+ case '<':
+ result += "&lt;";
+ break;
+ case '>':
+ result += "&gt;";
+ break;
+ case '&':
+ result += "&amp;";
+ break;
+ case '"':
+ result += "&quot;";
+ break;
+ default:
+ result += c;
+ break;
+ }
+ }
return result;
}