[Bio] / FigKernelPackages / Tracer.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/Tracer.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.23, Tue Sep 13 05:36:12 2005 UTC revision 1.27, Sat Oct 15 07:57:10 2005 UTC
# Line 824  Line 824 
824    
825  C<< my $codedString = Tracer::Escape($realString); >>  C<< my $codedString = Tracer::Escape($realString); >>
826    
827  Escape a string for use in a command length. Spaces will be replaced by C<\b>,  Escape a string for use in a command length. Tabs will be replaced by C<\t>, new-lines
828  tabs replaced by C<\t>, new-lines replaced by C<\n>, and backslashes will be  replaced by C<\n>, carriage returns by C<\r> and backslashes will be doubled. The effect
829  doubled. The effect is to exactly reverse the effect of L</UnEscape>.  is to exactly reverse the effect of L</UnEscape>.
830    
831  =over 4  =over 4
832    
# Line 850  Line 850 
850      # Loop through the parameter string, looking for sequences to escape.      # Loop through the parameter string, looking for sequences to escape.
851      while (length $realString > 0) {      while (length $realString > 0) {
852          # Look for the first sequence to escape.          # Look for the first sequence to escape.
853          if ($realString =~ /^(.*?)([ \n\t\\])/) {          if ($realString =~ /^(.*?)([\n\t\r\\])/) {
854              # Here we found it. The text preceding the sequence is in $1. The sequence              # Here we found it. The text preceding the sequence is in $1. The sequence
855              # itself is in $2. First, move the clear text to the return variable.              # itself is in $2. First, move the clear text to the return variable.
856              $retVal .= $1;              $retVal .= $1;
# Line 858  Line 858 
858              $realString = substr $realString, (length $2) + (length $1);              $realString = substr $realString, (length $2) + (length $1);
859              # Encode the escape sequence.              # Encode the escape sequence.
860              my $char = $2;              my $char = $2;
861              $char =~ tr/ \t\n/btn/;              $char =~ tr/\t\n\r/tnr/;
862              $retVal .= "\\" . $char;              $retVal .= "\\" . $char;
863          } else {          } else {
864              # Here there are no more escape sequences. The rest of the string is              # Here there are no more escape sequences. The rest of the string is
# Line 875  Line 875 
875    
876  C<< my $realString = Tracer::UnEscape($codedString); >>  C<< my $realString = Tracer::UnEscape($codedString); >>
877    
878  Replace escape sequences with their actual equivalents. C<\b> will be replaced by a space,  Replace escape sequences with their actual equivalents. C<\t> will be replaced by
879  C<\t> by a tab, C<\n> by a new-line character, and C<\\> by a back-slash.  a tab, C<\n> by a new-line character, C<\r> by a carriage return and C<\\> by a
880    back-slash.
881    
882  =over 4  =over 4
883    
# Line 896  Line 897 
897  sub UnEscape {  sub UnEscape {
898      # Get the parameter.      # Get the parameter.
899      my ($codedString) = @_;      my ($codedString) = @_;
     Tracer("Coded string is \"$codedString\".") if T(4);  
900      # Initialize the return variable.      # Initialize the return variable.
901      my $retVal = "";      my $retVal = "";
902      # Only proceed if the incoming string is nonempty.      # Only proceed if the incoming string is nonempty.
903      if (defined $codedString) {      if (defined $codedString) {
904          # Loop through the parameter string, looking for escape sequences. We can't do          # Loop through the parameter string, looking for escape sequences. We can't do
905          # translating because it causes problems with the escaped slash. ("\\b" becomes          # translating because it causes problems with the escaped slash. ("\\t" becomes
906          # "\ " no matter what we do.)          # "\<tab>" no matter what we do.)
907          while (length $codedString > 0) {          while (length $codedString > 0) {
908              # Look for the first escape sequence.              # Look for the first escape sequence.
909              if ($codedString =~ /^(.*?)\\(\\|b|n|t)/) {              if ($codedString =~ /^(.*?)\\(\\|n|t|r)/) {
910                  # Here we found it. The text preceding the sequence is in $1. The sequence                  # Here we found it. The text preceding the sequence is in $1. The sequence
911                  # itself is in $2. First, move the clear text to the return variable.                  # itself is in $2. First, move the clear text to the return variable.
912                  $retVal .= $1;                  $retVal .= $1;
913                  $codedString = substr $codedString, (2 + length $1);                  $codedString = substr $codedString, (2 + length $1);
914                  # Decode the escape sequence.                  # Decode the escape sequence.
915                  my $char = $2;                  my $char = $2;
916                  $char =~ tr/\\btn/\\ \t\n/;                  $char =~ tr/\\tnr/\\\t\n\r/;
917                  $retVal .= $char;                  $retVal .= $char;
918              } else {              } else {
919                  # Here there are no more escape sequences. The rest of the string is                  # Here there are no more escape sequences. The rest of the string is

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.27

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3