Re: GError location filename as wide chars



Torsten Schoenfeld <kaffeetisch gmx de> writes:

Glib::filename_display_name() ... is new in glib 2.6.0

Oops, yep.  What about something nasty like below?  Concept-stage only,
but it runs for me ...

(Is there an incantation to make "defined &Glib::filename_display_name"
evaluate at compile time, since it's basically a constant?)


use overload
   '""' => sub { $_[0]->message . $_[0]->location_for_display },
   fallback => 1;

sub location_for_display {
  my ($self) = @_;
  my $location = $self->{location};
  unless (utf8::is_utf8($location)) {
    if (defined &Glib::filename_display_name) {
      $location = Glib::filename_display_name($location);
    } else {
      # filename_to_unicode() throws an error (another GError) if bad bytes
      local $@; # don't clobber $@, the user's GError is likely there
      if (! eval { $location = Glib->filename_to_unicode($location); 1 }) {
        $location =~ s/([^[:ascii:]])/sprintf('\\x{%X}',ord($1))/ge;
        utf8::upgrade ($location);
      }
    }
  }
  return $location;
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]