tlowercase2.pp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. program tlowercase2;
  2. {$ifdef FPC}
  3. {$mode objfpc}
  4. {$H+}
  5. {$PACKENUM 1}
  6. {$endif fpc}
  7. {$ifndef FPC}
  8. {$APPTYPE CONSOLE}
  9. {$endif}
  10. uses
  11. SysUtils,
  12. character;
  13. {$ifndef FPC}
  14. type UnicodeChar = WideChar;
  15. {$endif}
  16. procedure DoError(ACode : Integer); overload;
  17. begin
  18. WriteLn('Error #',ACode);
  19. Halt(Acode);
  20. end;
  21. procedure DoError(ACode : Integer; ACodePoint : Integer); overload;
  22. begin
  23. WriteLn('Error #',ACode,' ; CodePoint = ',IntToHex(ACodePoint,4));
  24. Halt(Acode);
  25. end;
  26. procedure DoError(ACode : Integer; ACodePoint : UnicodeChar); overload;
  27. begin
  28. WriteLn('Error #',ACode,' ; CodePoint = ',IntToHex(Ord(ACodePoint),4));
  29. Halt(Acode);
  30. end;
  31. procedure DoError(ACode : Integer; AStr : UnicodeString; AIndex : Integer); overload;
  32. begin
  33. WriteLn('Error #',ACode,' ; CodePoint = ',IntToHex(Ord(AStr[AIndex]),4));
  34. Halt(Acode);
  35. end;
  36. var
  37. e, i : Integer;
  38. strPrefix, uc : UnicodeString;
  39. locCharPos : Integer;
  40. begin
  41. strPrefix := '012345AZERT ';
  42. locCharPos := Length(strPrefix) + 1;
  43. e := 1;
  44. for i := Ord('a') to Ord('z') do begin
  45. uc := strPrefix + UnicodeChar(i) + strPrefix;
  46. if not TCharacter.IsLower(uc,locCharPos) then
  47. DoError(e,i);
  48. end;
  49. Inc(e);
  50. for i := Ord('A') to Ord('Z') do begin
  51. uc := strPrefix + UnicodeChar(i) + strPrefix;
  52. if TCharacter.IsLower(uc,locCharPos) then
  53. DoError(e,i);
  54. end;
  55. Inc(e);
  56. for i := Low(Word) to High(Word) do begin
  57. uc := strPrefix + UnicodeChar(i) + strPrefix;
  58. if (TCharacter.GetUnicodeCategory(uc,locCharPos) = TUnicodeCategory.ucLowercaseLetter) then begin
  59. if not TCharacter.IsLower(uc,locCharPos) then
  60. DoError(e,uc,locCharPos);
  61. end;
  62. end;
  63. Inc(e);
  64. for i := Low(Word) to High(Word) do begin
  65. uc := strPrefix + UnicodeChar(i) + strPrefix;
  66. if (TCharacter.GetUnicodeCategory(uc,locCharPos) <> TUnicodeCategory.ucLowercaseLetter) then begin
  67. if TCharacter.IsLower(uc,locCharPos) then
  68. DoError(e,uc,locCharPos);
  69. end;
  70. end;
  71. WriteLn('ok');
  72. end.