Skip to content

Commit

Permalink
Replace empty string with constant
Browse files Browse the repository at this point in the history
  • Loading branch information
rbergen committed Dec 6, 2023
1 parent 838b203 commit 9fcee0d
Show file tree
Hide file tree
Showing 27 changed files with 87 additions and 75 deletions.
4 changes: 4 additions & 0 deletions docs/Changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ x: Bugfix

=========================================

0.5.1.0 (2023-12-06)
* Moved to .NET 8.0
* Use string.Empty for empty strings

0.5.0.0 (2021-12-04)
* Moved to .NET 6.0
* Switched to deterministic versioning
Expand Down
18 changes: 9 additions & 9 deletions src/MixAssembler/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ private static ParsedSourceLine ParseLine(string sourceLine, ParsingStatus statu
lineFields[OpFieldIndex] = lineFields[OpFieldIndex].ToUpper();
lineFields[AddressFieldIndex] = lineFields[AddressFieldIndex].ToUpper();

if (lineFields[OpFieldIndex] == "")
if (lineFields[OpFieldIndex] == string.Empty)
{
status.ReportParsingError(LineSection.LocationField, 0, sourceLine.Length, "op and address fields are missing");

return new ParsedSourceLine(status.LineNumber, lineFields[0], "", "", "", null, null);
return new ParsedSourceLine(status.LineNumber, lineFields[0], string.Empty, string.Empty, string.Empty, null, null);
}

var symbol = ParseLocField(lineFields[LocFieldIndex], status);
Expand All @@ -170,7 +170,7 @@ private static ParsedSourceLine ParseLine(string sourceLine, ParsingStatus statu

private static SymbolBase ParseLocField(string locField, ParsingStatus status)
{
if (locField == "")
if (locField == string.Empty)
return null;

status.LineSection = LineSection.LocationField;
Expand Down Expand Up @@ -249,23 +249,23 @@ private static string[] SplitLine(string sourceLine)
var searchBeyondIndex = FindFirstWhiteSpace(sourceLine, -1);

if (searchBeyondIndex == -1)
return new string[] { sourceLine, "", "", "" };
return new string[] { sourceLine, string.Empty, string.Empty, string.Empty };

var opFieldStart = FindFirstNonWhiteSpace(sourceLine, searchBeyondIndex);

if (opFieldStart == -1)
return new string[] { sourceLine.Substring(0, searchBeyondIndex), "", "", "" };
return new string[] { sourceLine.Substring(0, searchBeyondIndex), string.Empty, string.Empty, string.Empty };

var opFieldEnd = FindFirstWhiteSpace(sourceLine, opFieldStart);

if (opFieldEnd == -1)
return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine[opFieldStart..], "", "" };
return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine[opFieldStart..], string.Empty, string.Empty };

int opFieldLength = opFieldEnd - opFieldStart;
var addressFieldStart = FindFirstNonWhiteSpace(sourceLine, opFieldEnd);

if (addressFieldStart == -1)
return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine.Substring(opFieldStart, opFieldLength), "", "" };
return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine.Substring(opFieldStart, opFieldLength), string.Empty, string.Empty };

if (sourceLine[addressFieldStart] == '"')
{
Expand All @@ -280,13 +280,13 @@ private static string[] SplitLine(string sourceLine)
addressFieldEnd = FindFirstWhiteSpace(sourceLine, addressFieldStart);

if (addressFieldEnd == -1)
return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine.Substring(opFieldStart, opFieldLength), sourceLine[addressFieldStart..], "" };
return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine.Substring(opFieldStart, opFieldLength), sourceLine[addressFieldStart..], string.Empty };

int addressFieldLength = addressFieldEnd - addressFieldStart;
var commentFieldStart = FindFirstNonWhiteSpace(sourceLine, addressFieldEnd);

if (commentFieldStart == -1)
return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine.Substring(opFieldStart, opFieldLength), sourceLine.Substring(addressFieldStart, addressFieldLength), "" };
return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine.Substring(opFieldStart, opFieldLength), sourceLine.Substring(addressFieldStart, addressFieldLength), string.Empty };

return new string[] { sourceLine.Substring(0, searchBeyondIndex), sourceLine.Substring(opFieldStart, opFieldLength), sourceLine.Substring(addressFieldStart, addressFieldLength), sourceLine[commentFieldStart..] };
}
Expand Down
2 changes: 1 addition & 1 deletion src/MixAssembler/Symbol/LiteralConstantSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override bool IsValueDefined(int currentAddress)
=> this.valueDefined;

