Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/bandwidth-parse-bit-suffix-corre…
Browse files Browse the repository at this point in the history
…ctly' into next
  • Loading branch information
ArneBab committed Jun 18, 2022
2 parents 6587bd5 + 5a42fd2 commit 2456302
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/freenet/support/Fields.java
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ public static String trimPerSecond(String limit) {
final String lower = limit.toLowerCase();
for(String ending :
new String[] {
"/s", "/sec", "/second", "bps", NodeL10n.getBase().getString("FirstTimeWizardToadlet.bandwidthPerSecond").toLowerCase()
"/s", "/sec", "/second", "ps", NodeL10n.getBase().getString("FirstTimeWizardToadlet.bandwidthPerSecond").toLowerCase()
}) {
if(lower.endsWith(ending)) {
return limit.substring(0, limit.length() - ending.length());
Expand All @@ -732,11 +732,16 @@ public static int parseInt(String s, Dimension dimension) throws NumberFormatExc

/**
* Parse a human-readable string possibly including SI and ICE units into an integer.
*
* If it is a size (suffix b für bits or B for bytes), the size is returned as bytes.
* 8b = 1, 8B = 8.
* @throws NumberFormatException
* if the string is not parseable
*/
public static int parseInt(String s) throws NumberFormatException {
s = s.replaceFirst("(i)*B$", "");
boolean isSizeInBits = s.endsWith("b");
// strip bit/byte suffix
s = s.replaceFirst((isSizeInBits ? "(i)*b$" : "(i)*B$"), "");
int res = 1;
int x = s.length() - 1;
int idx;
Expand All @@ -750,7 +755,7 @@ public static int parseInt(String s) throws NumberFormatException {
res = Integer.MAX_VALUE;
throw new NumberFormatException(e.getMessage());
}
return res;
return isSizeInBits ? res / 8 : res;
}

/**
Expand Down

0 comments on commit 2456302

Please sign in to comment.