Leaked source code of windows server 2003
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.

107 lines
2.7 KiB

  1. /*****************************************************************/
  2. /** Microsoft Windows for Workgroups **/
  3. /** Copyright (C) Microsoft Corp., 1991-1992 **/
  4. /*****************************************************************/
  5. /*
  6. stris.cxx
  7. NLS/DBCS-aware string class: InsertStr method
  8. This file contains the implementation of the InsertStr 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::InsertStr
  28. SYNOPSIS: Insert passed string into *this at istrStart
  29. ENTRY:
  30. EXIT: If this function returns FALSE, ReportError has been
  31. called to report the error that occurred.
  32. RETURN: TRUE on success, FALSE otherwise.
  33. NOTES: If *this is not STR_OWNERALLOCed and the inserted string
  34. won't fit in the allocated space for *this, then *this
  35. will be reallocated.
  36. HISTORY:
  37. johnl 11/28/90 Created
  38. rustanl 04/14/91 Fixed new length calculation. Report
  39. error if owner alloc'd and not enough
  40. space.
  41. beng 04/26/91 Replaced CB with INT
  42. beng 07/23/91 Allow on erroneous string;
  43. simplified CheckIstr
  44. ********************************************************************/
  45. BOOL NLS_STR::InsertStr( const NLS_STR & nlsIns, ISTR & istrStart )
  46. {
  47. if (QueryError() || !nlsIns)
  48. return FALSE;
  49. CheckIstr( istrStart );
  50. INT cbNewSize = strlen() + nlsIns.strlen() + 1 ; // include new null char
  51. if ( QueryAllocSize() < cbNewSize )
  52. {
  53. if ( IsOwnerAlloc())
  54. {
  55. // Big trouble! Report error, and return failure.
  56. //
  57. UIASSERT( !"Owner alloc'd string not big enough" );
  58. ReportError( WN_OUT_OF_MEMORY );
  59. return FALSE;
  60. }
  61. // Attempt to allocate more memory
  62. //
  63. if ( !realloc( cbNewSize ) )
  64. {
  65. ReportError( WN_OUT_OF_MEMORY );
  66. return FALSE;
  67. }
  68. }
  69. ::memmovef( (CHAR *)QueryPch(istrStart) + nlsIns.strlen(),
  70. (CHAR *)QueryPch(istrStart),
  71. ::strlenf(QueryPch(istrStart) ) + 1 );
  72. ::memmovef( (CHAR *)QueryPch(istrStart),
  73. (CHAR *)nlsIns.QueryPch(),
  74. nlsIns.strlen() );
  75. UIASSERT( cbNewSize >= 1 ); // should have been assigned something +1 above
  76. _cchLen = cbNewSize - 1; // don't count null character here
  77. IncVers();
  78. UpdateIstr( &istrStart ); // This ISTR does not become invalid
  79. // after the string update
  80. return TRUE;
  81. }