You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
Copy file name to clipboardExpand all lines: README.md
+68-5Lines changed: 68 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# EncodedString
2
2
3
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/encoded_string`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
-
TODO: Delete this and the text above, and describe your gem
3
+
EncodedString is a wrapper for a string and a given encoding that handles operations on
4
+
strings with different encodings, invalid encodings, have no known conversion method,
5
+
or are otherwise incompatible, all without raising excpetions
if the String contains characters invalid for the target encoding
48
+
e.g. "\x80".encode('UTF-8','ASCII-8BIT')
49
+
vs "\x80".encode('UTF-8','ASCII-8BIT', undef: :replace, replace: '<undef>')
50
+
# => '<undef>'
51
+
Encoding::CompatibilityError
52
+
when Encoding.compatibile?(str1, str2) is nil
53
+
e.g. utf_16le_emoji_string.split("\n")
54
+
e.g. valid_unicode_string.encode(utf8_encoding) << ascii_string
55
+
Encoding::InvalidByteSequenceError:
56
+
when the string being transcoded contains a byte invalid for
57
+
either the source or target encoding
58
+
e.g. "\x80".encode('UTF-8','US-ASCII')
59
+
vs "\x80".encode('UTF-8','US-ASCII', invalid: :replace, replace: '<byte>')
60
+
# => '<byte>'
61
+
ArgumentError
62
+
when operating on a string with invalid bytes
63
+
e.g."\x80".split("\n")
64
+
TypeError
65
+
when a symbol is passed as an encoding
66
+
Encoding.find(:"UTF-8")
67
+
when calling force_encoding on an object
68
+
that doesn't respond to #to_str
69
+
70
+
Raised by transcoding methods:
71
+
Encoding::ConverterNotFoundError:
72
+
when a named encoding does not correspond with a known converter
73
+
e.g. 'abc'.force_encoding('UTF-8').encode('foo')
74
+
or a converter path cannot be found
75
+
e.g. "\x80".force_encoding('ASCII-8BIT').encode('Emacs-Mule')
76
+
77
+
Raised by byte <-> char conversions
78
+
RangeError: out of char range
79
+
e.g. the UTF-16LE emoji: 128169.chr
80
+
```
81
+
82
+
See [lib/encoded_string.rb](lib/encoded_string.rb) and
83
+
[spec/encoded_string_spec.rb](spec/encoded_string_spec.rb) for more information.
26
84
27
85
## Development
28
86
@@ -32,5 +90,10 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
90
33
91
## Contributing
34
92
35
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/encoded_string.
93
+
Bug reports and pull requests are welcome on GitHub at https://github.com/bf4/encoded_string. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
94
+
95
+
96
+
## License
97
+
98
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
0 commit comments