SysReAllocString(BSTR FAR* pbstr, const OLECHAR FAR* psz) { if(psz == NULL) { SysFreeString(*pbstr); *pbstr = NULL; return TRUE; } return SysReAllocStringLen(pbstr, psz, STRLEN(psz)); }
CMarkdown::HSTR CMarkdown::_HSTR::Entities() { HSTR H = this; BSTR p, q = H->B; while (*(p = q)) { OLECHAR *value = 0; switch (*p) { case '&': value = L"&"; break; case '"': value = L"""; break; case '\'': value = L"'"; break; case '<' : value = L"<"; break; case '>' : value = L">"; break; } ++q; if (value) { int i = p - H->B; int j = q - H->B; int cchValue = lstrlenW(value); if (int cchGrow = cchValue - 1) { BSTR B = H->B; int b = SysStringLen(B); size_t cbMove = (b - j) * sizeof(OLECHAR); if (cchGrow < 0) { memmove(q + cchGrow, q, cbMove); } if (!SysReAllocStringLen(&B, B, b + cchGrow)) { continue; } H = (HSTR)B; p = H->B + i; q = H->B + j; if (cchGrow > 0) { memmove(q + cchGrow, q, cbMove); } } memcpy(p, value, cchValue * sizeof(OLECHAR)); q = p + cchValue; } } return H; }