strings.def 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. DEFINITION MODULE Strings;
  2. (* Bounded string operations over descriptor strings (classic
  3. Modula-2 form). Sources are [0..] indexed; destinations are
  4. truncated to fit (never overrun). *)
  5. PROCEDURE Length(VAR s : ARRAY OF CHAR) : INTEGER;
  6. (* Number of characters in s. *)
  7. PROCEDURE Assign(VAR src, dst : ARRAY OF CHAR);
  8. (* Copies src into dst (truncated to dst's capacity). *)
  9. PROCEDURE Concat(VAR s1, s2 : ARRAY OF CHAR; VAR dst : ARRAY OF CHAR);
  10. (* dst := s1 followed by s2 (truncated to fit). *)
  11. PROCEDURE Compare(VAR s1, s2 : ARRAY OF CHAR) : INTEGER;
  12. (* <0, 0 or >0 as s1 is less than, equal to, or greater than s2. *)
  13. PROCEDURE Delete(VAR s : ARRAY OF CHAR; start, count : INTEGER);
  14. (* Removes count characters from s, beginning at position start. *)
  15. PROCEDURE Append(VAR src, dst : ARRAY OF CHAR);
  16. (* Appends src to dst. NOTE: dst is an open array whose descriptor
  17. count is the logical length, so appending past it traps until the
  18. string model separates length from capacity. *)
  19. PROCEDURE Copy(VAR src, dst : ARRAY OF CHAR);
  20. (* Alias for Assign, ISO-style name. *)
  21. PROCEDURE Equal(VAR s1, s2 : ARRAY OF CHAR) : BOOLEAN;
  22. (* TRUE when the two strings have equal contents. *)
  23. PROCEDURE Pos(VAR pattern, s : ARRAY OF CHAR) : INTEGER;
  24. (* 1-based index of the leftmost occurrence of pattern in s, or 0. *)
  25. END Strings.