moved toString() back to SubLine

This commit is contained in:
Denis Molony 2021-05-06 08:26:47 +10:00
parent c3ee00673d
commit 76b2d4a291
2 changed files with 44 additions and 108 deletions

View File

@ -1,7 +1,5 @@
package com.bytezone.diskbrowser.applefile;
import static com.bytezone.diskbrowser.utilities.Utility.isControlCharacter;
// ---------------------------------------------------------------------------------//
class Alignment implements ApplesoftConstants
// ---------------------------------------------------------------------------------//
@ -34,8 +32,6 @@ class Alignment implements ApplesoftConstants
void check (SubLine subline)
// ---------------------------------------------------------------------------------//
{
// System.out.printf ("%-20s %d %d%n", subline, subline.equalsPosition,
// subline.endPosition - subline.equalsPosition);
if (equalsPosition < subline.equalsPosition)
equalsPosition = subline.equalsPosition;
@ -50,7 +46,7 @@ class Alignment implements ApplesoftConstants
public String getAlignedText (SubLine subline)
// ---------------------------------------------------------------------------------//
{
StringBuilder line = toStringBuilder (subline); // get line
StringBuilder line = subline.toStringBuilder (); // get line
if (equalsPosition == 0 || subline.is (TOKEN_REM))
return line.toString ();
@ -69,41 +65,6 @@ class Alignment implements ApplesoftConstants
return line.toString ();
}
// ---------------------------------------------------------------------------------//
static StringBuilder toStringBuilder (SubLine subline)
// ---------------------------------------------------------------------------------//
{
StringBuilder line = new StringBuilder ();
// All sublines end with 0 or : except IF lines that are split into two
int max = subline.startPtr + subline.length - 1;
if (subline.buffer[max] == 0)
--max;
if (subline.isImpliedGoto () && !ApplesoftBasicProgram.basicPreferences.showThen)
line.append ("GOTO ");
for (int p = subline.startPtr; p <= max; p++)
{
byte b = subline.buffer[p];
if (subline.isToken (b))
{
if (line.length () > 0 && line.charAt (line.length () - 1) != ' ')
line.append (' ');
int val = b & 0x7F;
if (b != TOKEN_THEN || ApplesoftBasicProgram.basicPreferences.showThen)
line.append (ApplesoftConstants.tokens[val] + " ");
}
// else if (Utility.isControlCharacter (b))
// line.append (ApplesoftBasicProgram.basicPreferences.showCaret
// ? "^" + (char) (b + 64) : "?");
else if (!isControlCharacter (b))
line.append ((char) b);
}
return line;
}
// ---------------------------------------------------------------------------------//
@Override
public String toString ()
@ -113,10 +74,8 @@ class Alignment implements ApplesoftConstants
text.append (String.format ("Equals position ..... %d%n", equalsPosition));
text.append (String.format ("Target length ....... %d%n", targetLength));
text.append (
String.format ("First subline ....... %s%n", toStringBuilder (firstSubLine)));
text.append (
String.format ("Last subline ........ %s", toStringBuilder (lastSubLine)));
text.append (String.format ("First subline ....... %s%n", firstSubLine));
text.append (String.format ("Last subline ........ %s", lastSubLine));
return text.toString ();
}

View File

