ruby/string.rb
Peter Zhu 491e36e187 [DOC] Inline UTF-8 docs into C code
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.
2026-11-06 00:11:32 +09:00

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