-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add tests for ByteArrayExtensions #38
Conversation
Fixed up some bugs found while testing. Added UTF32 Big Endian
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the file system for unit tests is not cool. In your case a better approach would be to use Encoding.<SomeEncoding>.GetBytes()
method for getting the bytes of a string.
Arguable, but you have a point. While I have your attention, any thoughts on how to identify a UTF16 file with zero in first two bytes after marking as opposed to thinking it is UTF32? |
@Teodor92 fixed the issue with using the FS in the tests. |
@M-Zuber, I can't think of a better approach than the additional check PS I'm sorry for my late answer. I was very busy last week... |
@vladislav-karamfilov thanks for the tip, added a check + test for a UTF16 buffer with leading zeros. So this should be finished and ready to merge |
@@ -33,18 +33,24 @@ public static string GetString(this byte[] buffer) | |||
{ | |||
encoding = Encoding.UTF8; | |||
} | |||
else if (buffer[0] == 0xfe && buffer[1] == 0xff) | |||
|
|||
// In addition to preamble check the length to help UTF16 with leading zeros be recognized properly as UTF32 is 4 bytes fixed with and UTF 16 is 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small typos:
fixed with
-> fixed width
UTF16
-> UTF-16
UTF 16
-> UTF-16
UTF32
-> UTF-32
Also UTF-16 is has variable width of 2 or 4 bytes. It's good to update the comment. 😸
It looks good to me. Just a few improvements in a comment and I can merge it. :-) |
Comments updated. Thanks. |
Fixed up some bugs found while testing.
Added UTF32 Big Endian
Closes #4