Skip to content

Commit f5459ff

Browse files
committed
I don't know. Some refactoring and a bug fix maybe?
Unfortunately I have no time machine so I cannot go back and ask myself why these changes were made. It seems that propdump didn't handle weird characters properly, so some code was moved to separate subs in order to be reused by propdump.
1 parent 31bc4c8 commit f5459ff

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

Unicodable.p6

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,30 @@ multi method irc-privmsg-channel($msg where .args[1] ~~ / ^ ‘.u’ \s (.*)/) {
6666
self.irc-to-me($msg)
6767
}
6868

69-
method get-description($ord) {
69+
multi method codepointify(Int $ord ) { $ord.fmt(U+%04X) }
70+
multi method codepointify(Str $char) { $char.ords».fmt(U+%04X).join: , }
71+
72+
method sanify($ord) {
7073
my $char;
7174
try {
7275
$char = $ord.chr;
73-
CATCH { default { return sprintf U+%04X (invalid codepoint), $ord } }
76+
CATCH { default { return {self.codepointify($ord)} (invalid codepoint) } }
7477
}
75-
$char = ~ $ord.chr if $ord.uniprop.starts-with: M; # TODO ask samcv
7678
try {
7779
$char.encode;
78-
CATCH { default { $char = unencodable character } }
80+
CATCH { default { return unencodable character } }
7981
}
82+
$char = ~ $ord.chr if $ord.uniprop.starts-with: M; # TODO ask samcv
8083
$char = control character if $ord.uniprop eq Cc;
81-
sprintf U+%04X %s [%s] (%s), $ord, $ord.uniname, $ord.uniprop, $char
84+
$char
85+
}
86+
87+
method get-description($ord) {
88+
my $sane = self.sanify($ord);
89+
return $sane if $sane.ends-with());
90+
sprintf %s %s [%s] (%s),
91+
self.codepointify($ord), $ord.uniname,
92+
$ord.uniprop, self.sanify($ord)
8293
}
8394

8495
method from-numerics($query) {
@@ -203,7 +214,7 @@ method propdump($msg, $query) {
203214
for @prop-table -> $category {
204215
$answer ~= sprintf \n### %s\n, $category.key;
205216
$answer ~= sprintf | %-55s |, Property names;
206-
$answer ~= .fmt: %-25s | for @query.map: -> $char { Value: {&escape($char.chr)} };
217+
$answer ~= .fmt: %-25s | for @query.map: -> $char { Value: {&escape(self.sanify: $char)} };
207218
$answer ~= \n;
208219
$answer ~= |{- x 57}|;
209220
$answer ~= {- x 27}| x @query;
@@ -212,7 +223,7 @@ method propdump($msg, $query) {
212223
my @props = @query.map: *.uniprop: $cat[0];
213224
my $bold = ([eq] @props) ?? !! **;
214225
$answer ~= ($bold ~ $cat.join(, ) ~ $bold).fmt: | %-55s |;
215-
$answer ~= &escape($_).fmt: %-25s | for @props;
226+
$answer ~= &escape(.comb».ords.flat.map({self.sanify($_)}).join).fmt: %-25s | for @props;
216227
$answer ~= \n;
217228
}
218229
}

0 commit comments

Comments
 (0)