Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
2.7 KiB

  1. /*****************************************************************/
  2. /** Microsoft Windows for Workgroups **/
  3. /** Copyright (C) Microsoft Corp., 1991-1992 **/
  4. /*****************************************************************/
  5. /*
  6. strrss.cxx
  7. NLS/DBCS-aware string class: strrss method
  8. This file contains the implementation of the strrss method
  9. for the STRING class. It is separate so that clients of STRING which
  10. do not use this operator need not link to it.
  11. FILE HISTORY:
  12. beng 01/18/91 Separated from original monolithic .cxx
  13. beng 02/07/91 Uses lmui.hxx
  14. */
  15. #include "npcommon.h"
  16. extern "C"
  17. {
  18. #include <netlib.h>
  19. }
  20. #if defined(DEBUG)
  21. static const CHAR szFileName[] = __FILE__;
  22. #define _FILENAME_DEFINED_ONCE szFileName
  23. #endif
  24. #include <npassert.h>
  25. #include <npstring.h>
  26. /*******************************************************************
  27. NAME: NLS_STR::ReplSubStr
  28. SYNOPSIS: Replace the substring starting at istrStart with the
  29. passed nlsRepl string.
  30. If both a start and end is passed, then the operation is
  31. equivalent to a DelSubStr( start, end ) and an
  32. InsertSubStr( start ).
  33. If just a start is passed in, then the operation is
  34. equivalent to DelSubStr( start ), concat new string to end.
  35. The ReplSubStr( NLS_STR&, istrStart&, INT cbDel) method is
  36. private.
  37. ENTRY:
  38. EXIT:
  39. NOTES:
  40. HISTORY:
  41. johnl 11/29/90 Created
  42. beng 04/26/91 Replaced CB with INT
  43. beng 07/23/91 Allow on erroneous string; simplified CheckIstr
  44. ********************************************************************/
  45. VOID NLS_STR::ReplSubStr( const NLS_STR & nlsRepl, ISTR& istrStart )
  46. {
  47. if (QueryError() || !nlsRepl)
  48. return;
  49. CheckIstr( istrStart );
  50. DelSubStr( istrStart );
  51. strcat( nlsRepl );
  52. }
  53. VOID NLS_STR::ReplSubStr( const NLS_STR& nlsRepl,
  54. ISTR& istrStart,
  55. const ISTR& istrEnd )
  56. {
  57. CheckIstr( istrEnd );
  58. UIASSERT( istrEnd.QueryIB() >= istrStart.QueryIB() );
  59. ReplSubStr( nlsRepl, istrStart, istrEnd - istrStart );
  60. }
  61. VOID NLS_STR::ReplSubStr( const NLS_STR& nlsRepl,
  62. ISTR& istrStart,
  63. INT cbToBeDeleted )
  64. {
  65. if (QueryError() || !nlsRepl)
  66. return;
  67. CheckIstr( istrStart );
  68. INT cbRequired = strlen() - cbToBeDeleted + nlsRepl.strlen() + 1;
  69. if ( !IsOwnerAlloc() && QueryAllocSize() < cbRequired )
  70. {
  71. if ( !realloc( cbRequired ) )
  72. {
  73. ReportError( WN_OUT_OF_MEMORY );
  74. return;
  75. }
  76. }
  77. else
  78. UIASSERT( QueryAllocSize() >= cbRequired );
  79. CHAR * pchStart = (CHAR *)QueryPch(istrStart) + cbToBeDeleted;
  80. ::memmovef( pchStart + nlsRepl.strlen()-cbToBeDeleted,
  81. pchStart,
  82. ::strlenf( pchStart ) + 1 );
  83. ::memmovef( (CHAR *)QueryPch(istrStart),
  84. nlsRepl._pchData,
  85. nlsRepl.strlen() );
  86. _cchLen = strlen() + nlsRepl.strlen() - cbToBeDeleted;
  87. IncVers();
  88. UpdateIstr( &istrStart );
  89. }