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.

262 lines
5.0 KiB

  1. /*****************************************************************/
  2. /** Microsoft Windows for Workgroups **/
  3. /** Copyright (C) Microsoft Corp., 1991-1992 **/
  4. /*****************************************************************/
  5. /*
  6. strmisc.cxx
  7. Miscellaneous members of the string classes
  8. The NLS_STR and ISTR classes have many inline member functions
  9. which bloat clients, especially in debug versions. This file
  10. gives those unhappy functions a new home.
  11. FILE HISTORY:
  12. beng 04/26/91 Created (relocated from string.hxx)
  13. gregj 05/22/92 Added ToOEM, ToAnsi methods
  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. #ifdef DEBUG
  27. /*******************************************************************
  28. NAME: NLS_STR::CheckIstr
  29. SYNOPSIS: Checks association between ISTR and NLS_STR instances
  30. ENTRY: istr - ISTR to check against this NLS_STR
  31. NOTES:
  32. Does nothing in retail build.
  33. HISTORY:
  34. beng 07/23/91 Header added; removed redundant "nls" parameter.
  35. ********************************************************************/
  36. VOID NLS_STR::CheckIstr( const ISTR& istr ) const
  37. {
  38. UIASSERT( (istr).QueryPNLS() == this );
  39. UIASSERT( (istr).QueryVersion() == QueryVersion() );
  40. }
  41. VOID NLS_STR::IncVers()
  42. {
  43. _usVersion++;
  44. }
  45. VOID NLS_STR::InitializeVers()
  46. {
  47. _usVersion = 0;
  48. }
  49. VOID NLS_STR::UpdateIstr( ISTR *pistr ) const
  50. {
  51. pistr->SetVersion( QueryVersion() );
  52. }
  53. USHORT NLS_STR::QueryVersion() const
  54. {
  55. return _usVersion;
  56. }
  57. const CHAR * NLS_STR::QueryPch() const
  58. {
  59. if (QueryError()) {
  60. UIASSERT(FALSE);
  61. return NULL;
  62. }
  63. return _pchData;
  64. }
  65. const CHAR * NLS_STR::QueryPch( const ISTR& istr ) const
  66. {
  67. if (QueryError())
  68. return NULL;
  69. CheckIstr( istr );
  70. return _pchData+istr.QueryIB();
  71. }
  72. WCHAR NLS_STR::QueryChar( const ISTR& istr ) const
  73. {
  74. if (QueryError())
  75. return 0;
  76. CheckIstr( istr );
  77. return *(_pchData+istr.QueryIB());
  78. }
  79. #endif // DEBUG
  80. /*******************************************************************
  81. NAME: NLS_STR::ToOEM
  82. SYNOPSIS: Convert string to OEM character set
  83. ENTRY: No parameters
  84. EXIT: String is in OEM character set
  85. RETURNS:
  86. NOTES: If the string is already OEM, nothing happens.
  87. A string may be constructed as OEM by constructing
  88. as usual, then calling SetOEM(). Casemap conversion
  89. does NOT work on OEM strings!
  90. HISTORY:
  91. gregj 05/22/92 Created
  92. ********************************************************************/
  93. VOID NLS_STR::ToOEM()
  94. {
  95. if (IsOEM())
  96. return; // string is already OEM
  97. SetOEM();
  98. #ifdef WIN31
  99. ::AnsiToOem( _pchData, _pchData );
  100. #endif
  101. }
  102. /*******************************************************************
  103. NAME: NLS_STR::ToAnsi
  104. SYNOPSIS: Convert string to ANSI character set
  105. ENTRY: No parameters
  106. EXIT: String is in ANSI character set
  107. RETURNS:
  108. NOTES: If the string is already ANSI (the default), nothing
  109. happens.
  110. HISTORY:
  111. gregj 05/22/92 Created
  112. ********************************************************************/
  113. VOID NLS_STR::ToAnsi()
  114. {
  115. if (!IsOEM())
  116. return; // string is already ANSI
  117. SetAnsi();
  118. #ifdef WIN31
  119. ::OemToAnsiBuff( _pchData, _pchData, _cbData);
  120. #endif
  121. }
  122. /*******************************************************************
  123. NAME: NLS_STR::SetOEM
  124. SYNOPSIS: Declares string to be in OEM character set
  125. ENTRY: No parameters
  126. EXIT: OEM flag set
  127. RETURNS:
  128. NOTES: Use this method if you construct a string which is
  129. known to be in the OEM character set (e.g., it came
  130. back from a Net API).
  131. HISTORY:
  132. gregj 05/22/92 Created
  133. ********************************************************************/
  134. VOID NLS_STR::SetOEM()
  135. {
  136. _fsFlags |= SF_OEM;
  137. }
  138. /*******************************************************************
  139. NAME: NLS_STR::SetAnsi
  140. SYNOPSIS: Declares string to be in ANSI character set
  141. ENTRY: No parameters
  142. EXIT: OEM flag set
  143. RETURNS:
  144. NOTES: This method is used primarily by NLS_STR itself,
  145. when an ANSI string is assigned to a previously
  146. OEM one.
  147. HISTORY:
  148. gregj 05/22/92 Created
  149. ********************************************************************/
  150. VOID NLS_STR::SetAnsi()
  151. {
  152. _fsFlags &= ~SF_OEM;
  153. }
  154. /*******************************************************************
  155. NAME: NLS_STR::IsDBCSLeadByte
  156. SYNOPSIS: Returns whether a character is a lead byte or not
  157. ENTRY: ch - byte to check
  158. EXIT: TRUE if "ch" is a lead byte
  159. RETURNS:
  160. NOTES: This method works whether the string is OEM or ANSI.
  161. In a non-DBCS build, this function is inline and
  162. always returns FALSE.
  163. HISTORY:
  164. gregj 04/02/93 Created
  165. ********************************************************************/
  166. BOOL NLS_STR::IsDBCSLeadByte( CHAR ch ) const
  167. {
  168. return IS_LEAD_BYTE(ch);
  169. }