Skip to content

Commit

Permalink
Made IAppendable methods an explicit IAppendable declaration and ensu…
Browse files Browse the repository at this point in the history
…red consistency using count instead of length in Append overloads
  • Loading branch information
Michael Condillac committed Apr 15, 2020
1 parent d76c733 commit 1734427
Showing 1 changed file with 71 additions and 12 deletions.
83 changes: 71 additions & 12 deletions src/Lucene.Net.Analysis.Common/Analysis/Util/OpenStringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ namespace Lucene.Net.Analysis.Util
/// <summary>
/// A StringBuilder that allows one to access the array.
/// </summary>
public class OpenStringBuilder : ICharSequence
public class OpenStringBuilder : IAppendable, ICharSequence
{
protected char[] m_buf;
protected int m_len;

public OpenStringBuilder()
public OpenStringBuilder()
: this(32)
{
}
Expand Down Expand Up @@ -73,15 +73,15 @@ public virtual void Set(char[] arr, int end)

public virtual int Capacity => m_buf.Length;

public virtual OpenStringBuilder Append(ICharSequence csq)
public virtual OpenStringBuilder Append(ICharSequence csq)
{
return Append(csq, 0, csq.Length);
}

public virtual OpenStringBuilder Append(ICharSequence csq, int startIndex, int length) // LUCENENET TODO: API - change to startIndex/length to match .NET
public virtual OpenStringBuilder Append(ICharSequence csq, int startIndex, int count) // LUCENENET TODO: API - change to startIndex/length to match .NET
{
EnsureCapacity(length - startIndex);
for (int i = startIndex; i < length; i++)
EnsureCapacity(count - startIndex);
for (int i = startIndex; i < count; i++)
{
UnsafeWrite(csq[i]);
}
Expand All @@ -95,10 +95,10 @@ public virtual OpenStringBuilder Append(string csq)
}

// LUCENENET specific - overload for string (more common in .NET than ICharSequence)
public virtual OpenStringBuilder Append(string csq, int startIndex, int length) // LUCENENET TODO: API - change to startIndex/length to match .NET
public virtual OpenStringBuilder Append(string csq, int startIndex, int count) // LUCENENET TODO: API - change to startIndex/length to match .NET
{
EnsureCapacity(length - startIndex);
for (int i = startIndex; i < length; i++)
EnsureCapacity(count - startIndex);
for (int i = startIndex; i < count; i++)
{
UnsafeWrite(csq[i]);
}
Expand All @@ -112,10 +112,10 @@ public virtual OpenStringBuilder Append(StringBuilder csq)
}

// LUCENENET specific - overload for StringBuilder
public virtual OpenStringBuilder Append(StringBuilder csq, int startIndex, int length) // LUCENENET TODO: API - change to startIndex/length to match .NET
public virtual OpenStringBuilder Append(StringBuilder csq, int startIndex, int count) // LUCENENET TODO: API - change to startIndex/length to match .NET
{
EnsureCapacity(length - startIndex);
for (int i = startIndex; i < length; i++)
EnsureCapacity(count - startIndex);
for (int i = startIndex; i < count; i++)
{
UnsafeWrite(csq[i]);
}
Expand All @@ -128,6 +128,20 @@ public virtual OpenStringBuilder Append(char c)
return this;
}

public virtual OpenStringBuilder Append(char[] value)
{
Write(value);
return this;
}
public virtual OpenStringBuilder Append(char[] value, int startIndex, int count)
{
EnsureCapacity(count - startIndex);
for (int i = startIndex; i < count; i++)
{
UnsafeWrite(value[i]);
}
return this;
}
// LUCENENET specific - removed (replaced with this[])
//public virtual char CharAt(int index)
//{
Expand Down Expand Up @@ -270,5 +284,50 @@ public override string ToString()
{
return new string(m_buf, 0, Length);
}

IAppendable IAppendable.Append(char value)
{
return Append(value);
}

IAppendable IAppendable.Append(string value)
{
return Append(value);
}

IAppendable IAppendable.Append(string value, int startIndex, int count)
{
return Append(value, startIndex, count);
}

IAppendable IAppendable.Append(StringBuilder value)
{
return Append(value);
}

IAppendable IAppendable.Append(StringBuilder value, int startIndex, int count)
{
return Append(value, startIndex, count);
}

IAppendable IAppendable.Append(char[] value)
{
return Append(value);
}

IAppendable IAppendable.Append(char[] value, int startIndex, int count)
{
return Append(value, startIndex, count);
}

IAppendable IAppendable.Append(ICharSequence value)
{
return Append(value);
}

IAppendable IAppendable.Append(ICharSequence value, int startIndex, int count)
{
return Append(value, startIndex, count);
}
}
}

0 comments on commit 1734427

Please sign in to comment.