Hacker News new | past | comments | ask | show | jobs | submit login

https://github.com/U8String/U8String which is a UTF-8 string library for C# that aims to offer rich and performant API to replace standard string for scenarios where you do want to consume UTF-8 directly. I'm working on it since last summer actually, it turned out to be much higher complexity project than expected :)

Also comes with a few niceties like the ability to directly consume Streams, Sockets, WebSockets and SafeFileHandles with U8Reader (sync/async) that solves painful and error-prone manual buffer handling when reading lines/segments/messages. It is kind of like higher level Rust's BufReader.




I like this a lot, thank you. Have to try it out in a project.

Is the default encoding when handling files UTF8 OR UTF8-BOM? Is both supported?

Another question: in the readme you have this example

`var joined = U8String.Join(',', boolean.Runes); // "T,r,u,e"`

Why is " T" of true in uppercase?


That's what bool.ToString() defaults to which I'm matching. As for the file API, it's a bit unfinished as I'm re-consolidating logic into U8File (OpenRead and ReadLines work acceptably, U8File.Read works too - U8Reader is in a more polished state), but the intention for the files is to detect and strip BOMs (it already does that in most[0] places[1]).

There is way more heavy lifting that the library does on the "data goes in" side of things because "data goes out" story in .NET is already in a good shape with everything accepting ReadOnlySpan<byte> and ReadOnlyMemory<byte> - zero-allocation interpolated UTF-8 output into streams, sockets, etc. is achieved through extension methods and should you want to write UTF-8 BOM, you can simply do so beforehand working with the corresponding API directly.

However, if you have a particular use case in mind that you're interested in or have trouble with - do let me know as I'd love to have more user feedback!

[0] https://github.com/U8String/U8String/blob/main/Sources/U8Str...

[1] https://github.com/U8String/U8String/blob/main/Sources/U8Str...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: