+ print $out_fh "\n#endif\n" unless exists $include_in_ext_re{$name};
+
+}
+
+sub mk_invlist_from_cp_list {
+
+ # Returns an inversion list constructed from the sorted input array of
+ # code points
+
+ my $list_ref = shift;
+
+ # Initialize to just the first element
+ my @invlist = ( $list_ref->[0], $list_ref->[0] + 1);
+
+ # For each succeeding element, if it extends the previous range, adjust
+ # up, otherwise add it.
+ for my $i (1 .. @$list_ref - 1) {
+ if ($invlist[-1] == $list_ref->[$i]) {
+ $invlist[-1]++;
+ }
+ else {
+ push @invlist, $list_ref->[$i], $list_ref->[$i] + 1;
+ }
+ }
+ return @invlist;
+}
+
+# Read in the Case Folding rules, and construct arrays of code points for the
+# properties we need.
+my ($cp_ref, $folds_ref, $format) = prop_invmap("Case_Folding");
+die "Could not find inversion map for Case_Folding" unless defined $format;
+die "Incorrect format '$format' for Case_Folding inversion map"
+ unless $format eq 'al';
+my @has_multi_char_fold;
+my @is_non_final_fold;
+
+for my $i (0 .. @$folds_ref - 1) {
+ next unless ref $folds_ref->[$i]; # Skip single-char folds
+ push @has_multi_char_fold, $cp_ref->[$i];
+
+ # Add to the the non-finals list each code point that is in a non-final
+ # position
+ for my $j (0 .. @{$folds_ref->[$i]} - 2) {
+ push @is_non_final_fold, $folds_ref->[$i][$j]
+ unless grep { $folds_ref->[$i][$j] == $_ } @is_non_final_fold;
+ }
+}
+
+sub _Perl_Multi_Char_Folds {
+ @has_multi_char_fold = sort { $a <=> $b } @has_multi_char_fold;
+ return mk_invlist_from_cp_list(\@has_multi_char_fold);
+}
+
+sub _Perl_Non_Final_Folds {
+ @is_non_final_fold = sort { $a <=> $b } @is_non_final_fold;
+ return mk_invlist_from_cp_list(\@is_non_final_fold);