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
+66-5
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
46
+
e.g. "\x80".encode('UTF-8','ASCII-8BIT')
47
+
vs "\x80".encode('UTF-8','ASCII-8BIT', undef: :replace, replace: '<undef>')
48
+
# => '<undef>'
49
+
Encoding::CompatibilityError
50
+
when Encoding.compatibile?(str1, str2) is nil
51
+
e.g. utf_16le_emoji_string.split("\n")
52
+
e.g. valid_unicode_string.encode(utf8_encoding) << ascii_string
53
+
Encoding::InvalidByteSequenceError:
54
+
when the string being transcoded contains a byte invalid for
55
+
either the source or target encoding
56
+
e.g. "\x80".encode('UTF-8','US-ASCII')
57
+
vs "\x80".encode('UTF-8','US-ASCII', invalid: :replace, replace: '<byte>')
58
+
# => '<byte>'
59
+
ArgumentError
60
+
when operating on a string with invalid bytes
61
+
e.g."\x80".split("\n")
62
+
TypeError
63
+
when a symbol is passed as an encoding
64
+
Encoding.find(:"UTF-8")
65
+
when calling force_encoding on an object
66
+
that doesn't respond to #to_str
67
+
68
+
Raised by transcoding methods:
69
+
Encoding::ConverterNotFoundError:
70
+
when a named encoding does not correspond with a known converter
71
+
e.g. 'abc'.force_encoding('UTF-8').encode('foo')
72
+
or a converter path cannot be found
73
+
e.g. "\x80".force_encoding('ASCII-8BIT').encode('Emacs-Mule')
74
+
75
+
Raised by byte <-> char conversions
76
+
RangeError: out of char range
77
+
e.g. the UTF-16LE emoji: 128169.chr
78
+
```
79
+
80
+
See [lib/encoded_string.rb](lib/encoded_string.rb) and
81
+
[spec/encoded_string_spec.rb](spec/encoded_string_spec.rb) for more information.
26
82
27
83
## Development
28
84
@@ -32,5 +88,10 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
88
33
89
## Contributing
34
90
35
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/encoded_string.
91
+
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.
92
+
93
+
94
+
## License
95
+
96
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
0 commit comments