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.

98 lines
2.3 KiB

  1. /*************************************************************************
  2. *
  3. * DBCS.C
  4. *
  5. * DBCS routines, ported from DOS
  6. *
  7. * Copyright (c) 1995 Microsoft Corporation
  8. *
  9. * $Log: N:\NT\PRIVATE\NW4\NWSCRIPT\VCS\DBCS.C $
  10. *
  11. * Rev 1.1 22 Dec 1995 14:24:10 terryt
  12. * Add Microsoft headers
  13. *
  14. * Rev 1.0 15 Nov 1995 18:06:44 terryt
  15. * Initial revision.
  16. *
  17. * Rev 1.1 25 Aug 1995 16:22:26 terryt
  18. * Capture support
  19. *
  20. * Rev 1.0 15 May 1995 19:10:24 terryt
  21. * Initial revision.
  22. *
  23. *************************************************************************/
  24. /*
  25. ** dbcs.c - DBCS functions for DOS apps.
  26. **
  27. ** Written by RokaH and DavidDi.
  28. */
  29. /* Headers
  30. **********/
  31. // IsDBCSLeadByte taken out of NT because there is one built in.
  32. // I left the Next and Prev in because I don't know whether this
  33. // algorithm is "safer" than the built in code.
  34. #include "common.h"
  35. /*
  36. ** unsigned char *NWAnsiNext(unsigned char *puch);
  37. **
  38. ** Moves to the next character in a string.
  39. **
  40. ** Arguments: puch - pointer to current location in string
  41. **
  42. ** Returns: char * - Pointer to next character in string.
  43. **
  44. ** Globals: none
  45. **
  46. ** N.b., if puch points to a null character, NWAnsiNext() will return puch.
  47. */
  48. unsigned char *NWAnsiNext(unsigned char *puch)
  49. {
  50. if (*puch == '\0')
  51. return(puch);
  52. else if (IsDBCSLeadByte(*puch))
  53. puch++;
  54. puch++;
  55. return(puch);
  56. }
  57. /*
  58. ** unsigned char *NWAnsiPrev(unsigned char *psz, unsigned char *puch);
  59. **
  60. ** Moves back one character in a string.
  61. **
  62. ** Arguments: psz - pointer to start of string
  63. ** puch - pointer to current location in string
  64. **
  65. ** Returns: char * - Pointer to previous character in string.
  66. **
  67. ** Globals: none
  68. **
  69. ** N.b., if puch <= psz, NWAnsiPrev() will return psz.
  70. **
  71. ** This function is implemented in a very slow fashion because we do not wish
  72. ** to trust that the given string is necessarily DBCS "safe," i.e., contains
  73. ** only single-byte characters and valid DBCS characters. So we start from
  74. ** the beginning of the string and work our way forward.
  75. */
  76. unsigned char *NWAnsiPrev(unsigned char *psz, unsigned char *puch)
  77. {
  78. unsigned char *puchPrevious;
  79. do
  80. {
  81. puchPrevious = psz;
  82. psz = NWAnsiNext(psz);
  83. } while (*psz != '\0' && psz < puch);
  84. return(puchPrevious);
  85. }