Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented IAppendable as per J2N #240

Merged
merged 1 commit into from
Apr 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}