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.

70 lines
1.8 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1992 - 1999
  5. *
  6. * File: mnemonic.h
  7. *
  8. * Contents: Mnemonic helpers
  9. *
  10. * History: 31-Aug-98 jeffro Created
  11. *
  12. *--------------------------------------------------------------------------*/
  13. #ifndef MNEMONIC_H
  14. #define MNEMONIC_H
  15. #pragma once
  16. /*+-------------------------------------------------------------------------*
  17. * GetMnemonicChar
  18. *
  19. * Returns the mnemonic character for the input string, 0 if none.
  20. *--------------------------------------------------------------------------*/
  21. template<class T>
  22. T GetMnemonicChar (const T* pszText, const T** pchMnemonic = NULL)
  23. {
  24. const T* pchT = pszText;
  25. const T chMnemonicMarker = '&';
  26. T chMnemonic = 0;
  27. // find the mnemonic character
  28. for (bool fContinue = true; fContinue; )
  29. {
  30. // find the next mnemonic marker
  31. while ((*pchT != 0) && (*pchT != chMnemonicMarker))
  32. pchT++;
  33. // no mnemonic marker?
  34. if (*pchT != chMnemonicMarker)
  35. break;
  36. switch (*++pchT)
  37. {
  38. // double mnemonic marker, keep going
  39. case chMnemonicMarker:
  40. pchT++;
  41. break;
  42. // end of string, no mnemonic
  43. case 0:
  44. fContinue = false;
  45. break;
  46. // found a mnemonic
  47. default:
  48. if (pchMnemonic != NULL)
  49. *pchMnemonic = pchT;
  50. chMnemonic = *pchT;
  51. fContinue = false;
  52. break;
  53. }
  54. }
  55. return (chMnemonic);
  56. }
  57. #endif /* MNEMONIC_H */