MCPcopy Create free account
hub / github.com/ProgerXP/Notepad2e / HL_Escape_html

Function HL_Escape_html

src/Edit.c:6766–6979  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6764
6765
6766void HL_Escape_html(HWND hwnd) {
6767 int beg, end , symb , res ;
6768 BOOL changed;
6769 struct Sci_TextToFind ttf;
6770 const char* _source = "&<>";
6771 const char* _target[] = { "&amp;", "&lt;", "&gt;" };
6772 assert(strlen(_source) == COUNTOF(_target));
6773 //
6774 //
6775 SendMessage(hwnd, SCI_BEGINUNDOACTION, 0, 0);
6776 beg = SendMessage(hwnd, SCI_GETSELECTIONSTART, 0, 0);
6777 end = SendMessage(hwnd, SCI_GETSELECTIONEND, 0, 0);
6778 if (beg == end){
6779 beg = 0;
6780 end = SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0);
6781 }
6782 //
6783 ttf.lpstrText = HL_Alloc(2);
6784 ttf.lpstrText[1] = '\0';
6785 changed = FALSE;
6786 for (symb = 0; symb < strlen(_source); ++symb)
6787 {
6788 ttf.chrg.cpMin = beg;
6789 ttf.chrg.cpMax = end;
6790 ttf.lpstrText[0] = _source[symb];
6791 //
6792 res = 0;
6793 while (-1 != res)
6794 {
6795 res = SendMessage(hwnd, SCI_FINDTEXT, 0, (LPARAM)&ttf);
6796 if (-1 != res){
6797#if 0
6798 if ('&' == _source[symb]){
6799#define _HL_LEN_TO_CHECK 5
6800 struct Sci_TextRange tr;
6801 int k;
6802 tr.chrg.cpMin = ttf.chrgText.cpMin;
6803 tr.chrg.cpMax = min(tr.chrg.cpMin + _HL_LEN_TO_CHECK, end);
6804 tr.lpstrText = HL_Alloc(tr.chrg.cpMax - tr.chrg.cpMin + 1);
6805 SendMessage(hwnd, SCI_GETTEXTRANGE, 0, (LPARAM)&tr);
6806 for (k = 0; k < COUNTOF(_target); ++k)
6807 {
6808 if (strstr(tr.lpstrText, _target[k])){
6809 res = -2;
6810 ttf.chrg.cpMin = ttf.chrgText.cpMax;
6811 break;
6812 }
6813 }
6814 //
6815 HL_Free(tr.lpstrText);
6816 }
6817 if (res >= 0){
6818#else
6819 {
6820#endif
6821 assert(ttf.chrgText.cpMax == ttf.chrgText.cpMin + 1);
6822 SendMessage(hwnd, SCI_DELETERANGE, ttf.chrgText.cpMin, 1);
6823 SendMessage(hwnd, SCI_INSERTTEXT, ttf.chrgText.cpMin, (LPARAM)_target[symb]);

Callers 1

MsgCommandFunction · 0.85

Calls 2

HL_AllocFunction · 0.85
HL_FreeFunction · 0.85

Tested by

no test coverage detected