[libc] Refactor static polymorphism in WriteBuffer (NFC). (#169089)

There are three flavors of WriteBuffer currently, all of which could be
passed into `printf_core::Writer` class. It's a tricky class, since it
chooses a flavor-specific logic either based on runtime dispatch (to
save code size and prevent generating three versions of the entirety of
printf_core), or based on template arguments (to avoid dealing with
function pointers in codegen for `FILL_BUFF_AND_DROP_OVERFLOW` path).

Refactor this somewhat convoluted logic to have three concrete
subclasses inheriting from the templated base class, and use static
polymorphism with `reinterpret_cast` to implement dispatching above. Now
we can actually have flavor-specific fields, constructors, and methods
(e.g. `flush_to_stream` is now a method of `FlushingBuffer`), and the
code on the user side is cleaner: the complexity of enabling/disabling
runtime-dispatch and using proper template arguments is now localized in
`writer.h`.

This code will need to be further templatized to support buffers of type
`wchar_t` to implement `swprintf()` and friends. This change would make
it (ever so slightly) easier.

NOKEYCHECK=True
GitOrigin-RevId: 5e63167965224e523ed69770754330c8cb22e90f
17 files changed