[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 2610 - (download) (as text) (annotate)
Sat Aug 14 13:55:54 2004 UTC (15 years, 6 months ago) by dpvc
File size: 1581 byte(s)
The class file for the Value::String object.  (Forgot to add it before
the last commit.  Sorry!)

    1 ###########################################################################
    2 
    3 package Value::String;
    4 my $pkg = 'Value::String';
    5 
    6 use strict;
    7 use vars qw(@ISA);
    8 @ISA = qw(Value);
    9 
   10 use overload
   11        '.'   => \&Value::_dot,
   12        '<=>' => \&compare,
   13        'cmp' => \&compare,
   14   'nomethod' => \&Value::nomethod,
   15         '""' => \&Value::stringify;
   16 
   17 #
   18 #  Create a string object
   19 #
   20 sub new {
   21   my $self = shift; my $class = ref($self) || $self;
   22   my $x = join('',@_);
   23   if ($Parser::installed) {
   24     Value::Error("Unrecognized string '$x'")
   25       unless $$Value::context->{strings}{$x};
   26   }
   27   bless {data => [$x]}, $class;
   28 }
   29 
   30 #
   31 #  Return the appropriate data.
   32 #
   33 sub length {1}
   34 sub typeRef {my $self = shift; Value::Type($self->class,$self->length)}
   35 sub value {shift->{data}[0]}
   36 
   37 ##################################################
   38 
   39 #
   40 #  Convert to a string object
   41 #
   42 sub promote {
   43   my $x = shift; $x = [$x,@_] if scalar(@_) > 0;
   44   $x = Value::makeValue($x); $x = join('',@{$x}) if ref($x) eq 'ARRAY';
   45   $x = $pkg->make($x) unless Value::isValue($x);
   46   return $x;
   47 }
   48 
   49 ############################################
   50 #
   51 #  Operations on strings
   52 #
   53 
   54 sub compare {
   55   my ($l,$r,$flag) = @_;
   56   if ($l->promotePrecedence($r)) {return $r->compare($l,!$flag)}
   57   $r = promote($r); if ($flag) {my $tmp = $l; $l = $r; $r = $tmp}
   58   return $l->value cmp $r->value;
   59 }
   60 
   61 ############################################
   62 #
   63 #  Generate the various output formats
   64 #
   65 
   66 sub TeX {'{\rm '.shift->value.'}'}
   67 sub perl {"'".shift->value."'"}
   68 
   69 ###########################################################################
   70 
   71 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9