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.

84 lines
1.6 KiB

  1. #include <TChar.h>
  2. #include <ComDef.h>
  3. #include <Windows.h>
  4. #include <Validation.h>
  5. #include <ResStr.h>
  6. // IsValidPrefixOrSuffix Function
  7. bool __stdcall IsValidPrefixOrSuffix(LPCTSTR pszPrefixOrSuffix)
  8. {
  9. bool bValid = false;
  10. if (pszPrefixOrSuffix)
  11. {
  12. int cchPrefixOrSuffix = _tcslen(pszPrefixOrSuffix);
  13. // if (cchPrefixOrSuffix <= MAXIMUM_PREFIX_SUFFIX_LENGTH)
  14. // {
  15. // BOOL bDefaultUsed;
  16. // CHAR szAnsi[2 * MAXIMUM_PREFIX_SUFFIX_LENGTH];
  17. // int cchAnsi = WideCharToMultiByte(
  18. // CP_ACP,
  19. // WC_NO_BEST_FIT_CHARS,
  20. // pszPrefixOrSuffix,
  21. // cchPrefixOrSuffix,
  22. // szAnsi,
  23. // sizeof(szAnsi) / sizeof(szAnsi[0]),
  24. // NULL,
  25. // &bDefaultUsed
  26. // );
  27. // if ((cchAnsi != 0) && (bDefaultUsed == FALSE))
  28. // {
  29. _TCHAR szInvalidPunctuation[256];
  30. _bstr_t strInvalid(GET_WSTR(IDS_INVALID_PREFIX_SUFFIX));
  31. if (strInvalid.length() > 0)
  32. {
  33. _tcsncpy(szInvalidPunctuation, strInvalid, 255);
  34. szInvalidPunctuation[255] = _T('\0');
  35. }
  36. else
  37. {
  38. szInvalidPunctuation[0] = _T('\0');
  39. }
  40. WORD wCharType;
  41. bool bInvalidTypeFound = false;
  42. for (int i = 0; i < cchPrefixOrSuffix; i++)
  43. {
  44. if (GetStringTypeEx(LOCALE_SYSTEM_DEFAULT, CT_CTYPE1, &pszPrefixOrSuffix[i], 1, &wCharType))
  45. {
  46. if (wCharType & C1_CNTRL)
  47. {
  48. bInvalidTypeFound = true;
  49. break;
  50. }
  51. if (wCharType & C1_PUNCT)
  52. {
  53. if (_tcschr(szInvalidPunctuation, pszPrefixOrSuffix[i]) != NULL)
  54. {
  55. bInvalidTypeFound = true;
  56. break;
  57. }
  58. }
  59. }
  60. }
  61. if (bInvalidTypeFound == false)
  62. {
  63. bValid = true;
  64. }
  65. // }
  66. // }
  67. }
  68. return bValid;
  69. }