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.

80 lines
1.9 KiB

  1. #include "npcommon.h"
  2. void InitSpn(
  3. char *abBits,
  4. char *abDBCBits,
  5. LPCSTR lpSpn
  6. )
  7. {
  8. LPCSTR lpCur;
  9. ::memset(abBits, '\0', 256/8);
  10. if (::fDBCSEnabled)
  11. ::memset(abDBCBits, '\0', 256/8);
  12. for (lpCur = lpSpn; *lpCur; ADVANCE(lpCur)) {
  13. if (IS_LEAD_BYTE(*lpCur)) {
  14. char chXOR = *lpCur ^ *(lpCur+1);
  15. SPN_SET(abDBCBits, chXOR);
  16. }
  17. else
  18. SPN_SET(abBits, *lpCur);
  19. }
  20. }
  21. // strspn(str, spn)
  22. //
  23. // Returns count of leading characters in str which exist
  24. // in spn; equivalent to returning the index of the first
  25. // character which is not in spn.
  26. UINT WINAPI strspnf(LPCSTR lpString, LPCSTR lpSpn)
  27. {
  28. char abBits[256/8];
  29. char abDBCBits[256/8];
  30. LPCSTR lpCur;
  31. InitSpn(abBits, abDBCBits, lpSpn);
  32. for (lpCur = lpString; *lpCur; ADVANCE(lpCur)) {
  33. if (IS_LEAD_BYTE(*lpCur)) {
  34. char chXOR = *lpCur ^ *(lpCur + 1);
  35. if (!SPN_TEST(abDBCBits, chXOR) ||
  36. (strchrf(lpSpn, GetTwoByteChar(lpCur)) == NULL))
  37. break;
  38. }
  39. else if (!SPN_TEST(abBits, *lpCur))
  40. break;
  41. }
  42. return (UINT) (lpCur - lpString);
  43. }
  44. // strcspn(str, spn)
  45. //
  46. // Returns count of leading characters in str which do not
  47. // exist in spn; equivalent to returning the index of the
  48. // first character which is in spn.
  49. UINT WINAPI strcspnf(LPCSTR lpString, LPCSTR lpSpn)
  50. {
  51. char abBits[256/8];
  52. char abDBCBits[256/8];
  53. LPCSTR lpCur;
  54. InitSpn(abBits, abDBCBits, lpSpn);
  55. for (lpCur = lpString; *lpCur; ADVANCE(lpCur)) {
  56. if (IS_LEAD_BYTE(*lpCur)) {
  57. char chXOR = *lpCur ^ *(lpCur + 1);
  58. if (SPN_TEST(abDBCBits, chXOR) &&
  59. (strchrf(lpSpn, GetTwoByteChar(lpCur)) != NULL))
  60. break;
  61. }
  62. else if (SPN_TEST(abBits, *lpCur))
  63. break;
  64. }
  65. return (UINT)(lpCur-lpString);
  66. }