ray 0.0.1 → 0.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. data/.gemtest +0 -0
  2. data/.yardopts +4 -0
  3. data/README.md +17 -21
  4. data/Rakefile +18 -139
  5. data/VERSION +1 -1
  6. data/ext/audio.cpp +723 -0
  7. data/ext/{color.c → color.cpp} +25 -13
  8. data/ext/drawable.cpp +91 -0
  9. data/ext/event.cpp +460 -0
  10. data/ext/extconf.rb +5 -104
  11. data/ext/font.cpp +190 -0
  12. data/ext/image.cpp +733 -0
  13. data/ext/input.cpp +74 -0
  14. data/ext/ray.cpp +168 -0
  15. data/ext/ray.hpp +356 -0
  16. data/ext/{rect.c → rect.cpp} +51 -37
  17. data/ext/shader.cpp +169 -0
  18. data/ext/shape.cpp +409 -0
  19. data/ext/sprite.cpp +306 -0
  20. data/ext/text.cpp +181 -0
  21. data/ext/vector.cpp +215 -0
  22. data/guide.md +619 -0
  23. data/lib/ray/audio.rb +0 -41
  24. data/lib/ray/color.rb +32 -10
  25. data/lib/ray/drawable.rb +16 -0
  26. data/lib/ray/dsl/event_listener.rb +25 -2
  27. data/lib/ray/dsl/event_runner.rb +33 -5
  28. data/lib/ray/dsl/event_translator.rb +66 -30
  29. data/lib/ray/dsl/handler.rb +3 -2
  30. data/lib/ray/dsl/matcher.rb +58 -14
  31. data/lib/ray/font.rb +38 -96
  32. data/lib/ray/font_set.rb +8 -8
  33. data/lib/ray/game.rb +87 -66
  34. data/lib/ray/helper.rb +105 -10
  35. data/lib/ray/image.rb +150 -24
  36. data/lib/ray/image_set.rb +3 -1
  37. data/lib/ray/input.rb +10 -0
  38. data/lib/ray/music_set.rb +5 -3
  39. data/lib/ray/ray.rb +21 -9
  40. data/lib/ray/rect.rb +48 -7
  41. data/lib/ray/rmagick.rb +41 -0
  42. data/lib/ray/scene.rb +99 -43
  43. data/lib/ray/scene_list.rb +67 -0
  44. data/lib/ray/shape.rb +132 -0
  45. data/lib/ray/sound_set.rb +4 -2
  46. data/lib/ray/sprite.rb +49 -111
  47. data/lib/ray/text.rb +101 -0
  48. data/lib/ray/text_helper.rb +37 -0
  49. data/lib/ray/turtle.rb +215 -0
  50. data/lib/ray/vector.rb +226 -0
  51. data/samples/audio/spacial.rb +44 -0
  52. data/samples/hello_world/hello.rb +9 -13
  53. data/samples/hello_world/hello_dsl.rb +8 -12
  54. data/samples/hello_world/text.rb +15 -0
  55. data/samples/opengl/binding.rb +38 -0
  56. data/samples/opengl/image.rb +32 -0
  57. data/samples/opengl/opengl.rb +34 -0
  58. data/samples/opengl/shader.rb +42 -0
  59. data/samples/pong/pong.rb +14 -10
  60. data/samples/run_scene.rb +53 -0
  61. data/samples/shaders/scene.rb +40 -0
  62. data/samples/shaders/shaders.rb +42 -0
  63. data/samples/shaders/shape.rb +34 -0
  64. data/samples/sokoban/sokoban.rb +18 -18
  65. data/samples/test/actual_scene.rb +41 -0
  66. data/samples/test/scene_riot.rb +39 -0
  67. data/samples/test/scene_spec.rb +32 -0
  68. data/samples/test/scene_test_unit.rb +25 -0
  69. data/samples/turtle/byzantium.rb +45 -0
  70. data/samples/turtle/hilbert.rb +48 -0
  71. data/samples/turtle/koch.rb +55 -0
  72. data/samples/turtle/mandala.rb +61 -0
  73. data/samples/turtle/tree.rb +57 -0
  74. data/test/audio_test.rb +69 -0
  75. data/test/color_test.rb +77 -0
  76. data/test/drawable_test.rb +19 -0
  77. data/test/dsl_test.rb +93 -0
  78. data/test/font_test.rb +57 -0
  79. data/test/helpers.rb +94 -0
  80. data/test/image_test.rb +82 -0
  81. data/test/ray_test.rb +25 -0
  82. data/test/rect_test.rb +121 -0
  83. data/{spec → test}/res/VeraMono.ttf +0 -0
  84. data/{spec → test}/res/aqua.bmp +0 -0
  85. data/{spec → test}/res/aqua.png +0 -0
  86. data/{spec → test}/res/aqua2.bmp +0 -0
  87. data/{spec → test}/res/not_a_jpeg.jpeg +0 -0
  88. data/{spec → test}/res/pop.wav +0 -0
  89. data/test/resource_set_test.rb +99 -0
  90. data/test/run_all.rb +7 -0
  91. data/test/shape_test.rb +101 -0
  92. data/test/sprite_test.rb +89 -0
  93. data/test/text_test.rb +78 -0
  94. data/test/turtle_test.rb +176 -0
  95. data/test/vector_test.rb +111 -0
  96. data/yard_ext.rb +0 -28
  97. metadata +95 -139
  98. data/.gitignore +0 -23
  99. data/.gitmodules +0 -3
  100. data/.rspec +0 -3
  101. data/ext/audio.c +0 -473
  102. data/ext/event.c +0 -557
  103. data/ext/font.c +0 -287
  104. data/ext/image.c +0 -933
  105. data/ext/joystick.c +0 -145
  106. data/ext/ray.c +0 -489
  107. data/ext/ray.h +0 -245
  108. data/ext/ray_osx.m +0 -161
  109. data/lib/ray/joystick.rb +0 -30
  110. data/psp/SDL_psp_main.c +0 -84
  111. data/psp/bigdecimal/README +0 -60
  112. data/psp/bigdecimal/bigdecimal.c +0 -4697
  113. data/psp/bigdecimal/bigdecimal.h +0 -216
  114. data/psp/bigdecimal/lib/bigdecimal/jacobian.rb +0 -85
  115. data/psp/bigdecimal/lib/bigdecimal/ludcmp.rb +0 -84
  116. data/psp/bigdecimal/lib/bigdecimal/math.rb +0 -235
  117. data/psp/bigdecimal/lib/bigdecimal/newton.rb +0 -77
  118. data/psp/bigdecimal/lib/bigdecimal/util.rb +0 -65
  119. data/psp/digest/bubblebabble/bubblebabble.c +0 -142
  120. data/psp/digest/defs.h +0 -20
  121. data/psp/digest/digest.c +0 -643
  122. data/psp/digest/digest.h +0 -32
  123. data/psp/digest/lib/digest.rb +0 -50
  124. data/psp/digest/lib/md5.rb +0 -27
  125. data/psp/digest/lib/sha1.rb +0 -27
  126. data/psp/digest/md5/md5.c +0 -420
  127. data/psp/digest/md5/md5.h +0 -80
  128. data/psp/digest/md5/md5init.c +0 -40
  129. data/psp/digest/rmd160/rmd160.c +0 -457
  130. data/psp/digest/rmd160/rmd160.h +0 -56
  131. data/psp/digest/rmd160/rmd160init.c +0 -40
  132. data/psp/digest/sha1/sha1.c +0 -269
  133. data/psp/digest/sha1/sha1.h +0 -39
  134. data/psp/digest/sha1/sha1init.c +0 -40
  135. data/psp/digest/sha2/lib/sha2.rb +0 -73
  136. data/psp/digest/sha2/sha2.c +0 -919
  137. data/psp/digest/sha2/sha2.h +0 -109
  138. data/psp/digest/sha2/sha2init.c +0 -52
  139. data/psp/enumerator/enumerator.c +0 -298
  140. data/psp/etc/etc.c +0 -559
  141. data/psp/ext.c +0 -289
  142. data/psp/fcntl/fcntl.c +0 -187
  143. data/psp/lib/rbconfig.rb +0 -178
  144. data/psp/nkf/lib/kconv.rb +0 -367
  145. data/psp/nkf/nkf-utf8/config.h +0 -88
  146. data/psp/nkf/nkf-utf8/nkf.c +0 -6040
  147. data/psp/nkf/nkf-utf8/utf8tbl.c +0 -8500
  148. data/psp/nkf/nkf-utf8/utf8tbl.h +0 -34
  149. data/psp/nkf/nkf.c +0 -654
  150. data/psp/socket/addrinfo.h +0 -173
  151. data/psp/socket/getaddrinfo.c +0 -676
  152. data/psp/socket/getnameinfo.c +0 -270
  153. data/psp/socket/pspsocket.c +0 -71
  154. data/psp/socket/pspsocket.h +0 -28
  155. data/psp/socket/socket.c +0 -4662
  156. data/psp/socket/sockport.h +0 -76
  157. data/psp/stringio/stringio.c +0 -1306
  158. data/psp/strscan/strscan.c +0 -1320
  159. data/psp/syck/bytecode.c +0 -1166
  160. data/psp/syck/emitter.c +0 -1242
  161. data/psp/syck/gram.c +0 -1894
  162. data/psp/syck/gram.h +0 -79
  163. data/psp/syck/handler.c +0 -174
  164. data/psp/syck/implicit.c +0 -2990
  165. data/psp/syck/node.c +0 -408
  166. data/psp/syck/rubyext.c +0 -2367
  167. data/psp/syck/syck.c +0 -504
  168. data/psp/syck/syck.h +0 -456
  169. data/psp/syck/token.c +0 -2725
  170. data/psp/syck/yaml2byte.c +0 -257
  171. data/psp/syck/yamlbyte.h +0 -170
  172. data/psp/thread/thread.c +0 -1175
  173. data/psp/zlib/zlib.c +0 -3547
  174. data/script.rb +0 -10
  175. data/spec/ray/audio_spec.rb +0 -146
  176. data/spec/ray/color_spec.rb +0 -57
  177. data/spec/ray/event_spec.rb +0 -80
  178. data/spec/ray/font_spec.rb +0 -93
  179. data/spec/ray/image_set_spec.rb +0 -48
  180. data/spec/ray/image_spec.rb +0 -162
  181. data/spec/ray/joystick_spec.rb +0 -21
  182. data/spec/ray/matcher_spec.rb +0 -50
  183. data/spec/ray/ray_spec.rb +0 -88
  184. data/spec/ray/rect_spec.rb +0 -154
  185. data/spec/ray/resource_set_spec.rb +0 -105
  186. data/spec/ray/sprite_spec.rb +0 -163
  187. data/spec/spec.opts +0 -4
  188. data/spec/spec_helper.rb +0 -8
