MBPrintf の Github ページを作ってみた

Github Pages というのがあることを発見したので作ってみました。こんなカッコいいページが簡単に作れちゃうんですね。内容は大したことないんですが :-)。独自ドメインも使えるみたいだけど、それはまたそのうち。

 中身は、2年前に作った MBPrintf.pm という Perl モジュールのページですよ。マルチバイト文字を扱うための printf です。

EUC の場合は、何も考えずに printf で日本語を処理しても、大概の場合は期待通りに出るんですね。20年も使っている自前の住所録コマンドをやっと Unicode 対応にしたら、printf の表示が出鱈目になっちゃって、昔のコードを読み直して修正するのが面倒だったので、まんま printf を置き換えられるようにしたものです。やっつけですが、とりあえず何も考えずに置き換えれば動くので結構便利です。効率はいいとは言えないけど、変に考えてフォーマット文字列を作るとか、頑張って printf を使わずに出力するとかよりはマシかもしれません。

試してないけど、韓国語や中国語でも使えるんじゃないのかなあ。

そうそう、マニュアルに書き忘れていますが、mbwidth という関数を export すると表示幅がわかります。

ファイルハンドルも含めて、完全に printf と互換にできる方法を知っている人がいたら教えてください。

NAME
       MBPrintf − printf family functions to handle multi−byte characters

SYNOPSIS
       use MBPrintf;

       mbprintf(FORMAT, LIST)

       mbsprintf(FORMAT, LIST)

DESCRIPTION
       "MBPrintf" is a almost‐printf‐compatible library with a capability of
       handling multi‐byte wide characters properly.

       "MBPrintf" は、マルチバイト文字を処理するための、ほぼ printf と互換
       のライブラリ関数です。

FUNCTIONS
       mbprintf(FORMAT, LIST)
       mbsprintf(FORMAT, LIST)
           Use just like Perl’s printf and sprintf functions except that
           printf does not take FILEHANDLE as a first argument.

           使い方は Perl の printf, sprintf と同じです。ただし、ファイルハン
           ドルを指定することはできません。

IMPLEMENTATION NOTES
       Strings in the LIST which contains wide‐width character are replaced
       before formatting, and recovered after the process.  Number of replaced
       arguments are limited by 25.

       LIST 中に全角文字を含む文字列があった場合、整形処理を行う前に別の文字列に
       置換され、処理が終わった後で元に戻されます。変換する文字列の最大数は25に
       制限されています。

       Unique replacement string contains a combination of control characters
       (Control‐A to Control‐E).  So, if the FORMAT contains a string in this
       range, it has a chance to be a subject of replacement.

       置換文字列には制御文字 (コントロールAからコントロールE)が含まれるため、
       これらの文字が FORMAT に含まれている場合には注意が必要です。

       Wide‐character judgement is done based on Unicode property
       East_Asian_Width is Wide or FullWidth.  There is another value
       Ambiguous and treatment of this type characters are literaly ambiguous
       and is not considered now.  It might be better to use
       Unicode::EastAsianWidth instead.

       全角文字の判定は Unicode の East_Asian_Width プロパティが Wide あるいは
       FullWidth であることで行っています。これ以外に Ambiguous という値があり
       ますが、取り扱いが文字通り曖昧なため考慮していません。
       Unicode::EastAsianWidth を使った方がいいのかも知れません。

AUTHOR
       Copyright (c) 2011 Kazumasa Utashiro.  All rights reserved.

LICENSE
       See <http://www.perl.com/perl/misc/Artistic.html>

はてなの Facebook 連携も初体験。