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.

116 lines
2.8 KiB

  1. /*****************************************************************/
  2. /** Microsoft Windows for Workgroups **/
  3. /** Copyright (C) Microsoft Corp., 1991-1992 **/
  4. /*****************************************************************/
  5. /*
  6. strqss.cxx
  7. NLS/DBCS-aware string class: QuerySubStr method
  8. This file contains the implementation of the QuerySubStr 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. // Magic value used below
  27. //
  28. #define CB_ENTIRE_STRING (-1)
  29. /*******************************************************************
  30. NAME: NLS_STR::QuerySubStr
  31. SYNOPSIS: Return a pointer to a new NLS_STR that contains the contents
  32. of *this from istrStart to:
  33. istrStart end of string or
  34. istrStart + istrEnd
  35. ENTRY:
  36. EXIT:
  37. RETURNS: Pointer to newly alloc'd NLS_STR, or NULL if error
  38. NOTES: The private method QuerySubStr(ISTR&, CB) is the worker
  39. method, the other two just check the parameters and
  40. pass the data. It is private since we can't allow the
  41. user to access the string on a byte basis
  42. CAVEAT: Note that this method creates an NLS_STR that the client is
  43. responsible for deleting.
  44. HISTORY:
  45. johnl 11/26/90 Created
  46. beng 04/26/91 Replaced CB wth INT; broke out CB_ENTIRE_STRING
  47. magic value
  48. beng 07/23/91 Allow on erroneous string; simplified CheckIstr
  49. ********************************************************************/
  50. NLS_STR * NLS_STR::QuerySubStr( const ISTR & istrStart, INT cbLen ) const
  51. {
  52. if (QueryError())
  53. return NULL;
  54. CheckIstr( istrStart );
  55. INT cchStrLen = ::strlenf(QueryPch(istrStart) );
  56. INT cbCopyLen = ( cbLen == CB_ENTIRE_STRING || cbLen >= cchStrLen )
  57. ? cchStrLen
  58. : cbLen;
  59. NLS_STR *pnlsNew = new NLS_STR( cbCopyLen + 1 );
  60. if ( pnlsNew == NULL )
  61. return NULL;
  62. if ( pnlsNew->QueryError() )
  63. {
  64. delete pnlsNew;
  65. return NULL;
  66. }
  67. ::memcpyf( pnlsNew->_pchData, QueryPch(istrStart), cbCopyLen );
  68. *(pnlsNew->_pchData + cbCopyLen) = '\0';
  69. pnlsNew->_cchLen = cbCopyLen;
  70. return pnlsNew;
  71. }
  72. NLS_STR * NLS_STR::QuerySubStr( const ISTR & istrStart ) const
  73. {
  74. return QuerySubStr( istrStart, CB_ENTIRE_STRING );
  75. }
  76. NLS_STR * NLS_STR::QuerySubStr( const ISTR & istrStart,
  77. const ISTR & istrEnd ) const
  78. {
  79. CheckIstr( istrEnd );
  80. UIASSERT( istrEnd.QueryIB() >= istrStart.QueryIB() );
  81. return QuerySubStr( istrStart, istrEnd - istrStart );
  82. }