Skip to content

Commit

Permalink
Add suffixes 's' and 'i'. (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdielKavash authored Apr 11, 2024
1 parent a0dad2c commit c705d87
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ minimizeShadowedDependencies = false
# If disabled, won't rename the shadowed classes.
relocateShadowedDependencies = false

# Adds the GTNH maven, CurseMaven, IC2/Player maven, and some more well-known 1.7.10 repositories.
# Adds the GTNH maven, CurseMaven, Modrinth, and some more well-known 1.7.10 repositories.
includeWellKnownRepositories = true

# Change these to your Maven coordinates if you want to publish to a custom Maven repository instead of the default GTNH Maven.
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pluginManagement {
}

plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.14'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.21'
}


Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class MathExpressionParser {
* strings that do not evaluate to a valid value. See {@link #parse(String, Context)} for an explanation of the
* syntax.
*/
public static final Pattern EXPRESSION_PATTERN = Pattern.compile("[0-9.,  _’+\\-*/^()eEkKmMgGbBtT%]*");
// Character ' ' (non-breaking space) to support French locale thousands separator.
public static final Pattern EXPRESSION_PATTERN = Pattern.compile("[0-9., \u202F_’+\\-*/^()eEkKmMgGbBtTsSiI%]*");
// Character \u202F (' ') (non-breaking space) to support French locale thousands separator.

private static final Context defaultContext = new Context();

Expand Down Expand Up @@ -178,6 +178,16 @@ public static double parse(String expr, Context ctx) {
case 'T':
handleSuffix(stack, Suffix.TRILLION, c, ctx);
break;

case 's':
case 'S':
handleSuffix(stack, Suffix.STACK, c, ctx);
break;
case 'i':
case 'I':
handleSuffix(stack, Suffix.INGOT, c, ctx);
break;

case '%':
handleSuffix(stack, Suffix.PERCENT, c, ctx);
break;
Expand Down Expand Up @@ -511,6 +521,8 @@ private enum Suffix {
MILLION(1_000_000d),
BILLION(1_000_000_000d),
TRILLION(1_000_000_000_000d),
STACK(64),
INGOT(144),
PERCENT(0); // Handled separately.

public final double multiplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ void SuffixesBasic_Test() {
assertEquals(10_000_000_000_000D, MathExpressionParser.parse("10t"));
assertEquals(11_000_000_000_000D, MathExpressionParser.parse("11T"));

assertEquals(12 * 64, MathExpressionParser.parse("12s"));
assertEquals(13 * 64, MathExpressionParser.parse("13S"));
assertEquals(14 * 144, MathExpressionParser.parse("14i"));
assertEquals(15 * 144, MathExpressionParser.parse("15I"));

assertEquals(16 * 64 + 16, MathExpressionParser.parse("16.25s", ctxEN));
assertEquals(17 * 144 + 72, MathExpressionParser.parse("17.5i", ctxEN));

assertEquals(2050, MathExpressionParser.parse("2.05k", ctxEN));
assertEquals(50, MathExpressionParser.parse("0.05k", ctxEN));
assertEquals(3000, MathExpressionParser.parse("3 k"));
Expand All @@ -157,6 +165,10 @@ void SuffixesArithmetic_Test() {
assertEquals(3_000_000, MathExpressionParser.parse("3kk"));
assertEquals(4_000_000_000D, MathExpressionParser.parse("4kkk"));

// Ideally we would want "1/9i" to parse into this too, but that would require a larger rework.
// Currently, suffixes are hardcoded to have the highest priority.
assertEquals(16, MathExpressionParser.parse("(1/9)i"));

// Not supported, but shouldn't fail.
assertEquals(6_000_000_000d, MathExpressionParser.parse("6km"));
assertEquals(500_000, MathExpressionParser.parse("0.5ke3", ctxEN));
Expand Down

0 comments on commit c705d87

Please sign in to comment.