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

Function EditCompressSpaces

src/Edit.c:3376–3466  ·  view source on GitHub ↗

============================================================================= EditCompressSpaces()

Source from the content-addressed store, hash-verified

3374// EditCompressSpaces()
3375//
3376void EditCompressSpaces ( HWND hwnd )
3377{
3378 if ( SC_SEL_RECTANGLE != SendMessage ( hwnd, SCI_GETSELECTIONMODE, 0, 0 ) ) {
3379 int iSelStart = ( int ) SendMessage ( hwnd, SCI_GETSELECTIONSTART, 0, 0 );
3380 int iSelEnd = ( int ) SendMessage ( hwnd, SCI_GETSELECTIONEND, 0, 0 );
3381 int iCurPos = ( int ) SendMessage ( hwnd, SCI_GETCURRENTPOS, 0, 0 );
3382 int iAnchorPos = ( int ) SendMessage ( hwnd, SCI_GETANCHOR, 0, 0 );
3383 int iLineStart = ( int ) SendMessage ( hwnd, SCI_LINEFROMPOSITION, ( WPARAM ) iSelStart, 0 );
3384 int iLineEnd = ( int ) SendMessage ( hwnd, SCI_LINEFROMPOSITION, ( WPARAM ) iSelEnd, 0 );
3385 int iLength = ( int ) SendMessage ( hwnd, SCI_GETLENGTH, 0, 0 );
3386 char *pszIn;
3387 char *pszOut;
3388 BOOL bIsLineStart, bIsLineEnd;
3389 BOOL bModified = FALSE;
3390 if ( iSelStart != iSelEnd ) {
3391 int cch = ( int ) SendMessage ( hwnd, SCI_GETSELTEXT, 0, 0 );
3392 pszIn = LocalAlloc ( LPTR, cch );
3393 pszOut = LocalAlloc ( LPTR, cch );
3394 SendMessage ( hwnd, SCI_GETSELTEXT, 0, ( LPARAM ) pszIn );
3395 bIsLineStart =
3396 ( iSelStart == SendMessage ( hwnd, SCI_POSITIONFROMLINE, ( WPARAM ) iLineStart, 0 ) );
3397 bIsLineEnd =
3398 ( iSelEnd == SendMessage ( hwnd, SCI_GETLINEENDPOSITION, ( WPARAM ) iLineEnd, 0 ) );
3399 } else {
3400 int cch = iLength + 1;
3401 pszIn = LocalAlloc ( GPTR, cch );
3402 pszOut = LocalAlloc ( GPTR, cch );
3403 SendMessage ( hwnd, SCI_GETTEXT, ( WPARAM ) cch, ( LPARAM ) pszIn );
3404 bIsLineStart = TRUE;
3405 bIsLineEnd = TRUE;
3406 }
3407 if ( pszIn && pszOut ) {
3408 char *ci, *co = pszOut;
3409 for ( ci = pszIn; *ci; ci++ ) {
3410 if ( *ci == ' ' || *ci == '\t' ) {
3411 if ( *ci == '\t' ) {
3412 bModified = TRUE;
3413 }
3414 while ( * ( ci + 1 ) == ' ' || * ( ci + 1 ) == '\t' ) {
3415 ci++;
3416 bModified = TRUE;
3417 }
3418 if ( !bIsLineStart && ( * ( ci + 1 ) != '\n' && * ( ci + 1 ) != '\r' ) ) {
3419 *co++ = ' ';
3420 } else {
3421 bModified = TRUE;
3422 }
3423 } else {
3424 if ( *ci == '\n' || *ci == '\r' ) {
3425 bIsLineStart = TRUE;
3426 } else {
3427 bIsLineStart = FALSE;
3428 }
3429 *co++ = *ci;
3430 }
3431 }
3432 if ( bIsLineEnd && co > pszOut && * ( co - 1 ) == ' ' ) {
3433 *--co = 0;

Callers 1

MsgCommandFunction · 0.85

Calls 1

MsgBoxFunction · 0.85

Tested by

no test coverage detected