# Heuristics to ensure UTF-8

    sub to_utf8 {
      my($s) = shift;
      if ($s =~ /[\200-\377]/) {
        my $warn;
        local $^W=1;
        local($SIG{__WARN__}) = sub { $warn = shift; };
        require Unicode::String;
        my $us = Unicode::String::utf8($s); # trigger warning
        if ($warn and $warn =~ /utf8/i) {
          $s = Unicode::String::latin1($s)->utf8;
          ######################################
        }
      }
      decode_highbit_entities($s);
      $s;
    }