[#44310] プログラムに対して意図したとおりの文字列を渡す方法 — "Information Kanasansoft" <kanasansoft@...>

kanasanです。

9 messages 2007/12/05

[#44332] クラス:相互参照系の作成方法について質問です — "Saburoh Sakai" <sabroh@...>

はじめまして、さかいと申します。

12 messages 2007/12/11

[#44366] Rake改善プロジェクト — "Hajime Hoshi" <hajimehoshi@...>

東京大学修士 1 年の星一と申します。

14 messages 2007/12/19

[ruby-list:44326] Re: mork.rb

From: Nobuyoshi Nakada <nobu@...>
Date: 2007-12-07 08:16:50 UTC
List: ruby-list #44326
なかだです。

At Fri, 7 Dec 2007 11:54:34 +0900,
S_Konno(今野 滋) wrote in [ruby-list:44324]:
> 試してみたところ、日本語の処理に課題がありそうです。
> (ソースをもう少し深く読み込めば解決方法があるのかも知れませんが)
> 例えば、
> http://www.ruby-lang.org/ja/のページタイトル
>   オブジェクト指向スクリプト言語 Ruby
> 
> が、Firefoxの履歴ファイルの中に、
>   $AA0$D60$B80$A70$AF0$C80$07c$11T$B90$AF0$EA0$D70$C80$00$8A$9E$8A $00R$00u$00b$00y$00
> 
> と、書かれてあります。これを、mork.rb は、
>   A0D0B0A0A0C00c1TB0A0E0D0C0898 Ruby
> 
> というフレーズで返してきます。

UTF-16LEを$+hex二桁でエスケープしたもののようですね。常にLEなの
か、プラットフォームによるのかはわかりませんが。


--- mork.rb@rev=2786	2007-12-07 17:00:52.000000000 +0900
+++ mork.rb	2007-12-07 17:12:28.487000000 +0900
@@ -12,4 +12,13 @@ require "strscan"
 
 class Mork
+	ProfileDir = case RUBY_PLATFORM
+	             when /darwin/
+	               "~/Library/Application Support/Firefox/Profiles"
+	             when /win/
+	               "~/Application Data/Mozilla/Firefox/Profiles"
+	             when
+	               "~/.mozilla/firefox"
+	             end
+
 	RE = {
 		:comment => %r|//.*\n|,
@@ -72,9 +81,6 @@ class Mork
 			end
 
-			if val.include?("$")
-				val.gsub!(/\$00/, "")
-				val.gsub!(/\$([\dA-F]{2})/) do |m|
-					m[1].chr
-				end
+			if val.gsub!(/\$([\dA-F]{2})/) {$1.hex.chr}
+				val = val.unpack("S*").pack("U*")
 			end
 
@@ -179,5 +185,5 @@ if $0 == __FILE__
 	require "pp"
 	require "pathname"
-	histfiles = Pathname.glob("#{ENV["HOME"]}/Library/Application Support/Firefox/Profiles/*/history.dat")
+	histfiles = Pathname.glob(File.expand_path("*/history.dat", Mork::ProfileDir))
 	puts histfiles
 


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

In This Thread