tispunctuation.pp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. program tispunctuation;
  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 CheckItems(AStart, AEnd : Word; ADoCheck : Boolean; AError : Integer); overload;
  32. var
  33. q : Integer;
  34. locItem : UnicodeChar;
  35. begin
  36. for q := AStart to AEnd do begin
  37. locItem := UnicodeChar(q);
  38. if TCharacter.IsPunctuation(locItem) <> ADoCheck then
  39. DoError(AError,locItem);
  40. end;
  41. end;
  42. procedure CheckItems(AItems : array of Word; ADoCheck : Boolean; AError : Integer); overload;
  43. var
  44. q : Integer;
  45. locItem : UnicodeChar;
  46. begin
  47. for q := Low(AItems) to High(AItems) do begin
  48. locItem := UnicodeChar(AItems[q]);
  49. if TCharacter.IsPunctuation(locItem) <> ADoCheck then
  50. DoError(AError,locItem);
  51. end;
  52. end;
  53. var
  54. e, i , k: Integer;
  55. uc : UnicodeChar;
  56. begin
  57. e := 1;
  58. CheckItems($0021,$0023,True,e);
  59. CheckItems($0025,$002A,True,e);
  60. CheckItems($002C,$002F,True,e);
  61. CheckItems($003A,$003B,True,e);
  62. CheckItems($003F,$0040,True,e);
  63. CheckItems($005B,$005D,True,e);
  64. CheckItems([$005F,$007B,$007D,$00A1,$00AB,{ $00AD,}$00B7,$00BB,$00BF,$037E],True,e);
  65. CheckItems($055A,$055F,True,e);
  66. CheckItems([$0589,$058A],True,e);
  67. CheckItems($FF5F,$FF65,True,e);
  68. Inc(e);
  69. for i := Low(Word) to High(Word) do begin
  70. uc := UnicodeChar(i);
  71. if (TCharacter.GetUnicodeCategory(uc) in
  72. [ TUnicodeCategory.ucConnectPunctuation, TUnicodeCategory.ucDashPunctuation,
  73. TUnicodeCategory.ucOpenPunctuation, TUnicodeCategory.ucClosePunctuation,
  74. TUnicodeCategory.ucInitialPunctuation, TUnicodeCategory.ucFinalPunctuation,
  75. TUnicodeCategory.ucOtherPunctuation
  76. ]
  77. )
  78. then begin
  79. if not TCharacter.IsPunctuation(uc) then
  80. DoError(e,uc);
  81. end;
  82. end;
  83. WriteLn('ok');
  84. end.