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:
committed by
Stephanie Anderl
parent
afc1b2146c
commit
b55659f236
@@ -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"&";
|
||||
break;
|
||||
case L'\"':
|
||||
buffer << L""";
|
||||
break;
|
||||
case L'\'':
|
||||
buffer << L"'";
|
||||
break;
|
||||
case L'<':
|
||||
buffer << L"<";
|
||||
break;
|
||||
case L'>':
|
||||
buffer << L">";
|
||||
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);
|
||||
|
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user