0

This is the CSS:

.tableDUTY {
    margin-bottom: 2mm;
}

.cellDutyLabel {
    border-right-style: none;
}

.textDutyLabel {
    font-size: 10pt;
    font-weight: normal;
}

.cellDutyName {
    font-size: 10pt;
    font-weight: normal;
}

.cellDutyHeading {
    padding-left: 1mm;
}

.textDutyHeading {
    padding: 1mm;
    color: #fff;
    background-color: #FD00FF;
    width: 90mm;
    font-size: 12pt;
    font-weight: 700;
    text-transform: uppercase;
    vertical-align: middle;
}

I know that I can rework all the text and do something like:

m_strCSS.Empty();
m_strCSS += L".tableDUTY {\r\n";
m_strCSS += L"\tmargin-bottom: 2mm;\r\n";
m_strCSS += L"}\r\n";
// etc.

But is there no way that I can just paste my CSS as-is into my CPP file and assign to the CString variable? I don't mind going through a more modern string type, like std::string, as long as I end up with a CString.

Ultimately, the CString is mapped to a CEdit control, so that it displays the multiline CSS text.

I also know I could use a lambda, like:

m_strCSS.Empty();
auto AddLine = [this](CString strLine)
{
    m_strCSS += strLine + L"\r\n";
};

AddLine(L".tableDUTY {");
AddLine(L"\tmargin-bottom: 2mm;");
AddLine(L"}");

But anything to take the whole block of CSS in one go?

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • 1
    I stumbled uppon `R"( ... )"` that seems to allow some people to create raw multiline strings (e.g https://stackoverflow.com/questions/1135841/c-multiline-string-literal). I'm not sure if this will work for you. Have you considered to actually read a file? You could potentially change the styles without recompiling your application. – lupz May 30 '23 at 08:44
  • @lupz Thanks for the suggestion. Whilst I can indeed do `m_strCSS = R"(...)";` I find that the text in the `CEdit` is all on one line. I have stayed with the lambda approach for now. – Andrew Truckle May 30 '23 at 08:56

1 Answers1

0

As a compromise I have settled on a lambda:

auto AddLine = [this](CString strLine = L"", const int iTabIndent = 0)
{
    for (auto iTab = 0; iTab < iTabIndent; iTab++)
        m_strCSS += L"\t";

    m_strCSS += strLine + L"\r\n";
};

This way I atleast drop the complexity of the tab \t being part of the string. Elsewhere I have up to 5 tabs. This works for me.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164