Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/rubyPublic

[DOC] Tweaks for String#dump#13883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
BurdetteLamar wants to merge3 commits intoruby:master
base:master
Choose a base branch
Loading
fromBurdetteLamar:rb_str_dump_doc

Conversation

BurdetteLamar
Copy link
Member

No description provided.

@BurdetteLamarBurdetteLamar added the DocumentationImprovements to documentation. labelJul 14, 2025
s # => "\a\b\t\n\v\f\r"
s.dump # => "\"\\a\\b\\t\\n\\v\\f\\r\""

Multi-byte characters are rendered in unicode notation:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It is only for Unicode encodings.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Does this mean that there are multi-byte characters that are not in Unicode encodings? If so, I'll need examples.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Fixed.

@BurdetteLamar
Copy link
MemberAuthor

@peterzhu2118, I'll need help with this:

  • I think I need examples of multi-byte characters that will not dump in Unicode notation.
  • Old doc notwithstanding, I found to character than dumps in hexadecimal notation. Are there any?

@peterzhu2118
Copy link
Member

I think I need examples of multi-byte characters that will not dump in Unicode notation.

For example:

'тест'.dump# => "\"\\u0442\\u0435\\u0441\\u0442\""'тест'.encode('utf-16le').dump# => "\"B\\x045\\x04A\\x04B\\x04\".dup.force_encoding(\"UTF-16LE\")"

Old doc notwithstanding, I found to character than dumps in hexadecimal notation. Are there any?

Sorry, I don't understand what you mean by this.

@BurdetteLamar
Copy link
MemberAuthor

Thanks,@peterzhu2118. What you've written above answers both questions (however poorly they're posed).

@BurdetteLamarBurdetteLamar requested a review fromnobuJuly 16, 2025 16:41
Comment on lines +9 to +25
s = 'hello'
s.encoding # => #<Encoding:UTF-8>
s.dump # => "\"hello\""
s.encode('utf-16').dump # => "\"\\xFE\\xFF\\x00h\\x00e\\x00l\\x00l\\x00o\".dup.force_encoding(\"UTF-16\")"
s.encode('utf-16le').dump # => "\"h\\x00e\\x00l\\x00l\\x00o\\x00\".dup.force_encoding(\"UTF-16LE\")"

s = 'тест'
s.encoding # => #<Encoding:UTF-8>
s.dump # => "\"\\u0442\\u0435\\u0441\\u0442\""
s.encode('utf-16').dump # => "\"\\xFE\\xFF\\x04B\\x045\\x04A\\x04B\".dup.force_encoding(\"UTF-16\")"
s.encode('utf-16le').dump # => "\"B\\x045\\x04A\\x04B\\x04\".dup.force_encoding(\"UTF-16LE\")"

s = 'こんにちは'
s.encoding # => #<Encoding:UTF-8>
s.dump # => "\"\\u3053\\u3093\\u306B\\u3061\\u306F\""
s.encode('utf-16').dump # => "\"\\xFE\\xFF0S0\\x930k0a0o\".dup.force_encoding(\"UTF-16\")"
s.encode('utf-16le').dump # => "\"S0\\x930k0a0o0\".dup.force_encoding(\"UTF-16LE\")"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think it would be better to move the examples of non-UTF8 encodings to a separate section with some text describing it (e.g. using hexadecimal format and addingdup.force_encoding(<encoding name>). This is because non-UTF8 is more of an edge case rather than a commonly used case.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I've moved the cited lines to the end. I think you want other changes, but I'm not sure what exactly is needed. Can you fix up one, as a guide for me?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@peterzhu2118peterzhu2118peterzhu2118 left review comments

@nobunobuAwaiting requested review from nobu

Assignees
No one assigned
Labels
DocumentationImprovements to documentation.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@BurdetteLamar@peterzhu2118@nobu

[8]ページ先頭

©2009-2025 Movatter.jp