Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reinterpret precision field for strings #34544

Merged

Commits on Jul 5, 2016

  1. feat: reinterpret precision field for strings

    This commit changes the behavior of formatting string arguments
    with both width and precision fields set.
    
    Documentation says that the `width` field is the "minimum width"
    that the format should take up. If the value's string does not
    fill up this many characters, then the padding specified by
    fill/alignment will be used to take up the required space.
    
    This is true for all formatted types except string, which is truncated
    down to `precision` number of chars and then all of `fill`, `align` and
    `width` fields are completely ignored.
    
    For example: `format!("{:/^10.8}", "1234567890);` emits "12345678".
    In the contrast Python version works as the expected:
    ```python
    >>> '{:/^10.8}'.format('1234567890')
    '/12345678/'
    ```
    
    This commit gives back the `Python` behavior by changing the `precision`
    field meaning to the truncation and nothing more. The result string *will*
    be prepended/appended up to the `width` field with the proper `fill` char.
    
    However, this is the breaking change.
    
    Also updated `std::fmt` docs about string precision.
    
    Signed-off-by: Evgeny Safronov <division494@gmail.com>
    3Hren committed Jul 5, 2016
    Configuration menu
    Copy the full SHA
    ede39ae View commit details
    Browse the repository at this point in the history