Giter Site home page Giter Site logo

Various issues in fprint. about gears HOT 5 CLOSED

orlp avatar orlp commented on August 26, 2024
Various issues in fprint.

from gears.

Comments (5)

Rapptz avatar Rapptz commented on August 26, 2024

Thanks. I'll look into this later.

from gears.

Rapptz avatar Rapptz commented on August 26, 2024

I'm getting around to this tonight. I have a few responses though.

Potential issue: format string is totally ignored if no additional arguments were passed. You mentioned this was by design, but I strongly recommend you to reconsider it as it potentially breaks generic code that relies on fprint, and if a user really wants the faster "unformatted formatting" they can always resort to just calling out << str .

This is a legitimate issue. I figure I might as well do it.

Doc issue: format-string is a confusing identifier in your grammar since you have the format string, containing literal text and format-strings. See the issue? I suggest taking over Pythons terminology and calling it a "replacement field".

The entire string is called a format-string. It's divided into | <parameter> : <format-spec> |. I see no ambiguity.

Critical issue: formatting is not stateless, as you do not correctly set default fill parameters, and they can carry over from replacement field to replacement field. For example: https://gist.github.com/orlp/a0aba247345baaf8c393 I only checked this for fill, but the same probably applies to precision, align, width and potentially more.

Valid concern. I'll fix it.

Checking issue: you do not check if an integer came after the dot in ["." precision]. An example invalid format string that you do not throw an exception on is |:.|

I'll fix this too.

Missing feature: std::hexfloat - you said GCC didn't support this, but I list it here for completion anyway.

I see no purpose of supporting this at the moment since I have to compile with GCC 4.8 or higher. I'm not going to drop support for GCC 4.8 and 4.9 just for a single component. I might make a macro to solve this (similar to GEARS_META_CPP14) but it's very low in my priority list and I feel like it might be more confusing than anything.

Missing feature: std::showpoint - I suggest changing p to std::showpoint and assigning + to std::showpos.

Valid concern. I'll fix this.

from gears.

Rapptz avatar Rapptz commented on August 26, 2024

Fixed in a21a017. If you see anything else missing feel free to reopen this issue.

from gears.

orlp avatar orlp commented on August 26, 2024

Two things:

  1. The entire string is called a format-string. It's divided into | : |. I see no ambiguity.

    Here's the thing, the parameter itself to the fprint function is what you would call a
    "format string". This in turn contains literal characters and replacement fields. In your
    grammar the literal characters are ignored, and you make it seem like there is only one
    replacement field in the entire format string:

    format-string ::= "|" <`parameter`> [":" `format-spec`] "|"
    

    This would be better IMO:

    format-string ::= [replacement-field | <any character>]*
    replacement-field ::= "|" <`parameter`> [":" `format-spec`] "|"
    
  2. In stream_state.reset you use the value 0x20. Is out.widen(' ') always guaranteed to be 0x20?

from gears.

Rapptz avatar Rapptz commented on August 26, 2024

I'm not sure if number 1 is a really big issue. I don't explicitly see the confusion but I'll fix it anyway.

With regards to number 2, I got to thinking and I realised the small subset of ASCII (i.e 0x00 - 0x7F) is probably not succumbed to widening. Only those that have a multi-byte representation in different locales do. I think ASCII is safe so 0x20 is guaranteed in at least Windows and Linux. So I might replace all the widen calls that are < 0x7F with explicit checking with a number and probably use eq_int_type instead of eq.

from gears.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.