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.

115 lines
2.5 KiB

  1. /*****************************************************************/
  2. /** Microsoft Windows for Workgroups **/
  3. /** Copyright (C) Microsoft Corp., 1991-1992 **/
  4. /*****************************************************************/
  5. /*
  6. strnchar.cxx
  7. NLS/DBCS-aware string class:QueryNumChar method
  8. This file contains the implementation of the QueryNumChar 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. terryk 04/04/91 Creation
  13. */
  14. #include "npcommon.h"
  15. extern "C"
  16. {
  17. #include <netlib.h>
  18. }
  19. #if defined(DEBUG)
  20. static const CHAR szFileName[] = __FILE__;
  21. #define _FILENAME_DEFINED_ONCE szFileName
  22. #endif
  23. #include <npassert.h>
  24. #include <npstring.h>
  25. #ifdef EXTENDED_STRINGS
  26. /*******************************************************************
  27. NAME: NLS_STR::QueryNumChar
  28. SYNOPSIS: return the total number of character within the string
  29. RETURNS: The number of logical character within the string
  30. NOTES:
  31. Treats erroneous string as having length 0
  32. HISTORY:
  33. terryk 04/04/91 Written
  34. beng 07/23/91 Allow on erroneous string
  35. ********************************************************************/
  36. INT NLS_STR::QueryNumChar() const
  37. {
  38. if (QueryError())
  39. return 0;
  40. ISTR istrCurPos( *this );
  41. INT cchCounter = 0;
  42. for ( ;
  43. this->QueryChar( istrCurPos ) != '\0';
  44. istrCurPos++, cchCounter ++ )
  45. ;
  46. return cchCounter;
  47. }
  48. /*******************************************************************
  49. NAME: NLS_STR::QueryTextLength
  50. SYNOPSIS: Calculate length of text in CHARS, sans terminator
  51. RETURNS: Count of CHARs
  52. NOTES:
  53. Compare QueryNumChar, which returns a number of glyphs.
  54. In a DBCS environment, this member will return 2 CHARS for
  55. each double-byte character, since a CHAR is there only 8 bits.
  56. HISTORY:
  57. beng 07/23/91 Created
  58. ********************************************************************/
  59. INT NLS_STR::QueryTextLength() const
  60. {
  61. return _cchLen / sizeof(CHAR);
  62. }
  63. /*******************************************************************
  64. NAME: NLS_STR::QueryTextSize
  65. SYNOPSIS: Calculate length of text in BYTES, including terminator
  66. RETURNS: Count of BYTES
  67. NOTES:
  68. QueryTextSize returns the number of bytes needed to duplicate
  69. the string into a byte vector.
  70. HISTORY:
  71. beng 07/23/91 Created
  72. ********************************************************************/
  73. INT NLS_STR::QueryTextSize() const
  74. {
  75. return _cchLen+sizeof(CHAR);
  76. }
  77. #endif // EXTENDED_STRINGS