[system] / trunk / pg / lib / Value / String.pm Repository:
ViewVC logotype

View of /trunk/pg/lib/Value/String.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5696 - (download) (as text) (annotate)
Sat Jun 14 12:14:21 2008 UTC (11 years, 8 months ago) by dpvc
File size: 2010 byte(s)
Added

	 no strict "refs"

to try to avoid new error checking in Perl 5.10.

    1 ###########################################################################
    2 
    3 package Value::String;
    4 my $pkg = 'Value::String';
    5 
    6 use strict; no strict "refs";
    7 our @ISA = qw(Value);
    8 
    9 #
   10 #  Create a string object
   11 #
   12 sub new {
   13   my $self = shift; my $class = ref($self) || $self;
   14   my $context = (Value::isContext($_[0]) ? shift : $self->context);
   15   my $x = join('',@_);
   16   my $s = bless {data => [$x], context => $context}, $class;
   17   if ($Parser::installed && !($x eq '' && $self->getFlag('allowEmptyStrings'))) {
   18     my $strings = $context->{strings};
   19     if (!$strings->{$x}) {
   20       my $X = $strings->{uc($x)};
   21       Value::Error("String constant '%s' is not defined in this context",$x)
   22         unless $X && !$X->{caseSensitive};
   23       $x = uc($x); while ($strings->{$x}{alias}) {$x = $strings->{$x}{alias}}
   24     }
   25     $s->{caseSensitive} = 1 if $strings->{$x}{caseSensitive};
   26   }
   27   return $s;
   28 }
   29 
   30 #
   31 #  Return the appropriate data.
   32 #
   33 sub length {1}
   34 sub typeRef {$Value::Type{string}}
   35 sub value {shift->{data}[0]}
   36 
   37 sub isOne {0}
   38 sub isZero {0}
   39 
   40 sub transferFlags {}
   41 
   42 ##################################################
   43 
   44 #
   45 #  Convert to a string object
   46 #
   47 sub promote {
   48   my $self = shift;
   49   my $context = (Value::isContext($_[0]) ? shift : $self->context);
   50   my $x = (scalar(@_) ? shift : $self); $x = [$x,@_] if scalar(@_) > 0;
   51   $x = Value::makeValue($x,showError=>1,context=>$context);
   52   $x = join('',@{$x}) if ref($x) eq 'ARRAY';
   53   $x = $self->make($context,$x) unless Value::isValue($x);
   54   return $x;
   55 }
   56 
   57 ############################################
   58 #
   59 #  Operations on strings
   60 #
   61 sub compare {
   62   my ($self,$l,$r) = Value::checkOpOrderWithPromote(@_);
   63   return $l->value cmp $r->value if $l->{caseSensitive} || $r->{caseSensitive};
   64   return uc($l->value) cmp uc($r->value);
   65 }
   66 
   67 ############################################
   68 #
   69 #  Generate the various output formats
   70 #
   71 
   72 sub TeX {'{\rm '.shift->value.'}'}
   73 sub perl {"'".shift->value."'"}
   74 
   75 ###########################################################################
   76 
   77 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9