escapeName static method
Applies the #xx escapes required in a PDF name.
Implementation
static String escapeName(String name) {
final body = name.startsWith('/') ? name.substring(1) : name;
final buffer = StringBuffer('/');
for (final unit in body.codeUnits) {
final regular = unit > 0x20 &&
unit < 0x7F &&
unit != 0x23 && // #
unit != 0x28 &&
unit != 0x29 &&
unit != 0x3C &&
unit != 0x3E &&
unit != 0x5B &&
unit != 0x5D &&
unit != 0x7B &&
unit != 0x7D &&
unit != 0x2F &&
unit != 0x25;
if (regular) {
buffer.writeCharCode(unit);
} else {
buffer.write('#');
buffer.write((unit & 0xFF).toRadixString(16).padLeft(2, '0'));
}
}
return buffer.toString();
}