@@ -1,178 +0,0 @@
1
-
2
- # This file was created by mkconfig.rb when ruby was built. Any
3
- # changes made to this file will be lost the next time ruby is built.
4
-
5
- module Config
6
- RUBY_VERSION == "1.8.6" or
7
- raise "ruby lib version (1.8.6) doesn't match executable version (#{RUBY_VERSION})"
8
-
9
- TOPDIR = File.dirname(__FILE__).chomp!("/lib/ruby/1.8/mipsallegrexel-elf")
10
- DESTDIR = '' unless defined? DESTDIR
11
- CONFIG = {}
12
- CONFIG["DESTDIR"] = DESTDIR
13
- CONFIG["INSTALL"] = '/bin/install -c'
14
- CONFIG["prefix"] = ""
15
- CONFIG["EXEEXT"] = ""
16
- CONFIG["ruby_install_name"] = "ruby"
17
- CONFIG["RUBY_INSTALL_NAME"] = "ruby"
18
- CONFIG["RUBY_SO_NAME"] = "ruby"
19
- CONFIG["SHELL"] = "/bin/sh"
20
- CONFIG["PATH_SEPARATOR"] = ":"
21
- CONFIG["PACKAGE_NAME"] = ""
22
- CONFIG["PACKAGE_TARNAME"] = ""
23
- CONFIG["PACKAGE_VERSION"] = ""
24
- CONFIG["PACKAGE_STRING"] = ""
25
- CONFIG["PACKAGE_BUGREPORT"] = ""
26
- CONFIG["exec_prefix"] = "$(prefix)"
27
- CONFIG["bindir"] = "/ruby/bin"
28
- CONFIG["sbindir"] = "/ruby/sbin"
29
- CONFIG["libexecdir"] = "$(exec_prefix)/libexec"
30
- CONFIG["datarootdir"] = "$(prefix)/share"
31
- CONFIG["datadir"] = "$(datarootdir)"
32
- CONFIG["sysconfdir"] = "/ruby/etc"
33
- CONFIG["sharedstatedir"] = "/ruby/com"
34
- CONFIG["localstatedir"] = "/ruby/var"
35
- CONFIG["includedir"] = "/ruby/include"
36
- CONFIG["oldincludedir"] = "/usr/include"
37
- CONFIG["docdir"] = "$(datarootdir)/doc/$(PACKAGE)"
38
- CONFIG["infodir"] = "$(datarootdir)/info"
39
- CONFIG["htmldir"] = "$(docdir)"
40
- CONFIG["dvidir"] = "$(docdir)"
41
- CONFIG["pdfdir"] = "$(docdir)"
42
- CONFIG["psdir"] = "$(docdir)"
43
- CONFIG["libdir"] = ""
44
- CONFIG["localedir"] = "$(datarootdir)/locale"
45
- CONFIG["mandir"] = "$(datarootdir)/man"
46
- CONFIG["ECHO_C"] = ""
47
- CONFIG["ECHO_N"] = "-n"
48
- CONFIG["ECHO_T"] = ""
49
- CONFIG["LIBS"] = "-lm -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel"
50
- CONFIG["build_alias"] = ""
51
- CONFIG["host_alias"] = "psp"
52
- CONFIG["target_alias"] = ""
53
- CONFIG["MAJOR"] = "1"
54
- CONFIG["MINOR"] = "8"
55
- CONFIG["TEENY"] = "6"
56
- CONFIG["build"] = "i686-pc-linux-gnulibc1"
57
- CONFIG["build_cpu"] = "i686"
58
- CONFIG["build_vendor"] = "pc"
59
- CONFIG["build_os"] = "linux-gnulibc1"
60
- CONFIG["host"] = "mipsallegrexel-psp-elf"
61
- CONFIG["host_cpu"] = "mipsallegrexel"
62
- CONFIG["host_vendor"] = "psp"
63
- CONFIG["host_os"] = "elf"
64
- CONFIG["target"] = "mipsallegrexel-psp-elf"
65
- CONFIG["target_cpu"] = "mipsallegrexel"
66
- CONFIG["target_vendor"] = "psp"
67
- CONFIG["target_os"] = "elf"
68
- CONFIG["CC"] = "psp-gcc"
69
- CONFIG["CFLAGS"] = "-I. -I/opt/pspdev/psp/sdk/include -O2 -G0 -D_PSP_FW_VERSION=150 -D_PSP_=1 "
70
- CONFIG["LDFLAGS"] = "-L. -L/opt/pspdev/psp/sdk/lib"
71
- CONFIG["CPPFLAGS"] = ""
72
- CONFIG["OBJEXT"] = "o"
73
- CONFIG["CPP"] = "psp-gcc -E"
74
- CONFIG["GREP"] = "/bin/grep"
75
- CONFIG["EGREP"] = "/bin/grep -E"
76
- CONFIG["GNU_LD"] = "yes"
77
- CONFIG["CPPOUTFILE"] = "-o conftest.i"
78
- CONFIG["OUTFLAG"] = "-o "
79
- CONFIG["YACC"] = "bison -y"
80
- CONFIG["YFLAGS"] = ""
81
- CONFIG["RANLIB"] = "psp-ranlib"
82
- CONFIG["AR"] = "psp-ar"
83
- CONFIG["AS"] = "psp-as"
84
- CONFIG["ASFLAGS"] = ""
85
- CONFIG["NM"] = ""
86
- CONFIG["WINDRES"] = ""
87
- CONFIG["DLLWRAP"] = ""
88
- CONFIG["OBJDUMP"] = ""
89
- CONFIG["LN_S"] = "ln -s"
90
- CONFIG["SET_MAKE"] = ""
91
- CONFIG["INSTALL_PROGRAM"] = "$(INSTALL)"
92
- CONFIG["INSTALL_SCRIPT"] = "$(INSTALL)"
93
- CONFIG["INSTALL_DATA"] = "$(INSTALL) -m 644"
94
- CONFIG["RM"] = "rm -f"
95
- CONFIG["CP"] = "cp"
96
- CONFIG["MAKEDIRS"] = "mkdir -p"
97
- CONFIG["ALLOCA"] = ""
98
- CONFIG["DLDFLAGS"] = ""
99
- CONFIG["ARCH_FLAG"] = ""
100
- CONFIG["STATIC"] = ""
101
- CONFIG["CCDLFLAGS"] = " -fPIC"
102
- CONFIG["LDSHARED"] = "ld"
103
- CONFIG["DLEXT"] = "so"
104
- CONFIG["DLEXT2"] = ""
105
- CONFIG["LIBEXT"] = "a"
106
- CONFIG["LINK_SO"] = ""
107
- CONFIG["LIBPATHFLAG"] = " -L'%1$-s'"
108
- CONFIG["RPATHFLAG"] = " -Wl,-R'%1$-s'"
109
- CONFIG["LIBPATHENV"] = "LD_LIBRARY_PATH"
110
- CONFIG["TRY_LINK"] = ""
111
- CONFIG["STRIP"] = "strip"
112
- CONFIG["EXTSTATIC"] = ""
113
- CONFIG["setup"] = "Setup"
114
- CONFIG["MINIRUBY"] = "ruby -I/home/kilian/PSP/ruby/ruby-1.8.6 -rfake"
115
- CONFIG["PREP"] = "fake.rb"
116
- CONFIG["RUNRUBY"] = "$(MINIRUBY) -I`cd $(srcdir)/lib; pwd`"
117
- CONFIG["EXTOUT"] = ".ext"
118
- CONFIG["ARCHFILE"] = ""
119
- CONFIG["RDOCTARGET"] = ""
120
- CONFIG["XCFLAGS"] = " -DRUBY_EXPORT"
121
- CONFIG["XLDFLAGS"] = " -L."
122
- CONFIG["LIBRUBY_LDSHARED"] = "ld"
123
- CONFIG["LIBRUBY_DLDFLAGS"] = ""
124
- CONFIG["rubyw_install_name"] = ""
125
- CONFIG["RUBYW_INSTALL_NAME"] = ""
126
- CONFIG["LIBRUBY_A"] = "lib$(RUBY_SO_NAME)-static.a"
127
- CONFIG["LIBRUBY_SO"] = "lib$(RUBY_SO_NAME).so.$(MAJOR).$(MINOR).$(TEENY)"
128
- CONFIG["LIBRUBY_ALIASES"] = "lib$(RUBY_SO_NAME).so"
129
- CONFIG["LIBRUBY"] = "$(LIBRUBY_A)"
130
- CONFIG["LIBRUBYARG"] = "$(LIBRUBYARG_STATIC)"
131
- CONFIG["LIBRUBYARG_STATIC"] = "-l$(RUBY_SO_NAME)-static"
132
- CONFIG["LIBRUBYARG_SHARED"] = "-Wl,-R -Wl,$(libdir) -L$(libdir) -L. "
133
- CONFIG["SOLIBS"] = ""
134
- CONFIG["DLDLIBS"] = " -lc"
135
- CONFIG["ENABLE_SHARED"] = "no"
136
- CONFIG["MAINLIBS"] = ""
137
- CONFIG["COMMON_LIBS"] = ""
138
- CONFIG["COMMON_MACROS"] = ""
139
- CONFIG["COMMON_HEADERS"] = ""
140
- CONFIG["EXPORT_PREFIX"] = ""
141
- CONFIG["MAKEFILES"] = "Makefile"
142
- CONFIG["arch"] = "mipsallegrexel-elf"
143
- CONFIG["sitearch"] = "mipsallegrexel-elf"
144
- CONFIG["sitedir"] = "/ruby/site_ruby"
145
- CONFIG["configure_args"] = " 'CC=psp-gcc' 'CFLAGS=-I. -I/opt/pspdev/psp/sdk/include -O2 -G0 -D_PSP_FW_VERSION=150 -D_PSP_=1 ' 'LDFLAGS=-L. -L/opt/pspdev/psp/sdk/lib' 'LIBS=-lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel' '--host=psp' '--config-cache' 'host_alias=psp'"
146
- CONFIG["NROFF"] = "/usr/bin/nroff"
147
- CONFIG["MANTYPE"] = "doc"
148
- CONFIG["ruby_version"] = "$(MAJOR).$(MINOR)"
149
- CONFIG["rubylibdir"] = "/ruby/$(ruby_version)"
150
- CONFIG["archdir"] = "$(rubylibdir)/$(arch)"
151
- CONFIG["sitelibdir"] = "$(sitedir)/$(ruby_version)"
152
- CONFIG["sitearchdir"] = "$(sitelibdir)/$(sitearch)"
153
- CONFIG["topdir"] = File.dirname(__FILE__)
154
- MAKEFILE_CONFIG = {}
155
- CONFIG.each{|k,v| MAKEFILE_CONFIG[k] = v.dup}
156
- def Config::expand(val, config = CONFIG)
157
- val.gsub!(/\$\$|\$\(([^()]+)\)|\$\{([^{}]+)\}/) do |var|
158
- if !(v = $1 || $2)
159
- '$'
160
- elsif key = config[v = v[/\A[^:]+(?=(?::(.*?)=(.*))?\z)/]]
161
- pat, sub = $1, $2
162
- config[v] = false
163
- Config::expand(key, config)
164
- config[v] = key
165
- key = key.gsub(/#{Regexp.quote(pat)}(?=\s|\z)/n) {sub} if pat
166
- key
167
- else
168
- var
169
- end
170
- end
171
- val
172
- end
173
- CONFIG.each_value do |val|
174
- Config::expand(val)
175
- end
176
- end
177
- RbConfig = Config # compatibility for ruby-1.9
178
- CROSS_COMPILING = nil unless defined? CROSS_COMPILING
@@ -1,367 +0,0 @@
1
- #
2
- # kconv.rb - Kanji Converter.
3
- #
4
- # $Id: kconv.rb 11708 2007-02-12 23:01:19Z shyouhei $
5
- #
6
- # ----
7
- #
8
- # kconv.rb implements the Kconv class for Kanji Converter. Additionally,
9
- # some methods in String classes are added to allow easy conversion.
10
- #
11
-
12
- require 'nkf'
13
-
14
- #
15
- # Kanji Converter for Ruby.
16
- #
17
- module Kconv
18
- #
19
- # Public Constants
20
- #
21
-
22
- #Constant of Encoding
23
-
24
- # Auto-Detect
25
- AUTO = NKF::AUTO
26
- # ISO-2022-JP
27
- JIS = NKF::JIS
28
- # EUC-JP
29
- EUC = NKF::EUC
30
- # Shift_JIS
31
- SJIS = NKF::SJIS
32
- # BINARY
33
- BINARY = NKF::BINARY
34
- # NOCONV
35
- NOCONV = NKF::NOCONV
36
- # ASCII
37
- ASCII = NKF::ASCII
38
- # UTF-8
39
- UTF8 = NKF::UTF8
40
- # UTF-16
41
- UTF16 = NKF::UTF16
42
- # UTF-32
43
- UTF32 = NKF::UTF32
44
- # UNKNOWN
45
- UNKNOWN = NKF::UNKNOWN
46
-
47
- #
48
- # Private Constants
49
- #
50
-
51
- # Revision of kconv.rb
52
- REVISION = %q$Revision: 11708 $
53
-
54
- #Regexp of Encoding
55
-
56
- # Regexp of Shift_JIS string (private constant)
57
- RegexpShiftjis = /\A(?:
58
- [\x00-\x7f\xa1-\xdf] |
59
- [\x81-\x9f\xe0-\xfc][\x40-\x7e\x80-\xfc]
60
- )*\z/nx
61
-
62
- # Regexp of EUC-JP string (private constant)
63
- RegexpEucjp = /\A(?:
64
- [\x00-\x7f] |
65
- \x8e [\xa1-\xdf] |
66
- \x8f [\xa1-\xfe] [\xa1-\xfe] |
67
- [\xa1-\xfe] [\xa1-\xfe]
68
- )*\z/nx
69
-
70
- # Regexp of UTF-8 string (private constant)
71
- RegexpUtf8 = /\A(?:
72
- [\x00-\x7f] |
73
- [\xc2-\xdf] [\x80-\xbf] |
74
- \xe0 [\xa0-\xbf] [\x80-\xbf] |
75
- [\xe1-\xef] [\x80-\xbf] [\x80-\xbf] |
76
- \xf0 [\x90-\xbf] [\x80-\xbf] [\x80-\xbf] |
77
- [\xf1-\xf3] [\x80-\xbf] [\x80-\xbf] [\x80-\xbf] |
78
- \xf4 [\x80-\x8f] [\x80-\xbf] [\x80-\xbf]
79
- )*\z/nx
80
-
81
- #
82
- # Public Methods
83
- #
84
-
85
- # call-seq:
86
- # Kconv.kconv(str, out_code, in_code = Kconv::AUTO)
87
- #
88
- # Convert <code>str</code> to out_code.
89
- # <code>out_code</code> and <code>in_code</code> are given as constants of Kconv.
90
- #
91
- # *Note*
92
- # This method decode MIME encoded string and
93
- # convert halfwidth katakana to fullwidth katakana.
94
- # If you don't want to decode them, use NKF.nkf.
95
- def kconv(str, out_code, in_code = AUTO)
96
- opt = '-'
97
- case in_code
98
- when ::NKF::JIS
99
- opt << 'J'
100
- when ::NKF::EUC
101
- opt << 'E'
102
- when ::NKF::SJIS
103
- opt << 'S'
104
- when ::NKF::UTF8
105
- opt << 'W'
106
- when ::NKF::UTF16
107
- opt << 'W16'
108
- end
109
-
110
- case out_code
111
- when ::NKF::JIS
112
- opt << 'j'
113
- when ::NKF::EUC
114
- opt << 'e'
115
- when ::NKF::SJIS
116
- opt << 's'
117
- when ::NKF::UTF8
118
- opt << 'w'
119
- when ::NKF::UTF16
120
- opt << 'w16'
121
- when ::NKF::NOCONV
122
- return str
123
- end
124
-
125
- opt = '' if opt == '-'
126
-
127
- ::NKF::nkf(opt, str)
128
- end
129
- module_function :kconv
130
-
131
- #
132
- # Encode to
133
- #
134
-
135
- # call-seq:
136
- # Kconv.tojis(str) -> string
137
- #
138
- # Convert <code>str</code> to ISO-2022-JP
139
- #
140
- # *Note*
141
- # This method decode MIME encoded string and
142
- # convert halfwidth katakana to fullwidth katakana.
143
- # If you don't want it, use NKF.nkf('-jxm0', str).
144
- def tojis(str)
145
- ::NKF::nkf('-jm', str)
146
- end
147
- module_function :tojis
148
-
149
- # call-seq:
150
- # Kconv.toeuc(str) -> string
151
- #
152
- # Convert <code>str</code> to EUC-JP
153
- #
154
- # *Note*
155
- # This method decode MIME encoded string and
156
- # convert halfwidth katakana to fullwidth katakana.
157
- # If you don't want it, use NKF.nkf('-exm0', str).
158
- def toeuc(str)
159
- ::NKF::nkf('-em', str)
160
- end
161
- module_function :toeuc
162
-
163
- # call-seq:
164
- # Kconv.tosjis(str) -> string
165
- #
166
- # Convert <code>str</code> to Shift_JIS
167
- #
168
- # *Note*
169
- # This method decode MIME encoded string and
170
- # convert halfwidth katakana to fullwidth katakana.
171
- # If you don't want it, use NKF.nkf('-sxm0', str).
172
- def tosjis(str)
173
- ::NKF::nkf('-sm', str)
174
- end
175
- module_function :tosjis
176
-
177
- # call-seq:
178
- # Kconv.toutf8(str) -> string
179
- #
180
- # Convert <code>str</code> to UTF-8
181
- #
182
- # *Note*
183
- # This method decode MIME encoded string and
184
- # convert halfwidth katakana to fullwidth katakana.
185
- # If you don't want it, use NKF.nkf('-wxm0', str).
186
- def toutf8(str)
187
- ::NKF::nkf('-wm', str)
188
- end
189
- module_function :toutf8
190
-
191
- # call-seq:
192
- # Kconv.toutf16(str) -> string
193
- #
194
- # Convert <code>str</code> to UTF-16
195
- #
196
- # *Note*
197
- # This method decode MIME encoded string and
198
- # convert halfwidth katakana to fullwidth katakana.
199
- # If you don't want it, use NKF.nkf('-w16xm0', str).
200
- def toutf16(str)
201
- ::NKF::nkf('-w16m', str)
202
- end
203
- module_function :toutf16
204
-
205
- #
206
- # guess
207
- #
208
-
209
- # call-seq:
210
- # Kconv.guess(str) -> integer
211
- #
212
- # Guess input encoding by NKF.guess2
213
- def guess(str)
214
- ::NKF::guess(str)
215
- end
216
- module_function :guess
217
-
218
- # call-seq:
219
- # Kconv.guess_old(str) -> integer
220
- #
221
- # Guess input encoding by NKF.guess1
222
- def guess_old(str)
223
- ::NKF::guess1(str)
224
- end
225
- module_function :guess_old
226
-
227
- #
228
- # isEncoding
229
- #
230
-
231
- # call-seq:
232
- # Kconv.iseuc(str) -> obj or nil
233
- #
234
- # Returns whether input encoding is EUC-JP or not.
235
- #
236
- # *Note* don't expect this return value is MatchData.
237
- def iseuc(str)
238
- RegexpEucjp.match( str )
239
- end
240
- module_function :iseuc
241
-
242
- # call-seq:
243
- # Kconv.issjis(str) -> obj or nil
244
- #
245
- # Returns whether input encoding is Shift_JIS or not.
246
- #
247
- # *Note* don't expect this return value is MatchData.
248
- def issjis(str)
249
- RegexpShiftjis.match( str )
250
- end
251
- module_function :issjis
252
-
253
- # call-seq:
254
- # Kconv.isutf8(str) -> obj or nil
255
- #
256
- # Returns whether input encoding is UTF-8 or not.
257
- #
258
- # *Note* don't expect this return value is MatchData.
259
- def isutf8(str)
260
- RegexpUtf8.match( str )
261
- end
262
- module_function :isutf8
263
-
264
- end
265
-
266
- class String
267
- # call-seq:
268
- # String#kconv(out_code, in_code = Kconv::AUTO)
269
- #
270
- # Convert <code>self</code> to out_code.
271
- # <code>out_code</code> and <code>in_code</code> are given as constants of Kconv.
272
- #
273
- # *Note*
274
- # This method decode MIME encoded string and
275
- # convert halfwidth katakana to fullwidth katakana.
276
- # If you don't want to decode them, use NKF.nkf.
277
- def kconv(out_code, in_code=Kconv::AUTO)
278
- Kconv::kconv(self, out_code, in_code)
279
- end
280
-
281
- #
282
- # to Encoding
283
- #
284
-
285
- # call-seq:
286
- # String#tojis -> string
287
- #
288
- # Convert <code>self</code> to ISO-2022-JP
289
- #
290
- # *Note*
291
- # This method decode MIME encoded string and
292
- # convert halfwidth katakana to fullwidth katakana.
293
- # If you don't want it, use NKF.nkf('-jxm0', str).
294
- def tojis; Kconv.tojis(self) end
295
-
296
- # call-seq:
297
- # String#toeuc -> string
298
- #
299
- # Convert <code>self</code> to EUC-JP
300
- #
301
- # *Note*
302
- # This method decode MIME encoded string and
303
- # convert halfwidth katakana to fullwidth katakana.
304
- # If you don't want it, use NKF.nkf('-exm0', str).
305
- def toeuc; Kconv.toeuc(self) end
306
-
307
- # call-seq:
308
- # String#tosjis -> string
309
- #
310
- # Convert <code>self</code> to Shift_JIS
311
- #
312
- # *Note*
313
- # This method decode MIME encoded string and
314
- # convert halfwidth katakana to fullwidth katakana.
315
- # If you don't want it, use NKF.nkf('-sxm0', str).
316
- def tosjis; Kconv.tosjis(self) end
317
-
318
- # call-seq:
319
- # String#toutf8 -> string
320
- #
321
- # Convert <code>self</code> to UTF-8
322
- #
323
- # *Note*
324
- # This method decode MIME encoded string and
325
- # convert halfwidth katakana to fullwidth katakana.
326
- # If you don't want it, use NKF.nkf('-wxm0', str).
327
- def toutf8; Kconv.toutf8(self) end
328
-
329
- # call-seq:
330
- # String#toutf16 -> string
331
- #
332
- # Convert <code>self</code> to UTF-16
333
- #
334
- # *Note*
335
- # This method decode MIME encoded string and
336
- # convert halfwidth katakana to fullwidth katakana.
337
- # If you don't want it, use NKF.nkf('-w16xm0', str).
338
- def toutf16; Kconv.toutf16(self) end
339
-
340
- #
341
- # is Encoding
342
- #
343
-
344
- # call-seq:
345
- # String#iseuc -> obj or nil
346
- #
347
- # Returns whether <code>self</code>'s encoding is EUC-JP or not.
348
- #
349
- # *Note* don't expect this return value is MatchData.
350
- def iseuc; Kconv.iseuc(self) end
351
-
352
- # call-seq:
353
- # String#issjis -> obj or nil
354
- #
355
- # Returns whether <code>self</code>'s encoding is Shift_JIS or not.
356
- #
357
- # *Note* don't expect this return value is MatchData.
358
- def issjis; Kconv.issjis(self) end
359
-
360
- # call-seq:
361
- # String#isutf8 -> obj or nil
362
- #
363
- # Returns whether <code>self</code>'s encoding is UTF-8 or not.
364
- #
365
- # *Note* don't expect this return value is MatchData.
366
- def isutf8; Kconv.isutf8(self) end
367
- end