To: J3 J3/19-160 From: Dan Nagle Subject: Part 2 Procedures Date: 2019-February-14 Reference: 18-007r1, 18-259r2 Introduction An approved work-item for JoR is moving some procedures from the withdrawn part 2 to the main standard. The procedures are those described in "3.7 Additional Generic Procedures for Substring Manipulation" of part 2. The module was proposed to be named "ISO_FORTRAN_STRINGS". This paper proposes to use this name. This should be confirmed or changed by a straw vote. I believe the names of the procedures should not be changed, because, firstly, they are descriptive as is, and secondly, they may be in use by program units USEing the ISO_VARYING_STRINGS module. Specifications The following procedures are moved from part 2 to an intrinsic module named "ISO_FORTRAN_STRINGS": EXTRACT() copies a substring from a string INSERT() inserts a substring into a string at a location REMOVE() removes a substring from a string REPLACE() replace characters by a substring (which is specified variously) SPLIT() split a string into two where a character from a set is found These procedures are described more fully below: EXTRACT (string [, start, finish]) Description. Extracts a specified substring from a string. Class. Elemental function. Arguments. string shall be of type CHARACTER. start (optional) shall be of type INTEGER. finish (optional) shall be of type INTEGER. Result Characteristics. Of type CHARACTER. Result Value. The result value is a copy of the characters of the argument string between positions start and finish, inclusive. If start is absent or less than one, the value one is used for start. If finish is absent or greater than LEN(string), the value LEN(string) is used for finish. If finish is less than start, the result is a zero-length string. INSERT (string, start, substring) Description. Inserts a substring into a string at a specified position. Class. Elemental function. Arguments. string shall be type CHARACTER. start shall be type INTEGER. substring shall be type CHARACTER. Result Characteristics. Type CHARACTER. Result Value. The result value is a copy of the characters of the argument string with the characters of substring inserted into the copy of string before the character at the character position start. If start is greater than LEN(string), the value LEN(string)+1 is used for start and substring is appended to the copy of string. If start is less than one, the value one is used for start and substring is inserted before the first character of the copy of string. REMOVE (string [, start, finish]) Description. Removes a specified substring from a string. Class. Elemental function. Arguments. string shall be of type CHARACTER start (optional) shall be of type INTEGER. finish (optional) shall be of type INTEGER. Result Characteristics. Of type CHARACTER. Result Value. The result value is a copy of the characters of string with the characters between positions start and finish, inclusive, removed. If start is absent or less than one, the value one is used for start. If finish is absent or greater than LEN(string), the value LEN(string) is used for finish. If finish is less than start, the characters of string are delivered unchanged as the result. REPLACE (string, start, substring) or REPLACE (string, start, finish, substring) or REPLACE (string, target, substring [,every, back]) Description. Replaces a subset of the characters in a string by a given substring. The subset may be specified either by position or by content. Class. Elemental function. Arguments. string shall be of type CHARACTER. start shall be of type INTEGER. finish shall be of type INTEGER. substring shall be of type CHARACTER. target shall be of type CHARACTER. It shall not be of zero length. every (optional) shall be of type LOGICAL. back (optional) shall be of type LOGICAL. Result Characteristics. Of type CHARACTER. Result Value. The result value is a copy of the characters in string modified as per one of the cases below. Case(i): For a reference of the form REPLACE(string,start,substring) the characters of the argument substring are inserted into the copy of string beginning with the character at the character position start. The characters in positions from start to MIN(start+LEN(substring)-1,LEN(string)) are deleted. If start is greater than LEN(string), the value LEN(string)+1 is used for start and substring is appended to the copy of string. If start is less than one, the value one is used for start. Case(ii): For a reference of the form REPLACE(string,start,finish,substring) the characters in the copy of string between positions start and finish, including those at start and finish, are deleted and replaced by the characters of substring. If start is less than one, the value one is used for start. If finish is greater than LEN(string), the value LEN(string) is used for finish. If finish is less than start, the characters of substring are inserted before the character at start and no characters are deleted. Case(iii): For a reference of the form REPLACE(string,target,substring,every,back) the copy of string is searched for occurrences of target. The search is done in the backward direction if the argument back is present with the value true, and in the forward direction otherwise. If target is found, it is replaced by substring. If every is present with the value true, the search and replace is continued from the character following target in the search direction specified until all occurrences of target in the copy string are replaced; otherwise only the first occurrence of target is replaced. SPLIT (string, word, set [, separator, back]) Description. Splits a string into two substrings with the substrings separated by the occurrence of a character from a specified separator set. Class. Elemental subroutine. Arguments. string shall be of type CHARACTER. It is an INTENT(INOUT) argument. word shall be of type CHARACTER. It is an INTENT(OUT) argument. set shall be of type CHARACTER. It is an INTENT(IN) argument. separator (optional) shall be of type CHARACTER. It is an INTENT(OUT) argument. back (optional) shall be of type LOGICAL. It is an INTENT(IN) argument. Action. The effect of the procedure is to divide the string at the first occurrence of a character that is in set. The string is searched in the forward direction unless back is present with the value true, in which case the search is in the backward direction. The characters passed over in the search are returned in the argument word and the remainder of the string, not including the separator character, is returned in the argument string. If the argument separator is present, the actual character found which separates the word from the remainder of the string is returned in separator. If no character from set is found or set is of zero length, the whole string is returned in word, string is returned as zero length, and separator (if present) is returned as zero length. The effect of the procedure is such that, on return, either word//separator//string is the same as the initial string for a forward search, or string//separator//word is the same as the initial string for a backward search.