private static string GetName(Word.Signs literalSign, long literalMagnitude, int count)
=> string.Concat("=", literalSign.IsNegative() ? "-" : "", literalMagnitude, '=', count);
=> string.Concat("=", literalSign.IsNegative() ? "-" : string.Empty, literalMagnitude, '=', count);

public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus status)
{
Expand Down
2 changes: 1 addition & 1 deletion src/MixEmul/Components/AssemblyFindingListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private void SelectedIndexChanged(object sender, EventArgs e)

private void AddFinding(AssemblyFinding finding)
{
var item = new ListViewItem(new string[] { finding.Severity.ToString(), (finding.LineNumber == int.MinValue) ? "" : (finding.LineNumber + 1).ToString(), finding.Message }, (int)finding.Severity)
var item = new ListViewItem(new string[] { finding.Severity.ToString(), (finding.LineNumber == int.MinValue) ? string.Empty : (finding.LineNumber + 1).ToString(), finding.Message }, (int)finding.Severity)
{
Tag = finding
};
Expand Down
6 changes: 3 additions & 3 deletions src/MixEmul/Components/DeviceStatusControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public DeviceStatusControl(MixDevice device)
this.statusLabel.Name = "mStatusLabel";
this.statusLabel.Size = new Size(32, 16);
this.statusLabel.TabIndex = 1;
this.statusLabel.Text = "";
this.statusLabel.Text = string.Empty;
this.statusLabel.TextAlign = ContentAlignment.MiddleCenter;
this.statusLabel.DoubleClick += Control_DoubleClick;

Expand Down Expand Up @@ -89,9 +89,9 @@ private void ResetMenuItem_Click(object sender, EventArgs e)
{
SuspendLayout();

this.indexLabel.Text = "";
this.indexLabel.Text = string.Empty;
this.statusLabel.BackColor = Color.Gray;
this.statusLabel.Text = "";
this.statusLabel.Text = string.Empty;
ToolTip?.SetToolTip(this.statusLabel, "No device connected");

this.inputMenuItem.Checked = false;
Expand Down
10 changes: 5 additions & 5 deletions src/MixEmul/Components/InstructionInstanceTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private void ShowAddressMenuItem_Click(object sender, EventArgs e)

private void AddTextElement(string element, bool markAsError)
{
if (element == "")
if (element == string.Empty)
return;

int textLength = TextLength;
Expand All @@ -143,12 +143,12 @@ private void AddTextElement(string element, bool markAsError)

private string GetAssemblyErrorsCaption(ParsedSourceLine line, AssemblyFindingCollection findings)
{
string caption = "";
string caption = string.Empty;
int findingNumber = 1;

foreach (AssemblyFinding finding in findings)
{
string fieldLabel = "";
string fieldLabel = string.Empty;

if (finding.Severity == Severity.Error)
{
Expand Down Expand Up @@ -249,7 +249,7 @@ private bool CheckContentsEditable()
if (ReadOnly || !this.noInstructionRendered && !this.instructionWord.IsEmpty)
return true;

base.Text = "";
base.Text = string.Empty;
SetEditMode();

return false;
Expand Down Expand Up @@ -438,7 +438,7 @@ private void HandleNoInstruction(string caption)
var text = new InstructionText(instance);

SuspendLayout();
base.Text = "";
base.Text = string.Empty;

ForeColor = this.lastRenderedSourceLine != null ? this.loadedInstructionTextColor : this.renderedTextColor;
AddTextElement(text.Mnemonic + " ", false);
Expand Down
11 changes: 9 additions & 2 deletions src/MixEmul/Components/LogListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ public LogListView()
}

public void AddLogLine(LogLine line)
=> this.listView.Items.Insert(0, new ListViewItem(new string[] { line.Severity.ToString(), line.ModuleName ?? "", (line.Address == -1) ? "" : line.Address.ToString("D4"), line.Title ?? "", line.Message ?? "" }, (int)line.Severity));
=> this.listView.Items.Insert(0, new ListViewItem(new string[]
{
line.Severity.ToString(),
line.ModuleName ?? string.Empty,
(line.Address == -1) ? string.Empty : line.Address.ToString("D4"),
line.Title ?? string.Empty,
line.Message ?? string.Empty
}, (int)line.Severity));

protected virtual void OnAddressSelected(AddressSelectedEventArgs args)
=> AddressSelected?.Invoke(this, args);
Expand Down Expand Up @@ -122,7 +129,7 @@ public int SelectedAddress
{
ListView.SelectedListViewItemCollection selectedItems = this.listView.SelectedItems;

if (selectedItems.Count == 0 || selectedItems[0].SubItems[AddressFieldIndex].Text == "")
if (selectedItems.Count == 0 || selectedItems[0].SubItems[AddressFieldIndex].Text == string.Empty)
return NoAddress;

int address = NoAddress;
Expand Down
6 changes: 3 additions & 3 deletions src/MixEmul/Components/LongValueTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private void This_Leave(object sender, EventArgs e)
private void LongValueTextBox_Enter(object sender, EventArgs e)
{
if (ClearZero && this.magnitude == 0 && this.sign.IsPositive())
base.Text = "";
base.Text = string.Empty;
}

private void This_KeyDown(object sender, KeyEventArgs e)
Expand Down Expand Up @@ -122,7 +122,7 @@ private void CheckAndUpdateValue(string newValue)
long magnitude = 0;
Word.Signs sign = Word.Signs.Positive;

if (newValue == "" || newValue == "-")
if (newValue == string.Empty || newValue == "-")
{
if (MinValue > 0)
magnitude = MinValue;
Expand Down Expand Up @@ -311,7 +311,7 @@ private void This_TextChanged(object sender, EventArgs e)
try
{
string text = Text;
if (text != "" && (!SupportSign || text != "-"))
if (text != string.Empty && (!SupportSign || text != "-"))
{
var num = long.Parse(text);
textIsValid = ((num >= MinValue) && (num <= MaxValue)) && (SupportSign || (num >= 0L));
Expand Down
2 changes: 1 addition & 1 deletion src/MixEmul/Components/MixByteCollectionCharTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private void This_TextChanged(object sender, EventArgs e)
if (this.updating)
return;

string validText = "";
string validText = string.Empty;

foreach (var c in Text.Where(c => MixByte.MixChars.Contains(c)))
validText += c;
Expand Down
4 changes: 2 additions & 2 deletions src/MixEmul/Components/MixByteTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void CheckAndUpdateValue(string newValue)
{
try
{
CheckAndUpdateValue(newValue == "" ? (byte)0 : byte.Parse(newValue));
CheckAndUpdateValue(newValue == string.Empty ? (byte)0 : byte.Parse(newValue));
}
catch (FormatException) { }
}
Expand Down Expand Up @@ -137,7 +137,7 @@ private void This_TextChanged(object sender, EventArgs e)
{
string text = Text;

if (text != "")
if (text != string.Empty)
{
var byteValue = byte.Parse(text);
textIsValid = byteValue >= 0 && byteValue <= MixByte.MaxValue;
Expand Down
2 changes: 1 addition & 1 deletion src/MixEmul/Components/PreferencesForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ private void UpdateDeviceFileControls(DeviceFileComboBoxItem item)
{
if (item == null)
{
this.deviceFileBox.Text = "";
this.deviceFileBox.Text = string.Empty;
this.deviceFileSetButton.Enabled = false;
this.deviceFileDefaultButton.Enabled = false;
}
Expand Down
6 changes: 3 additions & 3 deletions src/MixEmul/Components/RegistersEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public RegistersEditor(MixLib.Registers registers = null)
this.compareButton.Size = new Size(18, 21);
this.compareButton.Location = new Point((this.rAEditor.Left + this.rAEditor.Width) - this.compareButton.Width, this.rJEditor.Top);
this.compareButton.TabIndex = 21;
this.compareButton.Text = "" + this.registers.CompareIndicator.ToChar();
this.compareButton.Text = this.registers.CompareIndicator.ToChar().ToString();
this.compareButton.Click += CompareButton_Click;

this.overflowLabel.Location = new Point(Math.Min(this.compareButton.Left, this.overflowBox.Left) - Math.Max(this.compareLabel.Width, this.overflowLabel.Width), this.overflowBox.Top);
Expand Down Expand Up @@ -273,15 +273,15 @@ private void CompareButton_Click(object sender, EventArgs e)
{
var compValue = this.registers.CompareIndicator.Next();
this.registers.CompareIndicator = compValue;
this.compareButton.Text = "" + compValue.ToChar();
this.compareButton.Text = compValue.ToChar().ToString();
}

public new void Update()
{
foreach (WordValueEditor editor in this.editors)
editor.Update();

this.compareButton.Text = "" + this.registers.CompareIndicator.ToChar();
this.compareButton.Text = this.registers.CompareIndicator.ToChar().ToString();
this.overflowBox.Checked = this.registers.OverflowIndicator;

base.Update();
Expand Down
2 changes: 1 addition & 1 deletion src/MixEmul/Components/SearchDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void FillControls()
}
else
{
this.searchTextBox.Text = "";
this.searchTextBox.Text = string.Empty;
this.valueCheckBox.Checked = true;
this.charsCheckBox.Checked = true;
this.instructionCheckBox.Checked = true;
Expand Down
10 changes: 5 additions & 5 deletions src/MixEmul/Components/SourceCodeControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public SourceCodeControl()
this.sourceBox.ReadOnly = true;
this.sourceBox.Size = Size;
this.sourceBox.TabIndex = 0;
this.sourceBox.Text = "";
this.sourceBox.Text = string.Empty;
this.sourceBox.DetectUrls = false;

Controls.Add(this.sourceBox);
Expand Down Expand Up @@ -279,7 +279,7 @@ public PreInstruction[] Instructions
set
{
this.markedFinding = null;
this.sourceBox.Text = "";
this.sourceBox.Text = string.Empty;
this.instructions.Clear();
this.findingsColored = false;

Expand All @@ -306,7 +306,7 @@ public PreInstruction[] Instructions
{
while (parsedLine.LineNumber > this.instructions.Count)
{
AddLine(new ParsedSourceLine(this.instructions.Count, ""));
AddLine(new ParsedSourceLine(this.instructions.Count, string.Empty));
}

AddLine(parsedLine);
Expand Down Expand Up @@ -352,7 +352,7 @@ public ProcessedSourceLine(ParsedSourceLine sourceLine, int lineTextIndex)
!SourceLine.IsCommentLine ? AddressTextIndex + AddressTextLength + Parser.FieldSpacing : LineTextIndex;

public int LineTextLength =>
(SourceLine.Comment == "" ? AddressTextIndex + AddressTextLength : CommentTextIndex + SourceLine.Comment.Length) - LineTextIndex;
(SourceLine.Comment == string.Empty ? AddressTextIndex + AddressTextLength : CommentTextIndex + SourceLine.Comment.Length) - LineTextIndex;

public int LocTextIndex
=> LineTextIndex;
Expand All @@ -376,7 +376,7 @@ public int AddressTextLength
if (SourceLine.IsCommentLine)
return 0;

if (SourceLine.Comment != "")
if (SourceLine.Comment != string.Empty)
return Math.Max(Parser.MinAddressLength, SourceLine.AddressField.Length);

return SourceLine.AddressField.Length;
Expand Down
4 changes: 2 additions & 2 deletions src/MixEmul/Components/SymbolListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public SymbolCollection Symbols

this.listView.BeginUpdate();
this.listView.Items.Clear();
this.symbolNameTextBox.Text = "";
this.symbolValueTextBox.Text = "";
this.symbolNameTextBox.Text = string.Empty;
this.symbolValueTextBox.Text = string.Empty;

if (this.symbols != null)
{
Expand Down
6 changes: 3 additions & 3 deletions src/MixEmul/Components/TeletypeForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public void ClearOutput()
return;
}

this.outputTextBox.Text = "";
this.outputTextBox.Text = string.Empty;
}

private void MOnTopCheckBox_CheckedChanged(object sender, EventArgs e) => TopMost = this.onTopCheckBox.Checked;
Expand All @@ -247,7 +247,7 @@ private void OutputAdded(object sender, EventArgs e)
}

string outputLine;
string textToAdd = "";
string textToAdd = string.Empty;

while ((outputLine = this.teletypeDevice.GetOutputLine()) != null)
{
Expand Down Expand Up @@ -276,7 +276,7 @@ private void SendInput()
AddOutputText("> " + this.inputTextBox.Text);

this.teletypeDevice.AddInputLine(this.inputTextBox.Text);
this.inputTextBox.Text = "";
this.inputTextBox.Text = string.Empty;
this.toolStripStatusLabel.Text = "Sent input to Mix";
}

Expand Down
4 changes: 2 additions & 2 deletions src/MixEmul/Components/ToolStripCycleButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ToolStripCycleButton(IContainer container) : this()
=> container.Add(this);

public ToolStripCycleButton()
: base(new Button { Text = "", FlatStyle = FlatStyle.Flat, Height = 21, Padding = new Padding(0), TextAlign = ContentAlignment.TopCenter })
: base(new Button { Text = string.Empty, FlatStyle = FlatStyle.Flat, Height = 21, Padding = new Padding(0), TextAlign = ContentAlignment.TopCenter })
{
InitializeComponent();
this.steps = new List<Step>();
Expand All @@ -31,7 +31,7 @@ public ToolStripCycleButton()
Control.SizeChanged += Control_SizeChanged;
Control.Click += Control_Click;
Control.Paint += ToolStripCycleButton_Paint;
Text = "";
Text = string.Empty;
}

protected void OnValueChanged(EventArgs e)
Expand Down
Loading

0 comments on commit 9fcee0d

Please sign in to comment.