[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.29, Wed Nov 23 17:53:52 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.
# Line 1151  Line 1159 
1159  C<< Assert($condition1, $condition2, ... $conditionN); >>  C<< Assert($condition1, $condition2, ... $conditionN); >>
1160    
1161  Return TRUE if all the conditions are true. This method can be used in conjunction with  Return TRUE if all the conditions are true. This method can be used in conjunction with
1162  the OR operator and the L</Confess> method, B<Assert> can function as a debugging assert.  the OR operator and the L</Confess> method as a debugging assert.
1163  So, for example  So, for example
1164    
1165  C<< Assert($recNum >= 0) || Confess("Invalid record number $recNum."); >>  C<< Assert($recNum >= 0) || Confess("Invalid record number $recNum."); >>
# Line 1364  Line 1372 
1372  sub Strip {  sub Strip {
1373      # Get a copy of the parameter string.      # Get a copy of the parameter string.
1374      my ($string) = @_;      my ($string) = @_;
1375      my $retVal = $string;      my $retVal = (defined $string ? $string : "");
1376      # Strip the line terminator characters.      # Strip the line terminator characters.
1377      $retVal =~ s/(\r|\n)+$//g;      $retVal =~ s/(\r|\n)+$//g;
1378      # Return the result.      # Return the result.
# Line 1432  Line 1440 
1440      return $retVal;      return $retVal;
1441  }  }
1442    
1443    =head3 EOF
1444    
1445    This is a constant that is lexically greater than any useful string.
1446    
1447    =cut
1448    
1449    sub EOF {
1450        return "\xFF\xFF\xFF\xFF\xFF";
1451    }
1452    
1453  =head3 TICK  =head3 TICK
1454    
1455  C<< my @results = TICK($commandString); >>  C<< my @results = TICK($commandString); >>

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3