You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert
https://github.com/tokuhirom/utf728 UTF-8 から UTF-7 への変換をおこなう対話的なシェルをつくりたい、などのように単機能の対話的なシェルをつくりたいというケースはままあるかとおもいます。 そんな場合には readline というモジュールが組込まれているので、それをつかえばいいです。 具体的には以下のように書けば OK です。簡単ですね。 var Iconv = require('iconv').Iconv, rl = require('readline'), util = require('util'), undefined; function MyApp() { this.utf827 = new Iconv('UTF-8', 'UTF-7'); this.utf728 = new Iconv('UTF-7', 'UTF-8'); } My
はじめに ソフト作ってるとき、「データ丸見えじゃなくてちょっと隠したいなー」ってときはありませんか? そんなときにおススメな ROT13 っていう方法があります。 ROT13 または ROT-13、rot13 は単換字式暗号(シーザー暗号)の一つである。 アルファベットを一文字毎に13文字後のアルファベットに置き換える。 Aは Nに、 B は O に置き換えられ、以下同様である。 http://ja.wikipedia.org/wiki/ROT13 すごい単純な仕組みだけど、これを使えば簡単に可逆暗号することができます。 可逆暗号やってみよう! さてここからが本題です。 実はPythonには可逆暗号のrot13のencodeとdecodeが用意されています。 # 元の文字列 str = u'xxxxxxxxxxxxxxx' # 暗号化します。 # rot13 でエンコード出来るように ba
続編あり ⇒ HTML::Entities の encode_entities() ハックの続き どの文字を文字参照にエンコードするべきかは、アプリケーションを動かす状況に応じて決めるべきものですけど、落としどころとして制御文字とHTML定義の文字実体参照に限るのは悪くないのではないかと、やりかたを探ってみました。HTML::Entities はハッシュ %entity2char にHTML文字実体参照の名前から対応文字への変換テーブルを格納しているので、それを使うことにしました。 use strict; use warnings; use HTML::Entities; use Encode; use Readonly; Readonly my $SPECIAL_ALL => quotemeta join q{}, (map { chr $_ } 0 .. 8, 11, 12, 14 .
2008年05月11日21:00 カテゴリLightweight LanguagesTips perl - 文字参照を(en|de)codeする すでに正解が書かれていますが、 [を] Unicode の16進数の実体参照を正規表現などで元に戻す pack と Encode::decode を使うと良いみたい。 はてなブックマーク - miyagawaのブックマーク / 2008年05月11日 それ HTML::Entities::decode / regexp でも chr(hex($1)) のほうがわかりやすくないかな 繰り返しておくだけの価値はあるので。 HTML::Entitiesを使う まず、HTML::Entitiesのdecode_entities()を使うという方法があります。これがベストプラクティスかな。 #!/usr/local/bin/perl use strict;
Catalyst - Session管理とHTMLエンティティコード(数値文字実体参照) でも言及されているように、Catalyst::Plugin::Session::State::URI を使っていると、 <img alt="日本語" /> などが、エスケープされてしまい、表示がおかしくなったりします。 これは、HTML::TokeParser::Simple::Token::Tag::Start が悪さをしているのですが、 HTML::TokeParse::Simple::Token::Tag::Start が呼んでいる HTML::Entities::encode_entities() の第二引数を設定できれば、この問題は回避できるのですが、HTML::TokeParser::Simple::Token::Tag::Start::rewrite_tag() を redefine し
HTML: :Entites hack PerlでHTMLの一般文字参照とか数字文字参照とかを扱うのにHTML::Entitiesというモジュールがあるんだけど、 これは日本語とかのASCII以外をすべて数字文字参照にしてしまうので、その辺りの対処方。 一番手っ取り早いのは、 use strict; use warnings; use utf8; use HTML::Entities; { no warnings 'redefine'; *HTML::Entities::num_entity = sub { $_[0] }; } print encode_entities('<あああ>'); こんな感じにすることなんだけど、これするとencode_entities_numericが動かなくなる。 あとどう見てもバッドノウハウ。 なんで、%HTML::Entities::entity2ch
TreeBuilder を使って,日本語と文字参照を含む文書を処理する場合の手順について,はまったのでまとめておく。 HTML::TreeBuilder が文字参照を勝手にデコードしてしまうので困った。便利なのだが,扱いが難しいのだ (HTML::TreeBuilder)。文字参照というのは,「&」が頭についている文字のこと (文字参照 - Wikipedia)。日本語と文字参照を含む文書を処理する場合の手順についてまとめる。 参考サイト 日本語処理 Encodeモジュールを使って、HTMLテキストを事前にdecodeメソッドで内部表現(UTFフラグありのUTF-8)に変更、処理後にencodeメソッドで元の文字コードに戻すとよいようです。 Perlメモ/HTML::TreeBuilderモジュール - Walrus, Digit. 日本語処理の基本はこれで。 文字参照処理 $tree->
2009年06月08日14:30 カテゴリLightweight Languages perl - use encoding; #は黒歴史 ぎゃあぁぁ length関数で文字列の長さを求める - perl初心者BLOG - Hatena::Group::Perl 日本語の文字数を正確に求めたい場合、use encodingを指定する use encoding;は、jperlなど、かつて存在したL10Nされたperl用に書かれたレガシースクリプトを、モダンperlで動かすときのためのおまじないです。こういう目的で利用すべきではありません。 このあたりのことは、以前 404 Blog Not Found:perl - no encoding; # whenever possible でも書いたのですが、大事なことなのでまた書きます。 スクリプトはUTF-8で書き、use utf8;する のがモ
2008年04月09日01:00 カテゴリLightweight Languages perl - Encode 入門 すでにOSCONでもYAPCでも、あちこちそちこちでこの基本方針に関しては話したのですが、ここ 404 Blog Not Found でも改めて。 Perl で utf8 化けしたときにどうしたらいいか - TokuLog 改め だまってコードを書けよハゲ 入り口で decode して、内部ではすべて flagged utf8 で扱い、出口で encode する。これがすべてです!とにかくこの基本方針をまもっていれば幸せになれます。ここでは、EUC-JPでエンコードされたファイル中の「小飼弾」「こがいだん」「コガイダン」「Kogai Dan」を正規表現で書き換えて標準出力にEUC-JPで出力するプログラムを例にとって説明します。 decode() then encode(
起源 円記号問題の始まりは1960年代にまで遡ります。1967 年に文字コード最初の国際規格である ISO R 646 が制定されましたが、その規格では 0x5C をはじめとして一部の文字が置き換え可能になっていました。アメリカの制定した ASCII では 0x5C に対して REVERSE SOLIDUS を割り当てました。一方、日本版である JIS X 0201 では YEN SIGN を割り当てました。 問題の拡大 7bit では扱いきれない文字を扱うため、世界で ISO 646 系のコードを拡張した文字コードが生まれました。日本ではシフトJIS、日本語 EUC、いわゆる JIS コードの三種類の文字コードが現れ、それぞれに多くの亜種が生まれました。では、それぞれの文字コードの 7bit 領域は ASCII と JIS X 0201 のどちらだったのでしょうか。 日本語 EUC 日本
2009年09月13日13:00 カテゴリLightweight Languages #perl - utf8::decode()ではなくEncode::decode_utf8()を使うべき理由 駄目です。 [を] Perl の utf8 まわりのおまじない 最近良く使うおまじない、というかイディオム。 utf8::decode($text) unless utf8::is_utf8($text); こういう場合は、Encode::decode_utf8()でないと。 以下をごらんください。 #!/usr/bin/perl use strict; use warnings; use Encode; use Devel::Peek; for my $bytes ( "\x2F", "\xC0\xAF", "\xE0\x80\xAF", "\xF0\x80\x80\xAF" ) { my $u
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く