Last active
December 20, 2016 02:40
-
-
Save msr-i386/3512ec10ee48d5b275e63b2796ad8603 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo 突然のワンライナーEx | awk '{for(i=1;i<=length();i++){len+=(substr($0,i,1)~/[\x01-\x7E]/)?1:2}for(i=0;i<len/2+2;i++){up=up "人";dn=dn "Y^"}printf("_%s_\n> %s <\n ̄%s ̄\n",up,$0,dn)}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
解説
1文字ずつ順に取り出し、文字がUTF-8で1バイト文字である場合は1、それ以外は2とすればよい。
UTF-8で1バイト文字かどうかは、文字のバイト列のうち0x01~0x7eが含まれているかどうかで判定する。
これらは全角換算で1文字なので、1.で取得した文字数の半分と両端の余白(半角換算2文字)の合計数分増やしていく。
printfを使用して整形。