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

Handle scientific notation when parsing sizes #179

Merged
merged 6 commits into from
Sep 20, 2022

Conversation

raxbg
Copy link
Contributor

@raxbg raxbg commented Nov 13, 2019

Parsing numbers written in scientific notation raises UnexpectedTokenException. This PR fixes this.

It might be a good idea to separate the number parsing and rendering from the Size class, however this will break backwards compatibility, so it might have to wait for a new major version release. Otherwise the numbers will have to extend Size...

@sabberworm
Copy link
Contributor

It might be a good idea to separate the number parsing and rendering from the Size class, however this will break backwards compatibility, so it might have to wait for a new major version release. Otherwise the numbers will have to extend Size...

I’m not exactly sure what you mean. Size is exactly designed to handle numbers… But I agree that we should probably store additional metadata about how the size was formatted originally and provide ways for OutputFormat to determine if the output should be normalized (and to what) or output as it was input.

@@ -28,9 +28,11 @@ public static function parse(ParserState $oParserState, $bIsColorComponent = fal
if ($oParserState->comes('-')) {
$sSize .= $oParserState->consume('-');
}
while (is_numeric($oParserState->peek()) || $oParserState->comes('.')) {
while (is_numeric($oParserState->peek()) || $oParserState->comes('.') || $oParserState->comes('e+', true) || $oParserState->comes('e-', true)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I’m not mistaken, the + isn’t mandatory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Fixed.

@raxbg
Copy link
Contributor Author

raxbg commented Nov 13, 2019

I was thinking of a Number class that can be used to parse/output numbers. Size can use Numbers to store the numeric portion of its numbers. Right now Size is a little weird, because it holds all kinds of numbers even colors instead of having a Color that holds Number objects for its numeric parts. Having this further separation will make it simpler for third parties when working with plain numbers, sizes and colors generated by the parser.

@sabberworm
Copy link
Contributor

Codacy Here is an overview of what got changed by this pull request:

Issues
======
- Added 3
           

Complexity increasing per file
==============================
- lib/Sabberworm/CSS/Value/Size.php  2
         

See the complete overview on Codacy

background-color: rgba(62,174,151,3.0418206565232E+21);
z-index: 3.0418206565232E-2;
font-size: 1em;
top: 1.923478e2px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,6 @@
body {
background-color: rgba(62,174,151,3.0418206565232E+21);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,6 @@
body {
background-color: rgba(62,174,151,3.0418206565232E+21);
z-index: 3.0418206565232E-2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sabberworm sabberworm merged commit 81897e7 into MyIntervals:master Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants