📄 foounparser.pm
字号:
# $Id: FooUnparser.pm,v 1.3 1996/07/27 07:47:22 matt Exp $## Foo unparser utility## (c) June 96 Matt Phillips.require 'FooObject.pm';package FooUnparser;# unparses object to file.sub unparse{ my ($file, $object) = @_; doObject ($file, $object, 0);}sub doObject{ my ($file, $object, $indent) = @_; if ($object->isAtomic ()) { my $value = $object->getAttr (); # change control/binary chars into \ddd form $value =~ s/([\x00-\x20\x80-\xff])/sprintf ("\\%02x", ord ($1))/ge; # escape any "'s $value =~ s/\"/\\\"/g; print $file ("\"$value\""); } else { my $first = 1; # true if at first attribute print $file ('( '); # output each attribute for $attr ($object->getAttrNames ()) { newlineAndIndent ($file, $indent + 1) if !$first; $first = 0; doAttr ($file, $attr, $object->getAttrs ($attr), $indent + 1); } newlineAndIndent ($file, $indent); print $file (')') }}sub doAttr{ my ($file, $attr, $values, $indent) = @_; print $file ($attr); if ($#$values == 0) { # no []'s if single value for attr my $value = $$values[0]; if ($value->isAtomic ()) { # put value on same line if atomic print $file ("\t"); } else { newlineAndIndent ($file, $indent); } doObject ($file, $value, $indent); } else { # use [] form for values my $first = 1; newlineAndIndent ($file, $indent); print $file ('[ '); for $value (@$values) { newlineAndIndent ($file, $indent + 1) if !$first; $first = 0; doObject ($file, $value, $indent + 1); } newlineAndIndent ($file, $indent); print $file (']'); }}sub newlineAndIndent{ my ($file, $indent) = @_; print $file ("\n", ' 'x$indent);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -