Page 1 of 1

Strings does not fit Oakwood guidelines

Posted: Mon Mar 28, 2022 9:27 am
by Ivan Denisov
Oakwood standard Strings module includes Delete and Insert procedures
https://oberoncore.ru/library/the_oakwo ... developers

What is your opinion, should Strings module of BlackBox also include these procedures?

Code: Select all

DEFINITION Strings;
PROCEDURE Length (s: ARRAY OF CHAR): INTEGER;
PROCEDURE Insert (source: ARRAY OF CHAR; pos: INTEGER; VAR dest: ARRAY OF CHAR);
PROCEDURE Append (extra: ARRAY OF CHAR; VAR dest: ARRAY OF CHAR);
PROCEDURE Delete (VAR s: ARRAY OF CHAR; pos, n: INTEGER);
PROCEDURE Replace (source: ARRAY OF CHAR; pos: INTEGER; VAR dest: ARRAY OF CHAR);
PROCEDURE Extract (source: ARRAY OF CHAR; pos, n: INTEGER; VAR dest: ARRAY OF CHAR);
PROCEDURE Pos (pattern, s: ARRAY OF CHAR; pos: INTEGER): INTEGER;
PROCEDURE Cap (VAR s: ARRAY OF CHAR);
END Strings

Re: Strings does not fit Oakwood guidelines

Posted: Mon Mar 28, 2022 7:50 pm
by HansKlaver
As is hinted at in the documentation of Strings both Insert and Delete can be implemented trivially in terms of procedure Replace. So maybe it is enough to stress this in the documentation by printing these words in bold typeface:

Hint: if len = 0 then rep is inserted in s at position pos. If LEN(rep$) = 0 then the stretch [pos, MIN(pos+len, LEN(s$))) is deleted from s.

Re: Strings does not fit Oakwood guidelines

Posted: Tue Mar 29, 2022 4:41 am
by Ivan Denisov
HansKlaver wrote: Mon Mar 28, 2022 7:50 pm As is hinted at in the documentation of Strings both Insert and Delete can be implemented trivially in terms of procedure Replace. So maybe it is enough to stress this in the documentation by printing these words in bold typeface:

Hint: if len = 0 then rep is inserted in s at position pos. If LEN(rep$) = 0 then the stretch [pos, MIN(pos+len, LEN(s$))) is deleted from s.
Thanks a lot, there is also in-code comment about this extra semantics. I agree, this should be highlighted in documentation.

Code: Select all

	PROCEDURE Replace* (VAR s: ARRAY OF CHAR; pos, len: INTEGER; IN rep: ARRAY OF CHAR);
		(* replace stretch s[pos]..s[pos+len-1] with rep *)
		(* insert semantics if len = 0; delete semantics if LEN(rep$) = 0 *)