@ -12,6 +12,7 @@ import static com.bytezone.diskbrowser.utilities.Utility.ASCII_PERCENT;
import static com.bytezone.diskbrowser.utilities.Utility.ASCII_QUOTE;
import static com.bytezone.diskbrowser.utilities.Utility.ASCII_RIGHT_BRACKET;
import static com.bytezone.diskbrowser.utilities.Utility.getIndent;
import static com.bytezone.diskbrowser.utilities.Utility.isControlCharacter;
import static com.bytezone.diskbrowser.utilities.Utility.isDigit;
import static com.bytezone.diskbrowser.utilities.Utility.isHighBitSet;
import static com.bytezone.diskbrowser.utilities.Utility.isLetter;
@ -465,8 +466,7 @@ public class SubLine implements ApplesoftConstants
while (++p < max)
if (buffer[p] == TOKEN_EQUALS)
{
// String expandedLine = toString ();
String expandedLine = Alignment.toStringBuilder (this).toString ();
String expandedLine = toString ();
equalsPosition = expandedLine.indexOf ('=');
endPosition = expandedLine.length ();
if (expandedLine.endsWith (":"))
@ -613,29 +613,6 @@ public class SubLine implements ApplesoftConstants
return false;
}
// ---------------------------------------------------------------------------------//
// public String getAlignedText (ApplesoftFormatter alignment)
// // ---------------------------------------------------------------------------------//
// {
// StringBuilder line = toStringBuilder (); // get line
//
// if (alignment.equalsPosition == 0 || is (TOKEN_REM))
// return line.toString ();
//
// int alignEqualsPos = alignment.equalsPosition;
// int targetLength = endPosition - equalsPosition;
//
// // insert spaces before '=' until it lines up with the other assignment lines
// while (alignEqualsPos-- > equalsPosition)
// line.insert (equalsPosition, ' ');
//
// if (line.charAt (line.length () - 1) == ':')
// while (targetLength++ <= alignment.targetLength)
// line.append (" ");
//
// return line.toString ();
// }
// ---------------------------------------------------------------------------------//
public byte[] getBuffer ()
// ---------------------------------------------------------------------------------//
@ -713,45 +690,45 @@ public class SubLine implements ApplesoftConstants
}
// ---------------------------------------------------------------------------------//
// private StringBuilder toStringBuilder ()
// // ---------------------------------------------------------------------------------//
// {
// StringBuilder line = new StringBuilder ();
//
// // All sublines end with 0 or : except IF lines that are split into two
// int max = startPtr + length - 1;
// if (buffer[max] == 0)
// --max;
//
// if (isImpliedGoto () && !ApplesoftBasicProgram.basicPreferences.showThen)
// line.append ("GOTO ");
//
// for (int p = startPtr; p <= max; p++)
// {
// byte b = buffer[p];
// if (isToken (b))
// {
// if (line.length () > 0 && line.charAt (line.length () - 1) != ' ')
// line.append (' ');
// int val = b & 0x7F;
// if (b != TOKEN_THEN || ApplesoftBasicProgram.basicPreferences.showThen)
// line.append (ApplesoftConstants.tokens[val] + " ");
// }
// // else if (Utility.isControlCharacter (b))
// // line.append (ApplesoftBasicProgram.basicPreferences.showCaret
// // ? "^" + (char) (b + 64) : "?");
// else if (!isControlCharacter (b))
// line.append ((char) b);
// }
//
// return line;
// }
StringBuilder toStringBuilder ()
// ---------------------------------------------------------------------------------//
{
StringBuilder line = new StringBuilder ();
// All sublines end with 0 or : except IF lines that are split into two
int max = startPtr + length - 1;
if (buffer[max] == 0)
--max;
if (isImpliedGoto () && !ApplesoftBasicProgram.basicPreferences.showThen)
line.append ("GOTO ");
for (int p = startPtr; p <= max; p++)
{
byte b = buffer[p];
if (isToken (b))
{
if (line.length () > 0 && line.charAt (line.length () - 1) != ' ')
line.append (' ');
int val = b & 0x7F;
if (b != TOKEN_THEN || ApplesoftBasicProgram.basicPreferences.showThen)
line.append (ApplesoftConstants.tokens[val] + " ");
}
// else if (Utility.isControlCharacter (b))
// line.append (ApplesoftBasicProgram.basicPreferences.showCaret
// ? "^" + (char) (b + 64) : "?");
else if (!isControlCharacter (b))
line.append ((char) b);
}
return line;
}
// ---------------------------------------------------------------------------------//
// @Override
// public String toString ()
// // ---------------------------------------------------------------------------------//
// {
// return toStringBuilder ().toString ();
// }
@Override
public String toString ()
// ---------------------------------------------------------------------------------//
{
return toStringBuilder ().toString ();
}
}