strUtils.def 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. DEFINITION MODULE strUtils;
  2. CONST
  3. whitespace = ' \t\n\r\v\f';
  4. asciiLowercase = 'abcdefghijklmnopqrstuvwxyz';
  5. asciiUppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6. asciiLetters = asciiLowercase + asciiUppercase;
  7. digits = '0123456789';
  8. hexdigits = digits + 'abcdef' + 'ABCDEF';
  9. octdigits = '01234567';
  10. punctuation = "!#$%&'()*+,-./:;<=>?@[\]^_`{|}~" + '#';
  11. printable = digits + asciiLetters + punctuation + whitespace;
  12. alphanum = asciiLetters + digits;
  13. (* pythonlike functions
  14. isalnum() Returns True if all characters in the string are alphanumeric
  15. isalpha() Returns True if all characters in the string are in the alphabet
  16. isascii() Returns True if all characters in the string are ascii characters
  17. isdigit() Returns True if all characters in the string are digits
  18. isidentifier() Returns True if the string is an identifier
  19. islower() Returns True if all characters in the string are lower case
  20. isprintable() Returns True if all characters in the string are printable
  21. isspace() Returns True if all characters in the string are whitespaces
  22. istitle() Returns True if the string follows the rules of a title
  23. isupper() Returns True if all characters in the string are upper case
  24. *)
  25. PROCEDURE isalnum(s : ARRAY OF CHAR) : BOOLEAN;
  26. (* Returns True if all characters in the string are alphanumeric*)
  27. PROCEDURE isalpha(s : ARRAY OF CHAR) : BOOLEAN;
  28. (* Returns True if all characters in the string are in the alphabet *)
  29. PROCEDURE isascii(s : ARRAY OF CHAR) : BOOLEAN;
  30. (* Returns True if all characters in the string are ascii characters *)
  31. PROCEDURE isdigit(s : ARRAY OF CHAR) : BOOLEAN;
  32. (* Returns True if all characters in the string are digits *)
  33. (* there is a dedicated procedure in CharClass for that *)
  34. PROCEDURE isidentifier(s : ARRAY OF CHAR) : BOOLEAN;
  35. (* Returns True if the string is an identifier *)
  36. PROCEDURE islower(s : ARRAY OF CHAR) : BOOLEAN;
  37. (* eturns True if all characters in the string are lower case *)
  38. (* there is a dedicated procedure in CharClass for that *)
  39. PROCEDURE isprintable(s : ARRAY OF CHAR) : BOOLEAN;
  40. (* Returns True if all characters in the string are printable *)
  41. PROCEDURE isspace(s : ARRAY OF CHAR) : BOOLEAN;
  42. (* Returns True if all characters in the string are whitespaces *)
  43. (* there is a dedicated procedure in CharClass for that *)
  44. PROCEDURE istitle(s : ARRAY OF CHAR) : BOOLEAN;
  45. (* Returns True if the string follows the rules of a title *)
  46. PROCEDURE isupper(s : ARRAY OF CHAR) : BOOLEAN;
  47. (* Returns True if all characters in the string are upper case *)
  48. (* there is a dedicated procedure in CharClass for that *)
  49. (* end of python alike functions *)
  50. (* this function copied from ooc source and may be considered a duplicate. *)
  51. PROCEDURE Compare (stringVal1, stringVal2: ARRAY OF CHAR): INTEGER ;
  52. (**Returns @oconst{less}, @oconst{equal}, or @oconst{greater}, according as
  53. @oparam{stringVal1} is lexically less than, equal to, or greater than
  54. @oparam{stringVal2}. Note that Oberon-2 and Oberon-07 already contains predefined comparison operators on strings. *)
  55. PROCEDURE Copy(VAR Ns: ARRAY OF CHAR; S: ARRAY OF CHAR);
  56. (* this function copied from ooc source and may be considered a duplicate. *)
  57. PROCEDURE Assign (source: ARRAY OF CHAR; VAR destination: ARRAY OF CHAR);
  58. (**Copies @oparam{source} to @oparam{destination}. Equivalent to the
  59. predefined procedure @code{COPY}. Unlike @code{COPY}, this procedure can be
  60. assigned to a procedure variable. *)
  61. PROCEDURE Pos (substr : CHAR ; s : ARRAY OF CHAR; n : CARDINAL ) : CARDINAL ;
  62. PROCEDURE RemoveLeftChars (VAR s : ARRAY OF CHAR; ch : CHAR);
  63. PROCEDURE RemoveRightChars (VAR s : ARRAY OF CHAR; ch : CHAR);
  64. PROCEDURE WordCount (source : ARRAY OF CHAR; separator : CHAR) : CARDINAL ;
  65. PROCEDURE NumberOfChar (s : ARRAY OF CHAR; ch : CHAR) : CARDINAL ;
  66. PROCEDURE Rpos ( s : ARRAY OF CHAR ; ch : CHAR) : CARDINAL ;
  67. PROCEDURE Lpos ( s : ARRAY OF CHAR ; ch : CHAR) : CARDINAL;
  68. PROCEDURE copyBytes(VAR src, dst: ARRAY OF CHAR; start, quantity: CARDINAL );
  69. (*
  70. PROCEDURE appendNumChars(VAR extra: pstring; extraNum: LONGINT; VAR destination: pstring; destinationNum: LONGINT);
  71. PROCEDURE string2pstring(s: ARRAY OF CHAR; VAR d : pstring);
  72. PROCEDURE string2pstrings(VAR text: ARRAY OF CHAR): pstrings;
  73. PROCEDURE ExtractWord (n : INTEGER; s : ARRAY OF CHAR; ch : CHAR) : pstring;
  74. PROCEDURE tokenize(s : ARRAY OF CHAR; ch : CHAR) : pstrings;
  75. *)
  76. (* copies all array, even after 0X, but puts 0X in the end *)
  77. PROCEDURE copyAll (src : ARRAY OF CHAR ; VAR dst : ARRAY OF CHAR);
  78. (** fills whole array with zeroes, useful when one needs to get several strings which contain characters < ' ' and not necessarily end with 0X *)
  79. PROCEDURE zeroStr(VAR str: ARRAY OF CHAR);
  80. PROCEDURE appendLFCR(VAR str: ARRAY OF CHAR);
  81. (*
  82. PROCEDURE findChar(ch: CHAR; VAR line: ARRAY OF CHAR; VAR b: BOOLEAN; VAR pos: INTEGER);
  83. (* cuts line, takes the part till the eol *)
  84. PROCEDURE cutLine(VAR src, dst: ARRAY OF CHAR);
  85. (* put 0X after eol in the string *)
  86. PROCEDURE terminateLine(VAR str: ARRAY OF CHAR);
  87. PROCEDURE getTillEOL(VAR src: ARRAY OF CHAR; spos: INTEGER; VAR dst: ARRAY OF CHAR); (* actually get till any character < ' ' *)
  88. (* get next word starting from spos till the ' ' *)
  89. PROCEDURE getNextWord(VAR src: ARRAY OF CHAR; spos: INTEGER; VAR dst: ARRAY OF CHAR);
  90. PROCEDURE getNextAlphaNumWord(VAR src: ARRAY OF CHAR; spos: INTEGER; VAR dst: ARRAY OF CHAR);
  91. PROCEDURE contains (VAR line : ARRAY OF CHAR; pattern: ARRAY OF CHAR): BOOLEAN;
  92. PROCEDURE contains1(VAR line: ARRAY OF CHAR; pat : ARRAY OF CHAR): BOOLEAN;
  93. (* IntToStr routine taken from
  94. https://github.com/romiras/Oberon-F-components/blob/master/Ott/Mod/IntStr.cp
  95. and modified to work on 64bit system by dcwbrown,
  96. in order to avoid using oocIntStr, which has many dependencies *)
  97. PROCEDURE Reverse0 (VAR str : ARRAY OF CHAR; start, end : INTEGER);
  98. (* Reverses order of characters in the interval [start..end]. *)
  99. PROCEDURE dumpChars(VAR s : ARRAY OF CHAR);
  100. PROCEDURE dumpAllChars(VAR s : ARRAY OF CHAR);
  101. *)
  102. END strUtils.