Files
Compile_And_Prove_Demo/proved/strings.adb
2017-04-05 19:27:27 +02:00

17 lines
481 B
Ada

package body Strings is
function Longest_Common_Prefix (X, Y : Str) return Natural is
Length : Natural := 0;
Max_Length : constant Natural := Natural'Min(X'Length, Y'Length);
begin
while Length < Max_Length loop
pragma Loop_Invariant (for all J in 1 .. Length => X(J) = Y(J));
exit when X (Length + 1) /= Y (Length + 1);
Length := Length + 1;
end loop;
return Length;
end Longest_Common_Prefix;
end Strings;