Skip to content

Commit c3ca640

Browse files
committed
Feature: Octal numbers are now supported.
...although I'm surprised they're supported in GLSL!
1 parent c9dcdab commit c3ca640

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

ShaderShrinker/Shrinker.Lexer/IntToken.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,13 @@ public IToken Simplify()
6868
Content = Content.TrimStart('-');
6969

7070
// Trim unnecessary leading zeros.
71-
while (Content.Length > 1 && Content.StartsWith("0") && char.IsNumber(Content[1]))
71+
// Note: A single leading zero represents an octal number!
72+
while (Content.Length > 2 && Content.StartsWith("00") && char.IsNumber(Content[2]))
7273
Content = Content.Substring(1);
7374

75+
if (Content == "00")
76+
Content = "0";
77+
7478
if (isNegative)
7579
Content = $"-{Content}";
7680

ShaderShrinker/UnitTests/ShrinkerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,9 @@ public void CheckSimplifyingFloatCasts(
416416
}
417417

418418
[Test, Sequential]
419-
public void CheckSimplifyingInts(
419+
public void CheckSimplifyingIntegers(
420420
[Values("0011", "-0011", "000", "00")] string code,
421-
[Values("11", "-11", "0", "0")] string expectedOutput)
421+
[Values("011", "-011", "0", "0")] string expectedOutput)
422422
{
423423
var lexer = new Lexer();
424424
lexer.Load(code);

0 commit comments

Comments
 (0)