1 # Copyright (C) 2014, Eric Wong <normalperson@yhbt.net> and all contributors
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
4 # represents a header value in various forms
5 package PublicInbox::Hval;
8 use fields qw(raw href);
9 use Encode qw(find_encoding);
10 use URI::Escape qw(uri_escape_utf8);
11 use PublicInbox::MID qw/mid_clean mid_compress/;
13 my $enc_ascii = find_encoding('us-ascii');
16 my ($class, $raw, $href) = @_;
17 my $self = fields::new($class);
19 # we never care about leading/trailing whitespace
23 $self->{href} = defined $href ? $href : $raw;
28 my ($class, $msgid) = @_;
29 $msgid = mid_clean($msgid);
30 $class->new($msgid, mid_compress($msgid));
34 my ($class, $raw) = @_;
35 $raw = '' unless defined $raw;
36 $raw =~ tr/\t\n / /s; # squeeze spaces
37 $raw =~ tr/\r//d; # kill CR
51 $s =~ s/\r\n/\n/sg; # fixup bad line endings
52 $s =~ s/([<>&'"])/$xhtml_map{$1}/ge;
53 $enc_ascii->encode($s, Encode::HTMLCREF);
56 sub as_html { ascii_html($_[0]->{raw}) }
57 sub as_href { ascii_html(uri_escape_utf8($_[0]->{href})) }