tvalc.pp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. unit tvalc;
  2. interface
  3. const
  4. HasErrors : boolean = false;
  5. Silent : boolean = true;
  6. CheckVal : boolean = true;
  7. SuccessCount : longint = 0;
  8. FailCount : longint = 0;
  9. type
  10. TCharSet = set of char;
  11. const
  12. ValidNumeralsBase2 : TCHarSet = ['0'..'1'];
  13. ValidNumeralsBase8 : TCHarSet = ['0'..'7'];
  14. ValidNumeralsBase10 : TCHarSet = ['0'..'9'];
  15. ValidNumeralsBase16 : TCHarSet = ['0'..'9','a'..'f','A'..'F'];
  16. SpecialCharsFirst : TCharSet = [' ',#9,'x','X','$','&','%','+','-'];
  17. SpecialCharsSecond : TCharSet = [#0];
  18. type
  19. ValTestType =
  20. (ValShouldFail,
  21. ValShouldSucceed,
  22. ValShouldSucceedAfterRemovingTrail);
  23. function Display(const s : string) : string;
  24. implementation
  25. function Display(const s : string) : string;
  26. var
  27. res,ordval : string;
  28. i : longint;
  29. quoted : boolean;
  30. begin
  31. res:='"';
  32. quoted:=false;
  33. for i:=1 to length(s) do
  34. if ord(s[i])<32 then
  35. begin
  36. if quoted then
  37. res:=res+'''';
  38. str(ord(s[i]),ordval);
  39. res:=res+'#'+ordval;
  40. quoted:=false;
  41. end
  42. else
  43. begin
  44. if not quoted then
  45. res:=res+'''';
  46. quoted:=true;
  47. res:=res+s[i];
  48. end;
  49. if quoted then
  50. res:=res+'''';
  51. res:=res+'"';
  52. Display:=res;
  53. end;
  54. end.