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

Function EditURLDecode

src/Edit.c:1735–1799  ·  view source on GitHub ↗

============================================================================= EditURLDecode()

Source from the content-addressed store, hash-verified

1733// EditURLDecode()
1734//
1735void EditURLDecode ( HWND hwnd )
1736{
1737 int cchTextW;
1738 int iCurPos;
1739 int iAnchorPos;
1740 UINT cpEdit;
1741 iCurPos = ( int ) SendMessage ( hwnd, SCI_GETCURRENTPOS, 0, 0 );
1742 iAnchorPos = ( int ) SendMessage ( hwnd, SCI_GETANCHOR, 0, 0 );
1743 if ( iCurPos != iAnchorPos ) {
1744 if ( SC_SEL_RECTANGLE != SendMessage ( hwnd, SCI_GETSELECTIONMODE, 0, 0 ) ) {
1745 int iSelCount = ( int ) SendMessage ( hwnd, SCI_GETSELECTIONEND, 0, 0 ) -
1746 ( int ) SendMessage ( hwnd, SCI_GETSELECTIONSTART, 0, 0 );
1747 char *pszText;
1748 LPWSTR pszTextW;
1749 DWORD cchUnescaped;
1750 char *pszUnescaped;
1751 DWORD cchUnescapedW;
1752 LPWSTR pszUnescapedW;
1753 pszText = LocalAlloc ( LPTR, ( iSelCount ) + 2 );
1754 if ( pszText == NULL ) {
1755 return;
1756 }
1757 pszTextW = LocalAlloc ( LPTR, ( iSelCount * 2 ) + 2 );
1758 if ( pszTextW == NULL ) {
1759 LocalFree ( pszText );
1760 return;
1761 }
1762 SendMessage ( hwnd, SCI_GETSELTEXT, 0, ( LPARAM ) pszText );
1763 cpEdit = ( UINT ) SendMessage ( hwnd, SCI_GETCODEPAGE, 0, 0 );
1764 cchTextW = MultiByteToWideChar ( cpEdit, 0, pszText, iSelCount, pszTextW, ( int ) LocalSize ( pszTextW ) / sizeof ( WCHAR ) );
1765 pszUnescaped = LocalAlloc ( LPTR, LocalSize ( pszText ) * 3 );
1766 if ( pszUnescaped == NULL ) {
1767 LocalFree ( pszText );
1768 LocalFree ( pszTextW );
1769 return;
1770 }
1771 pszUnescapedW = LocalAlloc ( LPTR, LocalSize ( pszTextW ) * 3 );
1772 if ( pszUnescapedW == NULL ) {
1773 LocalFree ( pszText );
1774 LocalFree ( pszTextW );
1775 LocalFree ( pszUnescaped );
1776 return;
1777 }
1778 cchUnescapedW = ( int ) LocalSize ( pszUnescapedW ) / sizeof ( WCHAR );
1779 UrlUnescape ( pszTextW, pszUnescapedW, &cchUnescapedW, 0 );
1780 cchUnescaped = WideCharToMultiByte ( cpEdit, 0, pszUnescapedW, cchUnescapedW, pszUnescaped, ( int ) LocalSize ( pszUnescaped ), NULL, NULL );
1781 if ( iCurPos < iAnchorPos ) {
1782 iAnchorPos = iCurPos + cchUnescaped;
1783 } else {
1784 iCurPos = iAnchorPos + cchUnescaped;
1785 }
1786 SendMessage ( hwnd, SCI_BEGINUNDOACTION, 0, 0 );
1787 SendMessage ( hwnd, SCI_CLEAR, 0, 0 );
1788 SendMessage ( hwnd, SCI_ADDTEXT, ( WPARAM ) cchUnescaped, ( LPARAM ) pszUnescaped );
1789 SendMessage ( hwnd, SCI_SETSEL, ( WPARAM ) iAnchorPos, ( LPARAM ) iCurPos );
1790 SendMessage ( hwnd, SCI_ENDUNDOACTION, 0, 0 );
1791 LocalFree ( pszText );
1792 LocalFree ( pszTextW );

Callers 1

MsgCommandFunction · 0.85

Calls 1

MsgBoxFunction · 0.85

Tested by

no test coverage detected