Skip to content

Feature Request: Add write_n() function to fmt::BasicWriter that restricts output to a specified number of characters. #298

Closed
@KevinDHall

Description

The idea is to make write_n() be a replacement for the snprintf() family of functions.

The reason this would be useful is to prevent fmt::BasicArrayWriter from throwing an exception when output cannot fit in the buffer. Currently one may wrap write() in a try block, but the element that caused the exception to be thrown will not be printed at all -- not even partially. Often it is desired to get partial output. One example is copying long strings (log or error messages). It is better to get some of the text instead of none of it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions