mirror of
https://github.com/ruby/ruby.git
synced 2026-11-09 08:42:18 +08:00
Since https://github.com/ruby/ruby/pull/15579, we are now able to use UTF-8 comments in C code, so we no longer need to have UTF-8 documentation in separate files and use RDoc :include: directives.
33 lines
906 B
Ruby
33 lines
906 B
Ruby
class String
|
|
# call-seq:
|
|
# valid_encoding? -> true or false
|
|
#
|
|
# Returns whether +self+ is encoded correctly:
|
|
#
|
|
# s = 'Straße'
|
|
# s.valid_encoding? # => true
|
|
# s.encoding # => #<Encoding:UTF-8>
|
|
# s.force_encoding(Encoding::ASCII).valid_encoding? # => false
|
|
#
|
|
# Related: see {Querying}[rdoc-ref:String@Querying].
|
|
#
|
|
def valid_encoding?
|
|
Primitive.attr! :leaf
|
|
Primitive.cexpr! 'rb_str_valid_encoding_p(self)'
|
|
end
|
|
|
|
# call-seq:
|
|
# ascii_only? -> true or false
|
|
#
|
|
# Returns whether +self+ contains only ASCII characters:
|
|
#
|
|
# 'abc'.ascii_only? # => true
|
|
# "abc\u{6666}".ascii_only? # => false
|
|
#
|
|
# Related: see {Querying}[rdoc-ref:String@Querying].
|
|
def ascii_only?
|
|
Primitive.attr! :leaf
|
|
Primitive.cexpr! 'rb_str_is_ascii_only_p(self)'
|
|
end
|
|
end
|