Update share output (#782)

* fix share bugs

* PR feedback

* PR feedback and merge fix

* Fix spacing and use explicit break

* Fix extra space
This commit is contained in:
Pepe Rivera
2019-11-19 15:54:24 -08:00
committed by Stephanie Anderl
parent afc1b2146c
commit b55659f236
8 changed files with 177 additions and 75 deletions

View File

@@ -264,6 +264,71 @@ void Utils::TrimBack(wstring& value)
}).base(), value.end());
}
String^ Utils::EscapeHtmlSpecialCharacters(String^ originalString, shared_ptr<vector<wchar_t>> specialCharacters)
{
// Construct a default special characters if not provided.
if (specialCharacters == nullptr)
{
specialCharacters = make_shared<vector<wchar_t>>();
specialCharacters->push_back(L'&');
specialCharacters->push_back(L'\"');
specialCharacters->push_back(L'\'');
specialCharacters->push_back(L'<');
specialCharacters->push_back(L'>');
}
bool replaceCharacters = false;
const wchar_t* pCh;
String^ replacementString = nullptr;
// First step is scanning the string for special characters.
// If there isn't any special character, we simply return the original string
for (pCh = originalString->Data(); *pCh; pCh++)
{
if (std::find(specialCharacters->begin(), specialCharacters->end(), *pCh) != specialCharacters->end())
{
replaceCharacters = true;
break;
}
}
if (replaceCharacters)
{
// If we indeed find a special character, we step back one character (the special
// character), and we create a new string where we replace those characters one by one
pCh--;
wstringstream buffer;
buffer << wstring(originalString->Data(), pCh);
for (; *pCh; pCh++)
{
switch (*pCh)
{
case L'&':
buffer << L"&amp;";
break;
case L'\"':
buffer << L"&quot;";
break;
case L'\'':
buffer << L"&apos;";
break;
case L'<':
buffer << L"&lt;";
break;
case L'>':
buffer << L"&gt;";
break;
default:
buffer << *pCh;
}
}
replacementString = ref new String(buffer.str().c_str());
}
return replaceCharacters ? replacementString : originalString;
}
bool operator==(const Color& color1, const Color& color2)
{
return equal_to<Color>()(color1, color2);

View File

@@ -430,6 +430,7 @@ namespace Utils
void TrimFront(std::wstring& value);
void TrimBack(std::wstring& value);
Platform::String ^ EscapeHtmlSpecialCharacters(Platform::String ^ originalString, std::shared_ptr<std::vector<wchar_t>> specialCharacters = nullptr);
}