[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.28, Tue Oct 18 17:42:48 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 will be deleted, and backslashes will be doubled. The
829  doubled. The effect is to exactly reverse the effect of L</UnEscape>.  result is to 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;
857              # Strip the processed section off the real string.              # Strip the processed section off the real string.
858              $realString = substr $realString, (length $2) + (length $1);              $realString = substr $realString, (length $2) + (length $1);
859              # Encode the escape sequence.              # Get the matched character.
860              my $char = $2;              my $char = $2;
861              $char =~ tr/ \t\n/btn/;              # If we have a CR, we are done.
862                if ($char ne "\r") {
863                    # It's not a CR, so encode the escape sequence.
864                    $char =~ tr/\t\n/tn/;
865              $retVal .= "\\" . $char;              $retVal .= "\\" . $char;
866                }
867          } else {          } else {
868              # 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
869              # transferred unmodified.              # transferred unmodified.
# Line 875  Line 879 
879    
880  C<< my $realString = Tracer::UnEscape($codedString); >>  C<< my $realString = Tracer::UnEscape($codedString); >>
881    
882  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
883  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, and C<\\> by a backslash. C<\r> codes will
884    be deleted.
885    
886  =over 4  =over 4
887    
# Line 896  Line 901 
901  sub UnEscape {  sub UnEscape {
902      # Get the parameter.      # Get the parameter.
903      my ($codedString) = @_;      my ($codedString) = @_;
     Tracer("Coded string is \"$codedString\".") if T(4);  
904      # Initialize the return variable.      # Initialize the return variable.
905      my $retVal = "";      my $retVal = "";
906      # Only proceed if the incoming string is nonempty.      # Only proceed if the incoming string is nonempty.
907      if (defined $codedString) {      if (defined $codedString) {
908          # 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
909          # translating because it causes problems with the escaped slash. ("\\b" becomes          # translating because it causes problems with the escaped slash. ("\\t" becomes
910          # "\ " no matter what we do.)          # "\<tab>" no matter what we do.)
911          while (length $codedString > 0) {          while (length $codedString > 0) {
912              # Look for the first escape sequence.              # Look for the first escape sequence.
913              if ($codedString =~ /^(.*?)\\(\\|b|n|t)/) {              if ($codedString =~ /^(.*?)\\(\\|n|t|r)/) {
914                  # 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
915                  # 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.
916                  $retVal .= $1;                  $retVal .= $1;
917                  $codedString = substr $codedString, (2 + length $1);                  $codedString = substr $codedString, (2 + length $1);
918                  # Decode the escape sequence.                  # Get the escape value.
919                  my $char = $2;                  my $char = $2;
920                  $char =~ tr/\\btn/\\ \t\n/;                  # If we have a "\r", we are done.
921                    if ($char ne 'r') {
922                        # Here it's not an 'r', so we convert it.
923                        $char =~ tr/\\tn/\\\t\n/;
924                  $retVal .= $char;                  $retVal .= $char;
925                    }
926              } else {              } else {
927                  # 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
928                  # transferred unmodified.                  # transferred unmodified.

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3