[Plib-cvs] plib/src/pui pu.h,1.134,1.135 puFileSelector.cxx,1.30,1.31 puInput.cxx,1.29,1.30 puLargeI
Brought to you by:
sjbaker
From: Sebastian U. <ud...@us...> - 2002-09-24 22:18:12
|
Update of /cvsroot/plib/plib/src/pui In directory usw-pr-cvs1:/tmp/cvs-serv17123 Modified Files: pu.h puFileSelector.cxx puInput.cxx puLargeInput.cxx Log Message: John F. Fay / me: Major improvements to the efficience of string handling in PUI Index: pu.h =================================================================== RCS file: /cvsroot/plib/plib/src/pui/pu.h,v retrieving revision 1.134 retrieving revision 1.135 diff -u -d -r1.134 -r1.135 --- pu.h 21 Sep 2002 17:47:09 -0000 1.134 +++ pu.h 24 Sep 2002 22:18:07 -0000 1.135 @@ -1524,25 +1524,9 @@ void setValidData ( const char *data ) { delete [] valid_data ; - - if ( data != NULL ) - valid_data = ulStrDup ( data ) ; - else - valid_data = NULL ; - } - - void addValidData ( const char *data ) [...71 lines suppressed...] - strcpy ( new_data, "\0" ) ; - if ( valid_data ) strcat ( new_data, valid_data ) ; - if ( data ) strcat ( new_data, data ) ; - delete [] valid_data ; - valid_data = new_data ; + valid_data = data != NULL ? ulStrDup ( data ) : NULL ; } + void addValidData ( const char *data ) ; int isValidCharacter ( char c ) const { @@ -1920,7 +1868,7 @@ { rejectInput () ; normalize_cursors () ; - if ( down_cb ) (*down_cb)(this) ; + if ( down_cb != NULL ) (*down_cb)(this) ; } void enableInput ( void ) { input_disabled = FALSE ; } Index: puFileSelector.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/pui/puFileSelector.cxx,v retrieving revision 1.30 retrieving revision 1.31 diff -u -d -r1.30 -r1.31 --- puFileSelector.cxx 21 Sep 2002 17:47:09 -0000 1.30 +++ puFileSelector.cxx 24 Sep 2002 22:18:07 -0000 1.31 @@ -53,6 +53,7 @@ #define DOTDOTSLASH "../" #define SLASH "/" #endif +#define SLASH_LEN 1 static void puFileSelectorHandleSlider ( puObject * slider ) { @@ -317,44 +318,59 @@ dflag = NULL ; num_files = 0 ; [...121 lines suppressed...] { - files[ ifile ] = new char[ strlen(dp->d_name)+4 ] ; - strcpy ( files [ ifile ], "[" ) ; - strcat ( files [ ifile ], dp->d_name ) ; - strcat ( files [ ifile ], "]" ) ; + files[ ifile ] = new char[ name_len + 3 ] ; + + files [ ifile ] [ 0 ] = '[' ; + memcpy ( files [ ifile ] + 1, dp->d_name, name_len ) ; + strcpy ( files [ ifile ] + 1 + name_len, "]" ) ; } else { - files[ ifile ] = new char[ strlen(dp->d_name)+1 ] ; - strcpy ( files [ ifile ], dp->d_name ) ; + files[ ifile ] = new char[ name_len + 1 ] ; + memcpy ( files [ ifile ], dp->d_name, name_len + 1 ) ; /* Plus one to include the final '\0' */ } ifile++ ; Index: puInput.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/pui/puInput.cxx,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- puInput.cxx 19 Sep 2002 23:32:58 -0000 1.29 +++ puInput.cxx 24 Sep 2002 22:18:07 -0000 1.30 @@ -389,16 +389,18 @@ break ; case 0x16 /* ^V */ : /* Paste buffer into text */ - if ( select_start_position != select_end_position ) - removeSelectRegion () ; + { + if ( select_start_position != select_end_position ) + removeSelectRegion () ; - p = new char [ strlen ( getStringValue () ) - + strlen ( puGetPasteBuffer () ) - + 1 ] ; - strncpy ( p, getStringValue (), cursor_position ) ; - strcpy ( p + cursor_position, puGetPasteBuffer () ) ; - strcat ( p, getStringValue () + cursor_position ) ; - cursor_position += strlen ( puGetPasteBuffer () ) ; + int str_val_len = strlen ( getStringValue () ) ; + int paste_len = strlen ( puGetPasteBuffer () ) ; + p = new char [ str_val_len + paste_len + 1 ] ; + memcpy ( p, getStringValue (), cursor_position ) ; + memcpy ( p + cursor_position, puGetPasteBuffer (), paste_len ) ; + memcpy ( p + cursor_position + paste_len, getStringValue () + cursor_position, str_val_len - cursor_position + 1 ) ; + cursor_position += paste_len ; + } break ; @@ -432,4 +434,41 @@ return TRUE ; } + +void puInput::addValidData ( const char *data ) +{ + int valid_len = valid_data != NULL ? strlen ( valid_data ) : 0 ; + int data_len = data != NULL ? strlen ( data ) : 0 ; + int new_data_len = valid_len + data_len ; + + char *new_data = new char [ new_data_len + 1 ] ; + + if ( valid_len != 0 ) + memcpy ( new_data, valid_data, valid_len ) ; + if ( data_len != 0 ) + memcpy ( new_data + valid_len, data, data_len ) ; + + new_data [ new_data_len ] = '\0' ; + delete [] valid_data ; + valid_data = new_data ; +} + + +puInput::puInput ( int minx, int miny, int maxx, int maxy ) : + puObject ( minx, miny, maxx, maxy ) +{ + type |= PUCLASS_INPUT ; + + accepting = FALSE ; + + cursor_position = 0 ; + select_start_position = -1 ; + select_end_position = -1 ; + + valid_data = NULL ; + input_disabled = FALSE ; + + setColourScheme ( 0.8f, 0.7f, 0.7f ) ; /* Yeukky Pink */ + setColour ( PUCOL_MISC, 0.1f, 0.1f, 1.0f ) ; /* Colour of 'I' bar cursor */ +} Index: puLargeInput.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/pui/puLargeInput.cxx,v retrieving revision 1.42 retrieving revision 1.43 diff -u -d -r1.42 -r1.43 --- puLargeInput.cxx 21 Sep 2002 17:47:09 -0000 1.42 +++ puLargeInput.cxx 24 Sep 2002 22:18:07 -0000 1.43 @@ -77,11 +77,11 @@ void puLargeInput::removeSelectRegion ( void ) { char *text = getStringValue () ; - char *p = new char [ strlen ( text ) + 1 - + int text_len = strlen ( text ) ; + char *p = new char [ text_len + 1 - ( select_end_position - select_start_position ) ] ; - strncpy ( p, text, select_start_position ) ; - p [ select_start_position ] = '\0' ; - strcat ( p, (text + select_end_position ) ) ; + memcpy ( p, text, select_start_position ) ; [...237 lines suppressed...] } +void puLargeInput::addValidData ( const char *data ) +{ + int valid_len = valid_data != NULL ? strlen ( valid_data ) : 0 ; + int data_len = data != NULL ? strlen ( data ) : 0 ; + int new_data_len = valid_len + data_len ; + + char *new_data = new char [ new_data_len + 1 ] ; + + if ( valid_len != 0 ) + memcpy ( new_data, valid_data, valid_len ) ; + if ( data_len != 0 ) + memcpy ( new_data + valid_len, data, data_len ) ; + + new_data [ new_data_len ] = '\0' ; + delete [] valid_data ; + valid_data = new_data ; +} |