rbs 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +5 -0
- data/CHANGELOG.md +23 -0
- data/README.md +6 -1
- data/core/array.rbs +2866 -1086
- data/core/basic_object.rbs +150 -30
- data/core/binding.rbs +33 -0
- data/core/builtin.rbs +4 -4
- data/core/class.rbs +43 -5
- data/core/comparable.rbs +57 -0
- data/core/complex.rbs +170 -4
- data/core/constants.rbs +51 -0
- data/core/deprecated.rbs +7 -0
- data/core/dir.rbs +305 -20
- data/core/encoding.rbs +472 -77
- data/core/enumerable.rbs +2173 -234
- data/core/enumerator.rbs +448 -182
- data/core/env.rbs +448 -1
- data/core/errno.rbs +1 -10
- data/core/errors.rbs +152 -2
- data/core/exception.rbs +201 -127
- data/core/false_class.rbs +27 -0
- data/core/fiber.rbs +118 -37
- data/core/fiber_error.rbs +8 -9
- data/core/file.rbs +1059 -139
- data/core/file_test.rbs +287 -32
- data/core/float.rbs +776 -300
- data/core/gc.rbs +185 -34
- data/core/global_variables.rbs +5 -1
- data/core/hash.rbs +1582 -649
- data/core/integer.rbs +974 -204
- data/core/io/buffer.rbs +710 -0
- data/core/io/wait.rbs +29 -8
- data/core/io.rbs +2438 -417
- data/core/kernel.rbs +2315 -316
- data/core/marshal.rbs +37 -2
- data/core/match_data.rbs +123 -6
- data/core/math.rbs +126 -6
- data/core/method.rbs +226 -102
- data/core/module.rbs +421 -45
- data/core/nil_class.rbs +64 -0
- data/core/numeric.rbs +620 -142
- data/core/object.rbs +453 -81
- data/core/object_space.rbs +92 -2
- data/core/proc.rbs +482 -285
- data/core/process.rbs +443 -34
- data/core/ractor.rbs +232 -9
- data/core/random.rbs +151 -52
- data/core/range.rbs +885 -160
- data/core/rational.rbs +122 -6
- data/core/rb_config.rbs +14 -4
- data/core/refinement.rbs +44 -0
- data/core/regexp.rbs +156 -14
- data/core/ruby_vm.rbs +42 -3
- data/core/signal.rbs +78 -39
- data/core/string.rbs +2123 -567
- data/core/string_io.rbs +204 -0
- data/core/struct.rbs +283 -28
- data/core/symbol.rbs +304 -30
- data/core/thread.rbs +1288 -688
- data/core/thread_group.rbs +66 -10
- data/core/time.rbs +643 -217
- data/core/trace_point.rbs +100 -12
- data/core/true_class.rbs +24 -0
- data/core/unbound_method.rbs +73 -7
- data/core/warning.rbs +37 -12
- data/docs/CONTRIBUTING.md +40 -34
- data/docs/stdlib.md +3 -102
- data/lib/rbs/annotate/annotations.rb +197 -0
- data/lib/rbs/annotate/formatter.rb +80 -0
- data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
- data/lib/rbs/annotate/rdoc_source.rb +120 -0
- data/lib/rbs/annotate.rb +6 -0
- data/lib/rbs/cli.rb +45 -1
- data/lib/rbs/definition_builder.rb +5 -1
- data/lib/rbs/location_aux.rb +12 -0
- data/lib/rbs/prototype/rb.rb +12 -0
- data/lib/rbs/version.rb +1 -1
- data/sig/annotate/annotations.rbs +102 -0
- data/sig/annotate/formatter.rbs +24 -0
- data/sig/annotate/rdoc_annotater.rbs +82 -0
- data/sig/annotate/rdoc_source.rbs +30 -0
- data/sig/cli.rbs +2 -0
- data/sig/collection/{collections.rbs → sources.rbs} +0 -0
- data/sig/location.rbs +6 -0
- data/sig/method_types.rbs +5 -1
- data/sig/polyfill.rbs +78 -0
- data/stdlib/abbrev/0/abbrev.rbs +6 -0
- data/stdlib/abbrev/0/array.rbs +26 -0
- data/stdlib/base64/0/base64.rbs +31 -0
- data/stdlib/benchmark/0/benchmark.rbs +74 -3
- data/stdlib/bigdecimal/0/big_decimal.rbs +614 -165
- data/stdlib/bigdecimal-math/0/big_math.rbs +41 -64
- data/stdlib/cgi/0/core.rbs +59 -0
- data/stdlib/coverage/0/coverage.rbs +164 -2
- data/stdlib/csv/0/csv.rbs +2862 -398
- data/stdlib/date/0/date.rbs +483 -25
- data/stdlib/date/0/date_time.rbs +187 -12
- data/stdlib/dbm/0/dbm.rbs +152 -17
- data/stdlib/digest/0/digest.rbs +146 -0
- data/stdlib/erb/0/erb.rbs +65 -245
- data/stdlib/fiber/0/fiber.rbs +73 -91
- data/stdlib/fileutils/0/fileutils.rbs +301 -1
- data/stdlib/find/0/find.rbs +9 -0
- data/stdlib/forwardable/0/forwardable.rbs +65 -1
- data/stdlib/io-console/0/io-console.rbs +227 -15
- data/stdlib/ipaddr/0/ipaddr.rbs +161 -0
- data/stdlib/json/0/json.rbs +1146 -144
- data/stdlib/logger/0/formatter.rbs +24 -0
- data/stdlib/logger/0/log_device.rbs +64 -0
- data/stdlib/logger/0/logger.rbs +165 -13
- data/stdlib/logger/0/period.rbs +10 -0
- data/stdlib/logger/0/severity.rbs +26 -0
- data/stdlib/monitor/0/monitor.rbs +163 -0
- data/stdlib/mutex_m/0/mutex_m.rbs +35 -6
- data/stdlib/net-http/0/net-http.rbs +1492 -683
- data/stdlib/nkf/0/nkf.rbs +372 -0
- data/stdlib/objspace/0/objspace.rbs +149 -90
- data/stdlib/openssl/0/openssl.rbs +8108 -71
- data/stdlib/optparse/0/optparse.rbs +487 -19
- data/stdlib/pathname/0/pathname.rbs +425 -124
- data/stdlib/prettyprint/0/prettyprint.rbs +120 -99
- data/stdlib/prime/0/integer-extension.rbs +20 -2
- data/stdlib/prime/0/prime.rbs +88 -21
- data/stdlib/pstore/0/pstore.rbs +102 -0
- data/stdlib/pty/0/pty.rbs +64 -14
- data/stdlib/resolv/0/resolv.rbs +420 -31
- data/stdlib/rubygems/0/basic_specification.rbs +4 -1
- data/stdlib/rubygems/0/config_file.rbs +33 -1
- data/stdlib/rubygems/0/dependency_installer.rbs +4 -3
- data/stdlib/rubygems/0/installer.rbs +13 -1
- data/stdlib/rubygems/0/path_support.rbs +4 -1
- data/stdlib/rubygems/0/platform.rbs +5 -1
- data/stdlib/rubygems/0/request_set.rbs +44 -2
- data/stdlib/rubygems/0/requirement.rbs +65 -2
- data/stdlib/rubygems/0/rubygems.rbs +407 -0
- data/stdlib/rubygems/0/source_list.rbs +13 -0
- data/stdlib/rubygems/0/specification.rbs +21 -1
- data/stdlib/rubygems/0/stream_ui.rbs +3 -1
- data/stdlib/rubygems/0/uninstaller.rbs +8 -1
- data/stdlib/rubygems/0/version.rbs +60 -157
- data/stdlib/securerandom/0/securerandom.rbs +44 -0
- data/stdlib/set/0/set.rbs +420 -106
- data/stdlib/shellwords/0/shellwords.rbs +55 -77
- data/stdlib/singleton/0/singleton.rbs +20 -0
- data/stdlib/socket/0/addrinfo.rbs +210 -9
- data/stdlib/socket/0/basic_socket.rbs +103 -11
- data/stdlib/socket/0/ip_socket.rbs +31 -9
- data/stdlib/socket/0/socket.rbs +586 -38
- data/stdlib/socket/0/tcp_server.rbs +22 -2
- data/stdlib/socket/0/tcp_socket.rbs +12 -1
- data/stdlib/socket/0/udp_socket.rbs +25 -2
- data/stdlib/socket/0/unix_server.rbs +22 -2
- data/stdlib/socket/0/unix_socket.rbs +45 -5
- data/stdlib/strscan/0/string_scanner.rbs +210 -9
- data/stdlib/tempfile/0/tempfile.rbs +58 -10
- data/stdlib/time/0/time.rbs +208 -116
- data/stdlib/timeout/0/timeout.rbs +10 -0
- data/stdlib/tmpdir/0/tmpdir.rbs +13 -4
- data/stdlib/tsort/0/cyclic.rbs +1 -0
- data/stdlib/tsort/0/interfaces.rbs +1 -0
- data/stdlib/tsort/0/tsort.rbs +42 -0
- data/stdlib/uri/0/common.rbs +57 -8
- data/stdlib/uri/0/file.rbs +55 -109
- data/stdlib/uri/0/ftp.rbs +6 -3
- data/stdlib/uri/0/generic.rbs +556 -327
- data/stdlib/uri/0/http.rbs +26 -115
- data/stdlib/uri/0/https.rbs +8 -102
- data/stdlib/uri/0/ldap.rbs +143 -137
- data/stdlib/uri/0/ldaps.rbs +8 -102
- data/stdlib/uri/0/mailto.rbs +3 -0
- data/stdlib/uri/0/rfc2396_parser.rbs +66 -26
- data/stdlib/uri/0/ws.rbs +6 -3
- data/stdlib/uri/0/wss.rbs +5 -3
- data/stdlib/yaml/0/dbm.rbs +151 -87
- data/stdlib/yaml/0/store.rbs +6 -0
- data/stdlib/zlib/0/zlib.rbs +90 -31
- metadata +17 -5
- data/lib/rbs/location.rb +0 -221
data/core/encoding.rbs
CHANGED
@@ -1,101 +1,378 @@
|
|
1
|
+
# <!-- rdoc-file=encoding.c -->
|
2
|
+
# An Encoding instance represents a character encoding usable in Ruby. It is
|
3
|
+
# defined as a constant under the Encoding namespace. It has a name and
|
4
|
+
# optionally, aliases:
|
5
|
+
#
|
6
|
+
# Encoding::ISO_8859_1.name
|
7
|
+
# #=> "ISO-8859-1"
|
8
|
+
#
|
9
|
+
# Encoding::ISO_8859_1.names
|
10
|
+
# #=> ["ISO-8859-1", "ISO8859-1"]
|
11
|
+
#
|
12
|
+
# Ruby methods dealing with encodings return or accept Encoding instances as
|
13
|
+
# arguments (when a method accepts an Encoding instance as an argument, it can
|
14
|
+
# be passed an Encoding name or alias instead).
|
15
|
+
#
|
16
|
+
# "some string".encoding
|
17
|
+
# #=> #<Encoding:UTF-8>
|
18
|
+
#
|
19
|
+
# string = "some string".encode(Encoding::ISO_8859_1)
|
20
|
+
# #=> "some string"
|
21
|
+
# string.encoding
|
22
|
+
# #=> #<Encoding:ISO-8859-1>
|
23
|
+
#
|
24
|
+
# "some string".encode "ISO-8859-1"
|
25
|
+
# #=> "some string"
|
26
|
+
#
|
27
|
+
# Encoding::ASCII_8BIT is a special encoding that is usually used for a byte
|
28
|
+
# string, not a character string. But as the name insists, its characters in the
|
29
|
+
# range of ASCII are considered as ASCII characters. This is useful when you
|
30
|
+
# use ASCII-8BIT characters with other ASCII compatible characters.
|
31
|
+
#
|
32
|
+
# ## Changing an encoding
|
33
|
+
#
|
34
|
+
# The associated Encoding of a String can be changed in two different ways.
|
35
|
+
#
|
36
|
+
# First, it is possible to set the Encoding of a string to a new Encoding
|
37
|
+
# without changing the internal byte representation of the string, with
|
38
|
+
# String#force_encoding. This is how you can tell Ruby the correct encoding of a
|
39
|
+
# string.
|
40
|
+
#
|
41
|
+
# string
|
42
|
+
# #=> "R\xC3\xA9sum\xC3\xA9"
|
43
|
+
# string.encoding
|
44
|
+
# #=> #<Encoding:ISO-8859-1>
|
45
|
+
# string.force_encoding(Encoding::UTF_8)
|
46
|
+
# #=> "R\u00E9sum\u00E9"
|
47
|
+
#
|
48
|
+
# Second, it is possible to transcode a string, i.e. translate its internal byte
|
49
|
+
# representation to another encoding. Its associated encoding is also set to the
|
50
|
+
# other encoding. See String#encode for the various forms of transcoding, and
|
51
|
+
# the Encoding::Converter class for additional control over the transcoding
|
52
|
+
# process.
|
53
|
+
#
|
54
|
+
# string
|
55
|
+
# #=> "R\u00E9sum\u00E9"
|
56
|
+
# string.encoding
|
57
|
+
# #=> #<Encoding:UTF-8>
|
58
|
+
# string = string.encode!(Encoding::ISO_8859_1)
|
59
|
+
# #=> "R\xE9sum\xE9"
|
60
|
+
# string.encoding
|
61
|
+
# #=> #<Encoding::ISO-8859-1>
|
62
|
+
#
|
63
|
+
# ## Script encoding
|
64
|
+
#
|
65
|
+
# All Ruby script code has an associated Encoding which any String literal
|
66
|
+
# created in the source code will be associated to.
|
67
|
+
#
|
68
|
+
# The default script encoding is Encoding::UTF_8 after v2.0, but it can be
|
69
|
+
# changed by a magic comment on the first line of the source code file (or
|
70
|
+
# second line, if there is a shebang line on the first). The comment must
|
71
|
+
# contain the word `coding` or `encoding`, followed by a colon, space and the
|
72
|
+
# Encoding name or alias:
|
73
|
+
#
|
74
|
+
# # encoding: UTF-8
|
75
|
+
#
|
76
|
+
# "some string".encoding
|
77
|
+
# #=> #<Encoding:UTF-8>
|
78
|
+
#
|
79
|
+
# The `__ENCODING__` keyword returns the script encoding of the file which the
|
80
|
+
# keyword is written:
|
81
|
+
#
|
82
|
+
# # encoding: ISO-8859-1
|
83
|
+
#
|
84
|
+
# __ENCODING__
|
85
|
+
# #=> #<Encoding:ISO-8859-1>
|
86
|
+
#
|
87
|
+
# `ruby -K` will change the default locale encoding, but this is not
|
88
|
+
# recommended. Ruby source files should declare its script encoding by a magic
|
89
|
+
# comment even when they only depend on US-ASCII strings or regular expressions.
|
90
|
+
#
|
91
|
+
# ## Locale encoding
|
92
|
+
#
|
93
|
+
# The default encoding of the environment. Usually derived from locale.
|
94
|
+
#
|
95
|
+
# see Encoding.locale_charmap, Encoding.find('locale')
|
96
|
+
#
|
97
|
+
# ## Filesystem encoding
|
98
|
+
#
|
99
|
+
# The default encoding of strings from the filesystem of the environment. This
|
100
|
+
# is used for strings of file names or paths.
|
101
|
+
#
|
102
|
+
# see Encoding.find('filesystem')
|
103
|
+
#
|
104
|
+
# ## External encoding
|
105
|
+
#
|
106
|
+
# Each IO object has an external encoding which indicates the encoding that Ruby
|
107
|
+
# will use to read its data. By default Ruby sets the external encoding of an IO
|
108
|
+
# object to the default external encoding. The default external encoding is set
|
109
|
+
# by locale encoding or the interpreter `-E` option. Encoding.default_external
|
110
|
+
# returns the current value of the external encoding.
|
111
|
+
#
|
112
|
+
# ENV["LANG"]
|
113
|
+
# #=> "UTF-8"
|
114
|
+
# Encoding.default_external
|
115
|
+
# #=> #<Encoding:UTF-8>
|
116
|
+
#
|
117
|
+
# $ ruby -E ISO-8859-1 -e "p Encoding.default_external"
|
118
|
+
# #<Encoding:ISO-8859-1>
|
119
|
+
#
|
120
|
+
# $ LANG=C ruby -e 'p Encoding.default_external'
|
121
|
+
# #<Encoding:US-ASCII>
|
122
|
+
#
|
123
|
+
# The default external encoding may also be set through
|
124
|
+
# Encoding.default_external=, but you should not do this as strings created
|
125
|
+
# before and after the change will have inconsistent encodings. Instead use
|
126
|
+
# `ruby -E` to invoke ruby with the correct external encoding.
|
127
|
+
#
|
128
|
+
# When you know that the actual encoding of the data of an IO object is not the
|
129
|
+
# default external encoding, you can reset its external encoding with
|
130
|
+
# IO#set_encoding or set it at IO object creation (see IO.new options).
|
131
|
+
#
|
132
|
+
# ## Internal encoding
|
133
|
+
#
|
134
|
+
# To process the data of an IO object which has an encoding different from its
|
135
|
+
# external encoding, you can set its internal encoding. Ruby will use this
|
136
|
+
# internal encoding to transcode the data when it is read from the IO object.
|
137
|
+
#
|
138
|
+
# Conversely, when data is written to the IO object it is transcoded from the
|
139
|
+
# internal encoding to the external encoding of the IO object.
|
140
|
+
#
|
141
|
+
# The internal encoding of an IO object can be set with IO#set_encoding or at IO
|
142
|
+
# object creation (see IO.new options).
|
143
|
+
#
|
144
|
+
# The internal encoding is optional and when not set, the Ruby default internal
|
145
|
+
# encoding is used. If not explicitly set this default internal encoding is
|
146
|
+
# `nil` meaning that by default, no transcoding occurs.
|
147
|
+
#
|
148
|
+
# The default internal encoding can be set with the interpreter option `-E`.
|
149
|
+
# Encoding.default_internal returns the current internal encoding.
|
150
|
+
#
|
151
|
+
# $ ruby -e 'p Encoding.default_internal'
|
152
|
+
# nil
|
153
|
+
#
|
154
|
+
# $ ruby -E ISO-8859-1:UTF-8 -e "p [Encoding.default_external, \
|
155
|
+
# Encoding.default_internal]"
|
156
|
+
# [#<Encoding:ISO-8859-1>, #<Encoding:UTF-8>]
|
157
|
+
#
|
158
|
+
# The default internal encoding may also be set through
|
159
|
+
# Encoding.default_internal=, but you should not do this as strings created
|
160
|
+
# before and after the change will have inconsistent encodings. Instead use
|
161
|
+
# `ruby -E` to invoke ruby with the correct internal encoding.
|
162
|
+
#
|
163
|
+
# ## IO encoding example
|
164
|
+
#
|
165
|
+
# In the following example a UTF-8 encoded string "Ru00E9sumu00E9" is transcoded
|
166
|
+
# for output to ISO-8859-1 encoding, then read back in and transcoded to UTF-8:
|
167
|
+
#
|
168
|
+
# string = "R\u00E9sum\u00E9"
|
169
|
+
#
|
170
|
+
# open("transcoded.txt", "w:ISO-8859-1") do |io|
|
171
|
+
# io.write(string)
|
172
|
+
# end
|
173
|
+
#
|
174
|
+
# puts "raw text:"
|
175
|
+
# p File.binread("transcoded.txt")
|
176
|
+
# puts
|
177
|
+
#
|
178
|
+
# open("transcoded.txt", "r:ISO-8859-1:UTF-8") do |io|
|
179
|
+
# puts "transcoded text:"
|
180
|
+
# p io.read
|
181
|
+
# end
|
182
|
+
#
|
183
|
+
# While writing the file, the internal encoding is not specified as it is only
|
184
|
+
# necessary for reading. While reading the file both the internal and external
|
185
|
+
# encoding must be specified to obtain the correct result.
|
186
|
+
#
|
187
|
+
# $ ruby t.rb
|
188
|
+
# raw text:
|
189
|
+
# "R\xE9sum\xE9"
|
190
|
+
#
|
191
|
+
# transcoded text:
|
192
|
+
# "R\u00E9sum\u00E9"
|
193
|
+
#
|
1
194
|
class Encoding < Object
|
195
|
+
# <!--
|
196
|
+
# rdoc-file=encoding.c
|
197
|
+
# - Encoding.aliases -> {"alias1" => "orig1", "alias2" => "orig2", ...}
|
198
|
+
# -->
|
2
199
|
# Returns the hash of available encoding alias and original encoding name.
|
3
200
|
#
|
4
201
|
# Encoding.aliases
|
5
|
-
# #=> {"BINARY"=>"ASCII-8BIT", "ASCII"=>"US-ASCII", "ANSI_X3.4-
|
6
|
-
# "SJIS"=>"
|
202
|
+
# #=> {"BINARY"=>"ASCII-8BIT", "ASCII"=>"US-ASCII", "ANSI_X3.4-1968"=>"US-ASCII",
|
203
|
+
# "SJIS"=>"Windows-31J", "eucJP"=>"EUC-JP", "CP932"=>"Windows-31J"}
|
204
|
+
#
|
7
205
|
def self.aliases: () -> ::Hash[String, String]
|
8
206
|
|
9
|
-
|
10
|
-
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# from the following locations:
|
207
|
+
# <!--
|
208
|
+
# rdoc-file=encoding.c
|
209
|
+
# - Encoding.compatible?(obj1, obj2) -> enc or nil
|
210
|
+
# -->
|
211
|
+
# Checks the compatibility of two objects.
|
15
212
|
#
|
16
|
-
#
|
213
|
+
# If the objects are both strings they are compatible when they are
|
214
|
+
# concatenatable. The encoding of the concatenated string will be returned if
|
215
|
+
# they are compatible, nil if they are not.
|
17
216
|
#
|
18
|
-
#
|
19
|
-
#
|
217
|
+
# Encoding.compatible?("\xa1".force_encoding("iso-8859-1"), "b")
|
218
|
+
# #=> #<Encoding:ISO-8859-1>
|
20
219
|
#
|
21
|
-
#
|
220
|
+
# Encoding.compatible?(
|
221
|
+
# "\xa1".force_encoding("iso-8859-1"),
|
222
|
+
# "\xa1\xa1".force_encoding("euc-jp"))
|
223
|
+
# #=> nil
|
22
224
|
#
|
23
|
-
#
|
225
|
+
# If the objects are non-strings their encodings are compatible when they have
|
226
|
+
# an encoding and:
|
227
|
+
# * Either encoding is US-ASCII compatible
|
228
|
+
# * One of the encodings is a 7-bit encoding
|
24
229
|
#
|
25
|
-
|
230
|
+
def self.compatible?: (untyped obj1, untyped obj2) -> Encoding?
|
231
|
+
|
232
|
+
# <!--
|
233
|
+
# rdoc-file=encoding.c
|
234
|
+
# - Encoding.default_external -> enc
|
235
|
+
# -->
|
236
|
+
# Returns default external encoding.
|
26
237
|
#
|
27
|
-
#
|
238
|
+
# The default external encoding is used by default for strings created from the
|
239
|
+
# following locations:
|
28
240
|
#
|
29
|
-
#
|
241
|
+
# * CSV
|
242
|
+
# * File data read from disk
|
243
|
+
# * SDBM
|
244
|
+
# * StringIO
|
245
|
+
# * Zlib::GzipReader
|
246
|
+
# * Zlib::GzipWriter
|
247
|
+
# * String#inspect
|
248
|
+
# * Regexp#inspect
|
30
249
|
#
|
31
|
-
# - [Regexp\#inspect](https://ruby-doc.org/core-2.6.3/Regexp.html#method-i-inspect)
|
32
250
|
#
|
33
251
|
# While strings created from these locations will have this encoding, the
|
34
|
-
# encoding may not be valid.
|
35
|
-
#
|
36
|
-
#
|
252
|
+
# encoding may not be valid. Be sure to check String#valid_encoding?.
|
253
|
+
#
|
254
|
+
# File data written to disk will be transcoded to the default external encoding
|
255
|
+
# when written, if default_internal is not nil.
|
37
256
|
#
|
38
|
-
#
|
39
|
-
#
|
257
|
+
# The default external encoding is initialized by the -E option. If -E isn't
|
258
|
+
# set, it is initialized to UTF-8 on Windows and the locale on other operating
|
259
|
+
# systems.
|
40
260
|
#
|
41
|
-
# The default external encoding is initialized by the locale or -E option.
|
42
261
|
def self.default_external: () -> Encoding
|
43
262
|
|
263
|
+
# <!--
|
264
|
+
# rdoc-file=encoding.c
|
265
|
+
# - Encoding.default_external = enc
|
266
|
+
# -->
|
267
|
+
# Sets default external encoding. You should not set Encoding::default_external
|
268
|
+
# in ruby code as strings created before changing the value may have a different
|
269
|
+
# encoding from strings created after the value was changed., instead you should
|
270
|
+
# use `ruby -E` to invoke ruby with the correct default_external.
|
271
|
+
#
|
272
|
+
# See Encoding::default_external for information on how the default external
|
273
|
+
# encoding is used.
|
274
|
+
#
|
44
275
|
def self.default_external=: (String arg0) -> String
|
45
276
|
| (Encoding arg0) -> Encoding
|
46
277
|
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
278
|
+
# <!--
|
279
|
+
# rdoc-file=encoding.c
|
280
|
+
# - Encoding.default_internal -> enc
|
281
|
+
# -->
|
282
|
+
# Returns default internal encoding. Strings will be transcoded to the default
|
283
|
+
# internal encoding in the following places if the default internal encoding is
|
284
|
+
# not nil:
|
50
285
|
#
|
51
|
-
#
|
286
|
+
# * CSV
|
287
|
+
# * Etc.sysconfdir and Etc.systmpdir
|
288
|
+
# * File data read from disk
|
289
|
+
# * File names from Dir
|
290
|
+
# * Integer#chr
|
291
|
+
# * String#inspect and Regexp#inspect
|
292
|
+
# * Strings returned from Readline
|
293
|
+
# * Strings returned from SDBM
|
294
|
+
# * Time#zone
|
295
|
+
# * Values from ENV
|
296
|
+
# * Values in ARGV including $PROGRAM_NAME
|
52
297
|
#
|
53
|
-
# - Etc.sysconfdir and Etc.systmpdir
|
54
298
|
#
|
55
|
-
#
|
56
|
-
#
|
299
|
+
# Additionally String#encode and String#encode! use the default internal
|
300
|
+
# encoding if no encoding is given.
|
57
301
|
#
|
58
|
-
#
|
59
|
-
#
|
302
|
+
# The script encoding (__ENCODING__), not default_internal, is used as the
|
303
|
+
# encoding of created strings.
|
60
304
|
#
|
61
|
-
#
|
305
|
+
# Encoding::default_internal is initialized with -E option or nil otherwise.
|
62
306
|
#
|
63
|
-
|
64
|
-
|
65
|
-
#
|
307
|
+
def self.default_internal: () -> Encoding?
|
308
|
+
|
309
|
+
# <!--
|
310
|
+
# rdoc-file=encoding.c
|
311
|
+
# - Encoding.default_internal = enc or nil
|
312
|
+
# -->
|
313
|
+
# Sets default internal encoding or removes default internal encoding when
|
314
|
+
# passed nil. You should not set Encoding::default_internal in ruby code as
|
315
|
+
# strings created before changing the value may have a different encoding from
|
316
|
+
# strings created after the change. Instead you should use `ruby -E` to invoke
|
317
|
+
# ruby with the correct default_internal.
|
66
318
|
#
|
67
|
-
#
|
319
|
+
# See Encoding::default_internal for information on how the default internal
|
320
|
+
# encoding is used.
|
68
321
|
#
|
69
|
-
|
322
|
+
def self.default_internal=: (String arg0) -> String?
|
323
|
+
| (Encoding arg0) -> Encoding?
|
324
|
+
| (nil arg0) -> nil
|
325
|
+
|
326
|
+
# <!--
|
327
|
+
# rdoc-file=encoding.c
|
328
|
+
# - Encoding.find(string) -> enc
|
329
|
+
# -->
|
330
|
+
# Search the encoding with specified *name*. *name* should be a string.
|
70
331
|
#
|
71
|
-
#
|
332
|
+
# Encoding.find("US-ASCII") #=> #<Encoding:US-ASCII>
|
72
333
|
#
|
73
|
-
#
|
334
|
+
# Names which this method accept are encoding names and aliases including
|
335
|
+
# following special aliases
|
74
336
|
#
|
75
|
-
#
|
337
|
+
# "external"
|
338
|
+
# : default external encoding
|
339
|
+
# "internal"
|
340
|
+
# : default internal encoding
|
341
|
+
# "locale"
|
342
|
+
# : locale encoding
|
343
|
+
# "filesystem"
|
344
|
+
# : filesystem encoding
|
76
345
|
#
|
77
|
-
# Additionally
|
78
|
-
# [String\#encode](https://ruby-doc.org/core-2.6.3/String.html#method-i-encode)
|
79
|
-
# and
|
80
|
-
# [String\#encode\!](https://ruby-doc.org/core-2.6.3/String.html#method-i-encode-21)
|
81
|
-
# use the default internal encoding if no encoding is given.
|
82
346
|
#
|
83
|
-
#
|
84
|
-
#
|
85
|
-
# ,
|
347
|
+
# An ArgumentError is raised when no encoding with *name*. Only
|
348
|
+
# `Encoding.find("internal")` however returns nil when no encoding named
|
349
|
+
# "internal", in other words, when Ruby has no default internal encoding.
|
86
350
|
#
|
87
|
-
# [::default\_internal](Encoding.downloaded.ruby_doc#method-c-default_internal)
|
88
|
-
# is initialized by the source file's internal\_encoding or -E option.
|
89
|
-
def self.default_internal: () -> Encoding?
|
90
|
-
|
91
|
-
def self.default_internal=: (String arg0) -> String?
|
92
|
-
| (Encoding arg0) -> Encoding?
|
93
|
-
| (nil arg0) -> nil
|
94
|
-
|
95
351
|
def self.find: (String | Encoding arg0) -> Encoding
|
96
352
|
|
353
|
+
# <!--
|
354
|
+
# rdoc-file=encoding.c
|
355
|
+
# - Encoding.list -> [enc1, enc2, ...]
|
356
|
+
# -->
|
357
|
+
# Returns the list of loaded encodings.
|
358
|
+
#
|
359
|
+
# Encoding.list
|
360
|
+
# #=> [#<Encoding:ASCII-8BIT>, #<Encoding:UTF-8>,
|
361
|
+
# #<Encoding:ISO-2022-JP (dummy)>]
|
362
|
+
#
|
363
|
+
# Encoding.find("US-ASCII")
|
364
|
+
# #=> #<Encoding:US-ASCII>
|
365
|
+
#
|
366
|
+
# Encoding.list
|
367
|
+
# #=> [#<Encoding:ASCII-8BIT>, #<Encoding:UTF-8>,
|
368
|
+
# #<Encoding:US-ASCII>, #<Encoding:ISO-2022-JP (dummy)>]
|
369
|
+
#
|
97
370
|
def self.list: () -> ::Array[Encoding]
|
98
371
|
|
372
|
+
# <!--
|
373
|
+
# rdoc-file=encoding.c
|
374
|
+
# - Encoding.name_list -> ["enc1", "enc2", ...]
|
375
|
+
# -->
|
99
376
|
# Returns the list of available encoding names.
|
100
377
|
#
|
101
378
|
# Encoding.name_list
|
@@ -103,49 +380,80 @@ class Encoding < Object
|
|
103
380
|
# "ISO-8859-1", "Shift_JIS", "EUC-JP",
|
104
381
|
# "Windows-31J",
|
105
382
|
# "BINARY", "CP932", "eucJP"]
|
383
|
+
#
|
106
384
|
def self.name_list: () -> ::Array[String]
|
107
385
|
|
386
|
+
# <!--
|
387
|
+
# rdoc-file=encoding.c
|
388
|
+
# - enc.ascii_compatible? -> true or false
|
389
|
+
# -->
|
108
390
|
# Returns whether ASCII-compatible or not.
|
109
391
|
#
|
110
|
-
#
|
111
|
-
#
|
112
|
-
#
|
113
|
-
# ```
|
392
|
+
# Encoding::UTF_8.ascii_compatible? #=> true
|
393
|
+
# Encoding::UTF_16BE.ascii_compatible? #=> false
|
394
|
+
#
|
114
395
|
def ascii_compatible?: () -> bool
|
115
396
|
|
116
|
-
#
|
117
|
-
#
|
118
|
-
#
|
397
|
+
# <!--
|
398
|
+
# rdoc-file=encoding.c
|
399
|
+
# - enc.dummy? -> true or false
|
400
|
+
# -->
|
401
|
+
# Returns true for dummy encodings. A dummy encoding is an encoding for which
|
402
|
+
# character handling is not properly implemented. It is used for stateful
|
403
|
+
# encodings.
|
404
|
+
#
|
405
|
+
# Encoding::ISO_2022_JP.dummy? #=> true
|
406
|
+
# Encoding::UTF_8.dummy? #=> false
|
119
407
|
#
|
120
|
-
# ```ruby
|
121
|
-
# Encoding::ISO_2022_JP.dummy? #=> true
|
122
|
-
# Encoding::UTF_8.dummy? #=> false
|
123
|
-
# ```
|
124
408
|
def dummy?: () -> bool
|
125
409
|
|
410
|
+
# <!--
|
411
|
+
# rdoc-file=encoding.c
|
412
|
+
# - enc.inspect -> string
|
413
|
+
# -->
|
414
|
+
# Returns a string which represents the encoding for programmers.
|
415
|
+
#
|
416
|
+
# Encoding::UTF_8.inspect #=> "#<Encoding:UTF-8>"
|
417
|
+
# Encoding::ISO_2022_JP.inspect #=> "#<Encoding:ISO-2022-JP (dummy)>"
|
418
|
+
#
|
126
419
|
def inspect: () -> String
|
127
420
|
|
421
|
+
# <!-- rdoc-file=encoding.c -->
|
128
422
|
# Returns the name of the encoding.
|
129
423
|
#
|
130
|
-
#
|
131
|
-
#
|
132
|
-
# ```
|
424
|
+
# Encoding::UTF_8.name #=> "UTF-8"
|
425
|
+
#
|
133
426
|
def name: () -> String
|
134
427
|
|
428
|
+
# <!--
|
429
|
+
# rdoc-file=encoding.c
|
430
|
+
# - enc.names -> array
|
431
|
+
# -->
|
135
432
|
# Returns the list of name and aliases of the encoding.
|
136
433
|
#
|
137
|
-
#
|
138
|
-
#
|
139
|
-
# ```
|
434
|
+
# Encoding::WINDOWS_31J.names #=> ["Windows-31J", "CP932", "csWindows31J", "SJIS", "PCK"]
|
435
|
+
#
|
140
436
|
def names: () -> ::Array[String]
|
141
437
|
|
438
|
+
# <!--
|
439
|
+
# rdoc-file=encoding.c
|
440
|
+
# - enc.replicate(name) -> encoding
|
441
|
+
# -->
|
442
|
+
# Returns a replicated encoding of *enc* whose name is *name*. The new encoding
|
443
|
+
# should have the same byte structure of *enc*. If *name* is used by another
|
444
|
+
# encoding, raise ArgumentError.
|
445
|
+
#
|
142
446
|
def replicate: (String name) -> Encoding
|
143
447
|
|
448
|
+
# <!--
|
449
|
+
# rdoc-file=encoding.c
|
450
|
+
# - enc.name -> string
|
451
|
+
# - enc.to_s -> string
|
452
|
+
# -->
|
144
453
|
# Returns the name of the encoding.
|
145
454
|
#
|
146
|
-
#
|
147
|
-
#
|
148
|
-
# ```
|
455
|
+
# Encoding::UTF_8.name #=> "UTF-8"
|
456
|
+
#
|
149
457
|
def to_s: () -> String
|
150
458
|
end
|
151
459
|
|
@@ -567,43 +875,130 @@ Encoding::Windows_31J: Encoding
|
|
567
875
|
|
568
876
|
Encoding::Windows_874: Encoding
|
569
877
|
|
878
|
+
# <!-- rdoc-file=transcode.c -->
|
879
|
+
# Encoding conversion class.
|
880
|
+
#
|
570
881
|
class Encoding::Converter < Object
|
571
882
|
end
|
572
883
|
|
884
|
+
# <!-- rdoc-file=transcode.c -->
|
885
|
+
# AFTER_OUTPUT
|
886
|
+
#
|
887
|
+
# Stop converting after some output is complete but before all of the input was
|
888
|
+
# consumed. See primitive_convert for an example.
|
889
|
+
#
|
573
890
|
Encoding::Converter::AFTER_OUTPUT: Integer
|
574
891
|
|
892
|
+
# <!-- rdoc-file=transcode.c -->
|
893
|
+
# CRLF_NEWLINE_DECORATOR
|
894
|
+
#
|
895
|
+
# Decorator for converting LF to CRLF
|
896
|
+
#
|
575
897
|
Encoding::Converter::CRLF_NEWLINE_DECORATOR: Integer
|
576
898
|
|
899
|
+
# <!-- rdoc-file=transcode.c -->
|
900
|
+
# CR_NEWLINE_DECORATOR
|
901
|
+
#
|
902
|
+
# Decorator for converting LF to CR
|
903
|
+
#
|
577
904
|
Encoding::Converter::CR_NEWLINE_DECORATOR: Integer
|
578
905
|
|
906
|
+
# <!-- rdoc-file=transcode.c -->
|
907
|
+
# INVALID_MASK
|
908
|
+
#
|
909
|
+
# Mask for invalid byte sequences
|
910
|
+
#
|
579
911
|
Encoding::Converter::INVALID_MASK: Integer
|
580
912
|
|
913
|
+
# <!-- rdoc-file=transcode.c -->
|
914
|
+
# INVALID_REPLACE
|
915
|
+
#
|
916
|
+
# Replace invalid byte sequences
|
917
|
+
#
|
581
918
|
Encoding::Converter::INVALID_REPLACE: Integer
|
582
919
|
|
920
|
+
# <!-- rdoc-file=transcode.c -->
|
921
|
+
# PARTIAL_INPUT
|
922
|
+
#
|
923
|
+
# Indicates the source may be part of a larger string. See primitive_convert
|
924
|
+
# for an example.
|
925
|
+
#
|
583
926
|
Encoding::Converter::PARTIAL_INPUT: Integer
|
584
927
|
|
928
|
+
# <!-- rdoc-file=transcode.c -->
|
929
|
+
# UNDEF_HEX_CHARREF
|
930
|
+
#
|
931
|
+
# Replace byte sequences that are undefined in the destination encoding with an
|
932
|
+
# XML hexadecimal character reference. This is valid for XML conversion.
|
933
|
+
#
|
585
934
|
Encoding::Converter::UNDEF_HEX_CHARREF: Integer
|
586
935
|
|
936
|
+
# <!-- rdoc-file=transcode.c -->
|
937
|
+
# UNDEF_MASK
|
938
|
+
#
|
939
|
+
# Mask for a valid character in the source encoding but no related character(s)
|
940
|
+
# in destination encoding.
|
941
|
+
#
|
587
942
|
Encoding::Converter::UNDEF_MASK: Integer
|
588
943
|
|
944
|
+
# <!-- rdoc-file=transcode.c -->
|
945
|
+
# UNDEF_REPLACE
|
946
|
+
#
|
947
|
+
# Replace byte sequences that are undefined in the destination encoding.
|
948
|
+
#
|
589
949
|
Encoding::Converter::UNDEF_REPLACE: Integer
|
590
950
|
|
951
|
+
# <!-- rdoc-file=transcode.c -->
|
952
|
+
# UNIVERSAL_NEWLINE_DECORATOR
|
953
|
+
#
|
954
|
+
# Decorator for converting CRLF and CR to LF
|
955
|
+
#
|
591
956
|
Encoding::Converter::UNIVERSAL_NEWLINE_DECORATOR: Integer
|
592
957
|
|
958
|
+
# <!-- rdoc-file=transcode.c -->
|
959
|
+
# XML_ATTR_CONTENT_DECORATOR
|
960
|
+
#
|
961
|
+
# Escape as XML AttValue
|
962
|
+
#
|
593
963
|
Encoding::Converter::XML_ATTR_CONTENT_DECORATOR: Integer
|
594
964
|
|
965
|
+
# <!-- rdoc-file=transcode.c -->
|
966
|
+
# XML_ATTR_QUOTE_DECORATOR
|
967
|
+
#
|
968
|
+
# Escape as XML AttValue
|
969
|
+
#
|
595
970
|
Encoding::Converter::XML_ATTR_QUOTE_DECORATOR: Integer
|
596
971
|
|
972
|
+
# <!-- rdoc-file=transcode.c -->
|
973
|
+
# XML_TEXT_DECORATOR
|
974
|
+
#
|
975
|
+
# Escape as XML CharData
|
976
|
+
#
|
597
977
|
Encoding::Converter::XML_TEXT_DECORATOR: Integer
|
598
978
|
|
979
|
+
# <!-- rdoc-file=error.c -->
|
980
|
+
# Raised by Encoding and String methods when the source encoding is incompatible
|
981
|
+
# with the target encoding.
|
982
|
+
#
|
599
983
|
class Encoding::CompatibilityError < EncodingError
|
600
984
|
end
|
601
985
|
|
986
|
+
# <!-- rdoc-file=transcode.c -->
|
987
|
+
# Raised by transcoding methods when a named encoding does not correspond with a
|
988
|
+
# known converter.
|
989
|
+
#
|
602
990
|
class Encoding::ConverterNotFoundError < EncodingError
|
603
991
|
end
|
604
992
|
|
993
|
+
# <!-- rdoc-file=transcode.c -->
|
994
|
+
# Raised by Encoding and String methods when the string being transcoded
|
995
|
+
# contains a byte invalid for the either the source or target encoding.
|
996
|
+
#
|
605
997
|
class Encoding::InvalidByteSequenceError < EncodingError
|
606
998
|
end
|
607
999
|
|
1000
|
+
# <!-- rdoc-file=transcode.c -->
|
1001
|
+
# Raised by Encoding and String methods when a transcoding operation fails.
|
1002
|
+
#
|
608
1003
|
class Encoding::UndefinedConversionError < EncodingError
|
609
1004
|
end
|