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

Function EditURLEncode

src/Edit.c:1664–1728  ·  view source on GitHub ↗

============================================================================= EditURLEncode()

Source from the content-addressed store, hash-verified

1662// EditURLEncode()
1663//
1664void EditURLEncode ( HWND hwnd )
1665{
1666 int cchTextW;
1667 int iCurPos;
1668 int iAnchorPos;
1669 UINT cpEdit;
1670 iCurPos = ( int ) SendMessage ( hwnd, SCI_GETCURRENTPOS, 0, 0 );
1671 iAnchorPos = ( int ) SendMessage ( hwnd, SCI_GETANCHOR, 0, 0 );
1672 if ( iCurPos != iAnchorPos ) {
1673 if ( SC_SEL_RECTANGLE != SendMessage ( hwnd, SCI_GETSELECTIONMODE, 0, 0 ) ) {
1674 int iSelCount = ( int ) SendMessage ( hwnd, SCI_GETSELECTIONEND, 0, 0 ) -
1675 ( int ) SendMessage ( hwnd, SCI_GETSELECTIONSTART, 0, 0 );
1676 char *pszText;
1677 LPWSTR pszTextW;
1678 DWORD cchEscaped;
1679 char *pszEscaped;
1680 DWORD cchEscapedW;
1681 LPWSTR pszEscapedW;
1682 pszText = LocalAlloc ( LPTR, ( iSelCount ) + 2 );
1683 if ( pszText == NULL ) {
1684 return;
1685 }
1686 pszTextW = LocalAlloc ( LPTR, ( iSelCount * 2 ) + 2 );
1687 if ( pszTextW == NULL ) {
1688 LocalFree ( pszText );
1689 return;
1690 }
1691 SendMessage ( hwnd, SCI_GETSELTEXT, 0, ( LPARAM ) pszText );
1692 cpEdit = ( UINT ) SendMessage ( hwnd, SCI_GETCODEPAGE, 0, 0 );
1693 cchTextW = MultiByteToWideChar ( cpEdit, 0, pszText, iSelCount, pszTextW, ( int ) LocalSize ( pszTextW ) / sizeof ( WCHAR ) );
1694 pszEscaped = LocalAlloc ( LPTR, LocalSize ( pszText ) * 3 );
1695 if ( pszEscaped == NULL ) {
1696 LocalFree ( pszText );
1697 LocalFree ( pszTextW );
1698 return;
1699 }
1700 pszEscapedW = LocalAlloc ( LPTR, LocalSize ( pszTextW ) * 3 );
1701 if ( pszEscapedW == NULL ) {
1702 LocalFree ( pszText );
1703 LocalFree ( pszTextW );
1704 LocalFree ( pszEscaped );
1705 return;
1706 }
1707 cchEscapedW = ( int ) LocalSize ( pszEscapedW ) / sizeof ( WCHAR );
1708 UrlEscape ( pszTextW, pszEscapedW, &cchEscapedW, URL_ESCAPE_SEGMENT_ONLY );
1709 cchEscaped = WideCharToMultiByte ( cpEdit, 0, pszEscapedW, cchEscapedW, pszEscaped, ( int ) LocalSize ( pszEscaped ), NULL, NULL );
1710 if ( iCurPos < iAnchorPos ) {
1711 iAnchorPos = iCurPos + cchEscaped;
1712 } else {
1713 iCurPos = iAnchorPos + cchEscaped;
1714 }
1715 SendMessage ( hwnd, SCI_BEGINUNDOACTION, 0, 0 );
1716 SendMessage ( hwnd, SCI_CLEAR, 0, 0 );
1717 SendMessage ( hwnd, SCI_ADDTEXT, ( WPARAM ) cchEscaped, ( LPARAM ) pszEscaped );
1718 SendMessage ( hwnd, SCI_SETSEL, ( WPARAM ) iAnchorPos, ( LPARAM ) iCurPos );
1719 SendMessage ( hwnd, SCI_ENDUNDOACTION, 0, 0 );
1720 LocalFree ( pszText );
1721 LocalFree ( pszTextW );

Callers 1

MsgCommandFunction · 0.85

Calls 1

MsgBoxFunction · 0.85

Tested by

no test coverage detected