畑正憲
and 1 contributors

NAME

Lingua::JA::Fold - to fold a Japanese text.

SYNOPSIS

 use utf8;
 use Lingua::JA::Fold qw(fold tab2space kana_half2full);
 
 my $text = 'アイウエオ      漢字';
 
 # replace a [TAB] with four [SPACE]s.
 $text = tab2space('text' => $text, 'space' => 4);
 # convert a half-width 'Kana' character to a full-width one.
 $text = kana_half2full($text);
 
 # fold a text under full-width two characters par a line.
 $text = fold('text' => $text, 'length' => 2);
 
 # output the result
 utf8::encode($text);
 print $text;

DESCRIPTION

This module is used to fold a Japanese text and so on.

The Japanese (the Chinese and the Korean would be the same) text has traditionally unique manner in representing. Basically those characters are used to be represented in two kind of size which is 'full-width' or 'half-width'. Width and Height of full-width characters are the same size (regular square). At the point, it is different from the alphabet characters which have normally variable (slim) width in representing. Roughly say, we call width of alphabet characters and Arabic numbers as a half, and do the width of other characters as a full. In a Japanese text which is mixed with alphabet and Arabic numbers, a character has a width, it would be full or half.

For such reasons, to fold a Japanese text is rather complicate thing.

FUNCTIONS

fold('text' => $text, 'length' => $i [, 'mode' => $mode])

Function. To fold a string within specified length of $i.

The way in which to calculate length is differs by a mode.

 'full-width' : culculated for a full-width character.
 'traditional': culculated for a full-width character; reflects traditional manner of composition.
 (not given)  : igore size difference between a full and a half.
The Japanese Traditional Manner of Composition

This formal manner is another saying as the forbidden rule. The rule is: 1) a termination mark like Ten "," and Maru ".", 2) a closing mark -- brace or parenthesis or bracket -- like ")", "}", "]", ">" and etc., 3) a repeat mark, those should not be placed at the top of a line. If it would be occured, such mark should be moved to the next to the bottom of the previous line.

Actually by this module what is detect as a forbidden mark are listed next:

 ’”、。〃々〉》」』】〕〟ゝゞヽヾ),.]}

Note that all of these marks are full-width Japanese characters.

length_half($text)

Function. Exportable. This is for counting length of a text for a half-width character.

length_full($text)

Function. Exportable. This is for counting length of a text for a full-width character.

tab2space('text' => $text, 'space' => $i)

Function. Exportable. To replace a [TAB] character in a text with given number of [SPACE]s.

kana_half2full($text)

Function. Exportable. To convert a character in a text from half-width 'Kana' to full-width one.

SEE ALSO

module: utf8
module: Encode

NOTE

This module runs under Unicode/UTF-8 environment (hence Perl5.8 or later is required), you should input text as UTF-8 flaged string. Specify the use utf8; pragma in your source code and use utf8::decode() method to UTF-8 flag on.

AUTHOR

Masanori HATA http://www.mihr.net/ (Saitama, JAPAN)

COPYRIGHT

Copyright ©2003-2008 Masanori HATA. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 32:

Non-ASCII character seen before =encoding in ''アイウエオ'. Assuming UTF-8