home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / modu1096.zip / ISOsym / strings.def < prev    next >
Text File  |  1996-08-30  |  7KB  |  151 lines

  1. DEFINITION MODULE Strings;
  2.  
  3.   (* Facilities for manipulating strings *)
  4.  
  5. TYPE
  6.   String1 = ARRAY [0..0] OF CHAR;
  7.  (* String1 is provided for constructing a value of a single-character string
  8.     type from a single character value in order to pass CHAR values to 
  9.     ARRAY OF CHAR parameters.
  10.   *)
  11.  
  12. PROCEDURE Length (stringVal: ARRAY OF CHAR): CARDINAL;
  13.   (* Returns the length of stringVal (the same value as would be returned by the
  14.      pervasive function LENGTH).
  15.   *)
  16.  
  17.  
  18. (* The following seven procedures construct a string value, and attempt to
  19.    assign it to a variable parameter.  They all have the property that if
  20.    the length of the constructed string value exceeds the capacity of the
  21.    variable parameter, a truncated value is assigned, while if the length
  22.    of the constructed string value is less than the capacity of the variable
  23.    parameter, a string terminator is appended before assignment is performed.
  24. *)
  25.  
  26.  
  27. PROCEDURE Assign (source: ARRAY OF CHAR; VAR destination: ARRAY OF CHAR);
  28.   (* Copies source to destination *)
  29.  
  30. PROCEDURE Extract (source: ARRAY OF CHAR; startIndex, numberToExtract: CARDINAL;
  31.                    VAR destination: ARRAY OF CHAR);
  32.   (* Copies at most numberToExtract characters from source to destination,
  33.      starting at position startIndex in source.
  34.   *)
  35.  
  36. PROCEDURE Delete (VAR string: ARRAY OF CHAR; startIndex, numberToDelete: CARDINAL);
  37.   (* Deletes at most numberToDelete characters from stringVar, starting at position
  38.      startIndex.
  39.   *)
  40.  
  41. PROCEDURE Insert (source: ARRAY OF CHAR; startIndex: CARDINAL;
  42.                   VAR destination: ARRAY OF CHAR);
  43.   (* Inserts source into destination at position startIndex *)
  44.  
  45. PROCEDURE Replace (source: ARRAY OF CHAR; startIndex: CARDINAL;
  46.                    VAR destination: ARRAY OF CHAR);
  47.   (* Copies source into destination, starting at position startIndex.
  48.      Copying stops when all of source has been copied, or when the last
  49.      character of the string value in destination has been replaced.
  50.   *)
  51.  
  52. PROCEDURE Append (source: ARRAY OF CHAR; VAR destination: ARRAY OF CHAR);
  53.   (* Appends source to destination. *)
  54.  
  55. PROCEDURE Concat (source1, source2: ARRAY OF CHAR; VAR destination: ARRAY OF CHAR);
  56.   (* Concatenates source2 onto source1 and copies the result into destination. *)
  57.  
  58.  
  59. (* The following predicates provide for pre-testing of the operation-completion
  60.    conditions for the procedures above.
  61. *)
  62.  
  63. PROCEDURE CanAssignAll (sourceLength: CARDINAL; VAR destination: ARRAY OF CHAR): BOOLEAN;
  64.   (* Returns TRUE if a number of characters, indicated by sourceLength, will fit
  65.      into destination; otherwise returns FALSE.
  66.   *)
  67.  
  68. PROCEDURE CanExtractAll (sourceLength, startIndex, numberToExtract: CARDINAL;
  69.                          VAR destination: ARRAY OF CHAR): BOOLEAN;
  70.   (* Returns TRUE if there are numberToExtract characters starting at startIndex
  71.      and within the sourceLength of some string, and if the capacity of destination
  72.      is sufficient to hold numberToExtract characters; otherwise returns FALSE.
  73.   *)
  74.  
  75. PROCEDURE CanDeleteAll (stringLength, startIndex, numberToDelete: CARDINAL): BOOLEAN;
  76.   (* Returns TRUE if there are numberToDelete characters starting at startIndex
  77.      and within the stringLength of some string; otherwise returns FALSE.
  78.   *)
  79.  
  80. PROCEDURE CanInsertAll (sourceLength, startIndex: CARDINAL;
  81.                         VAR destination: ARRAY OF CHAR): BOOLEAN;
  82.   (* Returns TRUE if there is room for the insertion of sourceLength characters from
  83.      some string into destination starting at startIndex; otherwise returns FALSE.
  84.   *)
  85.  
  86. PROCEDURE CanReplaceAll (sourceLength, startIndex: CARDINAL;
  87.                          VAR destination: ARRAY OF CHAR): BOOLEAN;
  88.   (* Returns TRUE if there is room for the replacement of sourceLength characters in
  89.      destination starting at startIndex; otherwise returns FALSE.
  90.   *)
  91.  
  92. PROCEDURE CanAppendAll (sourceLength: CARDINAL; VAR destination: ARRAY OF CHAR): BOOLEAN;
  93.   (* Returns TRUE if there is sufficient room in destination to append a string of
  94.      length sourceLength to the string in destination; otherwise returns FALSE.
  95.   *)
  96.  
  97. PROCEDURE CanConcatAll (source1Length, source2Length: CARDINAL;
  98.                         VAR destination: ARRAY OF CHAR): BOOLEAN;
  99.   (* Returns TRUE if there is sufficient room in destination for a two strings of
  100.      lengths source1Length and source2Length; otherwise returns FALSE.
  101.   *)
  102.  
  103.  
  104. (* The following type and procedures provide for the comparison of string values,
  105.    and for the location of substrings within strings.
  106. *)
  107.  
  108. TYPE
  109.   CompareResults = (less, equal, greater);
  110.  
  111.  
  112. PROCEDURE Compare (stringVal1, stringVal2: ARRAY OF CHAR): CompareResults;
  113.   (* Returns less, equal, or greater, according as stringVal1 is lexically
  114.      less than, equal to, or greater than stringVal2.
  115.   *)
  116.  
  117. PROCEDURE Equal (stringVal1, stringVal2: ARRAY OF CHAR): BOOLEAN;
  118.   (* Returns Strings.Compare(stringVal1, stringVal2) = Strings.equal *)
  119.  
  120. PROCEDURE FindNext (pattern, stringToSearch: ARRAY OF CHAR; startIndex: CARDINAL;
  121.                     VAR patternFound: BOOLEAN; VAR posOfPattern: CARDINAL);
  122.   (* Looks forward for next occurrence of pattern in stringToSearch, starting
  123.      the search at position startIndex. If startIndex < LENGTH(stringToSearch)
  124.      and pattern is found, patternFound is returned as TRUE, and posOfPattern
  125.      contains the start position in stringToSearch of pattern. Otherwise
  126.      patternFound is returned as FALSE, and posOfPattern is unchanged.
  127.   *)
  128.  
  129. PROCEDURE FindPrev (pattern, stringToSearch: ARRAY OF CHAR; startIndex: CARDINAL;
  130.                     VAR patternFound: BOOLEAN; VAR posOfPattern: CARDINAL);
  131.   (* Looks backward for the previous occurrence of pattern in stringToSearch and
  132.      returns the position of the first character of the pattern if found.
  133.      The search for the pattern begins at startIndex. If pattern is found,
  134.      patternFound is returned as TRUE, and posOfPattern contains the start
  135.      position in stringToSearch of pattern in the range [0..startIndex].
  136.      Otherwise patternFound is returned as FALSE, and posOfPattern is unchanged.
  137.   *)
  138.  
  139. PROCEDURE FindDiff (stringVal1, stringVal2: ARRAY OF CHAR;
  140.                     VAR differenceFound: BOOLEAN; VAR posOfDifference: CARDINAL);
  141.   (* Compares the string values in stringVal1 and stringVal2 for differences.
  142.      If they are equal, differenceFound is returned as FALSE, and TRUE otherwise.
  143.      If differenceFound is TRUE, posOfDifference is set to the position of the
  144.      first difference; otherwise posOfDifference is unchanged.
  145.   *)
  146.  
  147. PROCEDURE Capitalize (VAR stringVar: ARRAY OF CHAR);
  148.   (* Applies the function CAP to each character of the string value in stringVar *)
  149.  
  150. END Strings.
  151.