Remove trailing whitespace and clean up comments

This commit is contained in:
2025-12-10 13:50:02 -05:00
parent 1870e87a9c
commit 36b54929d0
5 changed files with 64 additions and 81 deletions

View File

@@ -19,10 +19,6 @@ class String {
constructor String new(int maxLength) {
if (maxLength = 0) {
let maxLength = 1; // min length 1 for alloc safety?
// Actually spec says allocation of 0 size might happen.
// My Array.new -> Memory.alloc handles 0 size by returning a 1 word block (header-1?? No).
// Let's alloc 0 if needed.
// If maxLength is 0, we can't really store anything.
}
if (maxLength > 0) {
let buffer = Array.new(maxLength);
@@ -74,23 +70,23 @@ class String {
return;
}
/** Returns the integer value of this string,
/** Returns the integer value of this string,
* until a non-digit character is detected. */
method int intValue() {
var int val, i, d;
var boolean neg;
let val = 0;
let i = 0;
let neg = false;
if (length > 0) {
if (buffer[0] = 45) { // '-'
let neg = true;
let i = 1;
}
}
while (i < length) {
let d = buffer[i] - 48; // '0' is 48
if ((d > -1) & (d < 10)) {
@@ -100,7 +96,7 @@ class String {
let i = length; // break
}
}
if (neg) {
return -val;
}
@@ -110,24 +106,24 @@ class String {
/** Sets this string to hold a representation of the given value. */
method void setInt(int val) {
let length = 0; // Clear string
if (val < 0) {
let val = -val;
do appendChar(45); // '-'
}
do int2String(val);
return;
}
// Helper for recursive int printing
method void int2String(int val) {
var int lastDigit;
var int c;
let lastDigit = val - ((val / 10) * 10); // val % 10
let c = lastDigit + 48;
if (val < 10) {
do appendChar(c);
} else {