Develop and Download Open Source Software

Browse Subversion Repository

Contents of /script/sjisText2header.rb

Parent Directory Parent Directory | Revision Log Revision Log


Revision 282 - (show annotations) (download)
Sat Mar 15 23:57:17 2008 UTC (16 years ago) by satofumi
File size: 849 byte(s)
adjust ruby scripts, and input event
1 #!/usr/bin/env ruby
2
3 # Shift-JIS の文字列を C言語の Unicode 資源に変換
4 # Satofumi KAMIMURA
5 # $Id$
6
7 require 'kconv'
8 require 'jcode'
9 $KCODE = 'SJIS'
10
11
12 def textToArray(text)
13 str = "{ ";
14 text.each_char { |ch|
15 if ch.mbchar?
16 str += '0x'
17 str += ('0' + Kconv.kconv(ch, Kconv::UTF16)[0].to_s(16))[-2, 2]
18 str += ('0' + Kconv.kconv(ch, Kconv::UTF16)[1].to_s(16))[-2, 2]
19 else
20 str += '\'' + ch + '\''
21 end
22 str += ', '
23 }
24 str += "0x0 }"
25 return str
26 end
27
28
29 if ARGV.length() != 1
30 exit(1)
31 end
32
33 open (ARGV[0]) { |io|
34 while line = io.gets
35
36 if /(\")(.*)(\")/ =~ line
37 match = $&
38 text = $2
39
40 # 文字列を変換して Unicode の配列データを作る
41 converted_text = textToArray(text);
42 line.chomp!
43 line = line.gsub!(match, converted_text) + ' // ' + text + "\n"
44 end
45 print line
46 end
47 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26