The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

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

SYNOPSIS

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

DESCRIPTION

This module is used for Japanese text wrapping 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'. The width and the 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 the 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 wrap Japanese text is rather complicate thing.

FUNCTIONS

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

Function. Fold a string within the specified length of $i.

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

 'full-width' : culculate for a full-width character.
 'traditional': culculate for a full-width character; reflects the traditional manner of composition.
 (not given)  : igore the 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 these marks are all full-width Japanese characters.

length_half($text)

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

length_full($text)

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

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

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

kana_half2full($text)

Function. Exportable. 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 a UTF-8 flaged string. Specify the use utf8; pragma in your source code and use utf8::decode() method to UTF-8 flag on a string.

AUTHOR

Masanori HATA <lovewing@dream.big.or.jp> (Saitama, JAPAN)

COPYRIGHT

Copyright (c) 2003-2004 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 CP1252