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.

117 lines
3.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1996, Microsoft Corporation.
  4. //
  5. // File: mbutil.hxx
  6. //
  7. // Contents: MultiByte To Unicode and ViceVersa utility functions and
  8. // classes.
  9. //
  10. // History: 96/Jan/3 DwightKr Created
  11. // Aug 20 1996 Srikants Moved from escurl.hxx to this file
  12. //
  13. //----------------------------------------------------------------------------
  14. #pragma once
  15. //+---------------------------------------------------------------------------
  16. //----------------------------------------------------------------------------
  17. inline void ConvertBackSlashToSlash( WCHAR * wcsPath )
  18. {
  19. Win4Assert( 0 != wcsPath );
  20. while ( 0 != *wcsPath )
  21. {
  22. if ( L'\\' == *wcsPath )
  23. {
  24. *wcsPath = L'/';
  25. }
  26. wcsPath++;
  27. }
  28. }
  29. //+---------------------------------------------------------------------------
  30. //----------------------------------------------------------------------------
  31. inline void ConvertSlashToBackSlash( WCHAR * wcsPath )
  32. {
  33. if ( 0 == wcsPath )
  34. return;
  35. while ( 0 != *wcsPath )
  36. {
  37. if ( L'/' == *wcsPath )
  38. {
  39. *wcsPath = L'\\';
  40. }
  41. wcsPath++;
  42. }
  43. }
  44. ULONG MultiByteToXArrayWideChar( BYTE const * pbBuffer,
  45. ULONG cbBuffer,
  46. UINT codePage,
  47. XArray<WCHAR> & wcsBuffer );
  48. DWORD WideCharToXArrayMultiByte( WCHAR const * wcsMessage,
  49. ULONG cwcMessage,
  50. UINT codePage,
  51. XArray<BYTE> & pszMessage );
  52. //+---------------------------------------------------------------------------
  53. //
  54. // Function: wcsipattern
  55. //
  56. // Synopsis: A case-insensitive, WCHAR implemtation of strstr.
  57. //
  58. // Arguments: [wcsString] - string to search
  59. // [wcsPattern] - pattern to look for
  60. //
  61. // Returns: pointer to pattern, 0 if no match found.
  62. //
  63. // History: 96/Jan/03 DwightKr created
  64. //
  65. // NOTE: Warning the first character of wcsPattern must be a case
  66. // insensitive letter. This results in a significant performance
  67. // improvement.
  68. //
  69. //----------------------------------------------------------------------------
  70. WCHAR * wcsipattern( WCHAR * wcsString, WCHAR const * wcsPattern );
  71. //+---------------------------------------------------------------------------
  72. //
  73. // Function: wcs2chr, inline
  74. //
  75. // Synopsis: An optimized strstr for one or two character WCHAR strings
  76. //
  77. // Arguments: [wcsString] - string to search
  78. // [wcsPattern] - pattern to look for
  79. //
  80. // Returns: pointer to pattern in string, 0 if no match found.
  81. //
  82. // History: 96/Apr/02 Alanw created
  83. //
  84. //----------------------------------------------------------------------------
  85. inline WCHAR * wcs2chr( WCHAR * wcsString, WCHAR const * wcsPattern )
  86. {
  87. Win4Assert ( wcsPattern != 0 &&
  88. wcslen( wcsPattern ) > 0 &&
  89. wcslen( wcsPattern ) <= 2 );
  90. Win4Assert( wcsPattern[0] == towupper(wcsPattern[0]) &&
  91. wcsPattern[1] == towupper(wcsPattern[1]) );
  92. while ( wcsString = wcschr( wcsString, *wcsPattern ) )
  93. {
  94. if ( wcsPattern[1] == L'\0' || wcsPattern[1] == wcsString[1] )
  95. break;
  96. wcsString++;
  97. }
  98. return wcsString;
  99. }