summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorNick Ing-Simmons <nik@tiuk.ti.com>2001-02-25 11:30:22 +0000
committerNick Ing-Simmons <nik@tiuk.ti.com>2001-02-25 11:30:22 +0000
commit50d2698546d7dba5ed48b29bf1c13887b041a4ba (patch)
tree04d357db5082a7935510aaddf48744a684d2b62f /ext
parentc745e42cb33cb9fcfc4d47fe732cfa4725aa5d07 (diff)
downloadperl-50d2698546d7dba5ed48b29bf1c13887b041a4ba.tar.gz
Change method names in Encode implementation classes to something
less confusing (preparing to "go public"). p4raw-id: //depot/perlio@8927
Diffstat (limited to 'ext')
-rw-r--r--ext/Encode/Encode.pm44
-rw-r--r--ext/Encode/Encode.xs10
2 files changed, 35 insertions, 19 deletions
diff --git a/ext/Encode/Encode.pm b/ext/Encode/Encode.pm
index eb07f1ffc6..f17cc1afeb 100644
--- a/ext/Encode/Encode.pm
+++ b/ext/Encode/Encode.pm
@@ -113,7 +113,7 @@ sub encode
my ($name,$string,$check) = @_;
my $enc = find_encoding($name);
croak("Unknown encoding '$name'") unless defined $enc;
- my $octets = $enc->fromUnicode($string,$check);
+ my $octets = $enc->encode($string,$check);
return undef if ($check && length($string));
return $octets;
}
@@ -123,7 +123,7 @@ sub decode
my ($name,$octets,$check) = @_;
my $enc = find_encoding($name);
croak("Unknown encoding '$name'") unless defined $enc;
- my $string = $enc->toUnicode($octets,$check);
+ my $string = $enc->decode($octets,$check);
return undef if ($check && length($octets));
return $string;
}
@@ -135,9 +135,9 @@ sub from_to
croak("Unknown encoding '$from'") unless defined $f;
my $t = find_encoding($to);
croak("Unknown encoding '$to'") unless defined $t;
- my $uni = $f->toUnicode($string,$check);
+ my $uni = $f->decode($string,$check);
return undef if ($check && length($string));
- $string = $t->fromUnicode($uni,$check);
+ $string = $t->encode($uni,$check);
return undef if ($check && length($uni));
return length($_[0] = $string);
}
@@ -156,14 +156,24 @@ sub decode_utf8
return $str;
}
+package Encode::Encoding;
+# Base class for classes which implement encodings
+# Temporary legacy methods
+sub toUnicode { shift->decode(@_) }
+sub fromUnicode { shift->encode(@_) }
+
+package Encode::XS;
+use base 'Encode::Encoding';
+
package Encode::Unicode;
+use base 'Encode::Encoding';
# Dummy package that provides the encode interface but leaves data
# as UTF-8 encoded. It is here so that from_to() works.
sub name { 'Unicode' }
-sub toUnicode
+sub decode
{
my ($obj,$str,$chk) = @_;
Encode::utf8_upgrade($str);
@@ -171,9 +181,10 @@ sub toUnicode
return $str;
}
-*fromUnicode = \&toUnicode;
+*encode = \&decode;
package Encode::utf8;
+use base 'Encode::Encoding';
# package to allow long-hand
# $octets = encode( utf8 => $string );
@@ -181,7 +192,7 @@ package Encode::utf8;
sub name { 'utf8' }
-sub toUnicode
+sub decode
{
my ($obj,$octets,$chk) = @_;
my $str = Encode::decode_utf8($octets);
@@ -193,7 +204,7 @@ sub toUnicode
return undef;
}
-sub fromUnicode
+sub encode
{
my ($obj,$string,$chk) = @_;
my $octets = Encode::encode_utf8($string);
@@ -202,6 +213,7 @@ sub fromUnicode
}
package Encode::Table;
+use base 'Encode::Encoding';
sub read
{
@@ -266,7 +278,7 @@ sub representation
$obj-{'Rep'}->($ch);
}
-sub toUnicode
+sub decode
{
my ($obj,$str,$chk) = @_;
my $rep = $obj->{'Rep'};
@@ -296,7 +308,7 @@ sub toUnicode
return $uni;
}
-sub fromUnicode
+sub encode
{
my ($obj,$uni,$chk) = @_;
my $fmuni = $obj->{'FmUni'};
@@ -319,12 +331,14 @@ sub fromUnicode
}
package Encode::iso10646_1;
+use base 'Encode::Encoding';
+
# Encoding is 16-bit network order Unicode
# Used for X font encodings
sub name { 'iso10646-1' }
-sub toUnicode
+sub decode
{
my ($obj,$str,$chk) = @_;
my $uni = '';
@@ -338,7 +352,7 @@ sub toUnicode
return $uni;
}
-sub fromUnicode
+sub encode
{
my ($obj,$uni,$chk) = @_;
my $str = '';
@@ -359,6 +373,8 @@ sub fromUnicode
package Encode::Escape;
+use base 'Encode::Encoding';
+
use Carp;
sub read
@@ -377,12 +393,12 @@ sub read
sub name { shift->{'Name'} }
-sub toUnicode
+sub decode
{
croak("Not implemented yet");
}
-sub fromUnicode
+sub encode
{
croak("Not implemented yet");
}
diff --git a/ext/Encode/Encode.xs b/ext/Encode/Encode.xs
index 3913fafb48..40c3dc7f70 100644
--- a/ext/Encode/Encode.xs
+++ b/ext/Encode/Encode.xs
@@ -167,7 +167,7 @@ PerlIOEncode_fill(PerlIO *f)
XPUSHs(e->bufsv);
XPUSHs(&PL_sv_yes);
PUTBACK;
- if (perl_call_method("toUnicode",G_SCALAR) != 1)
+ if (perl_call_method("decode",G_SCALAR) != 1)
code = -1;
SPAGAIN;
uni = POPs;
@@ -223,7 +223,7 @@ PerlIOEncode_flush(PerlIO *f)
XPUSHs(e->bufsv);
XPUSHs(&PL_sv_yes);
PUTBACK;
- if (perl_call_method("fromUnicode",G_SCALAR) != 1)
+ if (perl_call_method("encode",G_SCALAR) != 1)
code = -1;
SPAGAIN;
str = POPs;
@@ -462,12 +462,12 @@ sv_utf8_downgrade(sv,failok=0)
SV * sv
bool failok
-MODULE = Encode PACKAGE = Encode::XS PREFIX = Encode_
+MODULE = Encode PACKAGE = Encode::XS PREFIX = Method_
PROTOTYPES: ENABLE
void
-Encode_toUnicode(obj,src,check = 0)
+Method_decode(obj,src,check = 0)
SV * obj
SV * src
int check
@@ -480,7 +480,7 @@ CODE:
}
void
-Encode_fromUnicode(obj,src,check = 0)
+Method_encode(obj,src,check = 0)
SV * obj
SV * src
int check