summaryrefslogtreecommitdiff
path: root/fml/lib/FML/Language/Japanese/Utils.pm
diff options
context:
space:
mode:
Diffstat (limited to 'fml/lib/FML/Language/Japanese/Utils.pm')
-rw-r--r--fml/lib/FML/Language/Japanese/Utils.pm101
1 files changed, 101 insertions, 0 deletions
diff --git a/fml/lib/FML/Language/Japanese/Utils.pm b/fml/lib/FML/Language/Japanese/Utils.pm
new file mode 100644
index 00000000..92c858d8
--- /dev/null
+++ b/fml/lib/FML/Language/Japanese/Utils.pm
@@ -0,0 +1,101 @@
+#-*- perl -*-
+#
+# Copyright (C) 2001 Ken'ichi Fukamachi
+# All rights reserved. This program is free software; you can
+# redistribute it and/or modify it under the same terms as Perl itself.
+#
+# $FML: Utils.pm,v 1.2 2001/06/10 10:22:47 fukachan Exp $
+#
+
+package FML::NL::Japanese::Utils;
+use strict;
+use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
+use Carp;
+
+=head1 NAME
+
+FML::NL::Japanese::Utils - what is this
+
+=head1 SYNOPSIS
+
+ use FML::NL::Japanese::Utils qw(is_iso2022jp_string);
+ if ( is_iso2022jp_string($string) ) { do_something_if_Japanese;}
+
+=head1 DESCRIPTION
+
+Utilities for Japanse string
+
+=head1 METHODS
+
+=head2 <is_iso2022jp_string($string)>
+
+check whether $string looks Japanese.
+return 1 if it looks so.
+
+=cut
+
+require Exporter;
+
+@ISA = qw(Exporter);
+@EXPORT_OK = qw(is_iso2022jp_string);
+
+
+sub is_iso2022jp_string
+{
+ my ($buf) = @_;
+ return (not _look_not_iso2022jp_string($buf));
+}
+
+
+# based on fml-support: 07020, 07029
+# Koji Sudo <koji@cherry.or.jp>
+# Takahiro Kambe <taca@sky.yamashina.kyoto.jp>
+# check the given buffer has unusual Japanese (not ISO-2022-JP)
+sub _look_not_iso2022jp_string
+{
+ my ($buf) = @_;
+
+ # check 8 bit on
+ if ($buf =~ /[\x80-\xFF]/){
+ return 1;
+ }
+
+ # check SI/SO
+ if ($buf =~ /[\016\017]/) {
+ return 1;
+ }
+
+ # HANKAKU KANA
+ if ($buf =~ /\033\(I/) {
+ return 1;
+ }
+
+ # MSB flag or other control sequences
+ if ($buf =~ /[\001-\007\013\015\020-\032\034-\037\177-\377]/) {
+ return 1;
+ }
+
+ 0; # O.K.
+}
+
+
+
+=head1 AUTHOR
+
+Ken'ichi Fukamachi
+
+=head1 COPYRIGHT
+
+Copyright (C) 2001 Ken'ichi Fukamachi
+
+All rights reserved. This program is free software; you can
+redistribute it and/or modify it under the same terms as Perl itself.
+
+=head1 HISTORY
+
+FML::NL::Japanese::Utils appeared in fml5 mailing list driver package.
+See C<http://www.fml.org/> for more details.
+
+=cut
+
+1;