strchr.cpp
上传用户:xhy777
上传日期:2007-02-14
资源大小:24088k
文件大小:2k
源码类别:

系统编程

开发平台:

Visual C++

  1. /*****************************************************************/ 
  2. /**   Microsoft Windows for Workgroups **/
  3. /**   Copyright (C) Microsoft Corp., 1991-1992 **/
  4. /*****************************************************************/ 
  5. /*
  6. strchr.cxx
  7. NLS/DBCS-aware string class: strchr method
  8. This file contains the implementation of the strchr 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::strchr
  28. SYNOPSIS: Puts the index of the first occurrence of ch in *this
  29. into istrPos.
  30. ENTRY: pistrPos - points to ISTR in which to leave pos
  31. ch  - character sought
  32. istrStart- staring point in string.  If omitted, start
  33. at beginning
  34. EXIT: pistrPos
  35. RETURNS: TRUE if character found; otherwise FALSE
  36. NOTES: This routine only works for CHAR - not WCHAR.
  37. Hence it's useless for double-byte characters
  38. under MBCS.
  39. HISTORY:
  40. johnl 11/26/90 Written
  41. beng 07/22/91 Allow on erroneous strings; simplified CheckIstr
  42. ********************************************************************/
  43. BOOL NLS_STR::strchr( ISTR * pistrPos, const CHAR ch ) const
  44. {
  45. if ( QueryError() )
  46. return FALSE;
  47. UpdateIstr( pistrPos );
  48. CheckIstr( *pistrPos );
  49. const CHAR * pchStrRes = ::strchrf( QueryPch(), ch );
  50. if ( pchStrRes == NULL )
  51. {
  52. pistrPos->SetIB( strlen() );
  53. return FALSE;
  54. }
  55. pistrPos->SetIB((DWORD)(pchStrRes - QueryPch()));
  56. return TRUE;
  57. }
  58. BOOL NLS_STR::strchr( ISTR * pistrPos, const CHAR ch,
  59.   const ISTR & istrStart ) const
  60. {
  61. if ( QueryError() )
  62. return FALSE;
  63. CheckIstr( istrStart );
  64. UpdateIstr( pistrPos );
  65. CheckIstr( *pistrPos );
  66. const CHAR * pchStrRes = ::strchrf( QueryPch(istrStart), ch );
  67. if ( pchStrRes == NULL )
  68. {
  69. pistrPos->SetIB( strlen() );
  70. return FALSE;
  71. }
  72. pistrPos->SetIB((DWORD)(pchStrRes - QueryPch()));
  73. return TRUE;
  74. }