Fix TargetString stuck when length was 0. Add TargetString.TrustedAsArray.
This commit is contained in:
@@ -18,9 +18,9 @@ namespace Cryville.Common.Buffers {
|
|||||||
/// Creates an instance of the <see cref="TargetString" /> class.
|
/// Creates an instance of the <see cref="TargetString" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="capacity">The initial capacity of the string.</param>
|
/// <param name="capacity">The initial capacity of the string.</param>
|
||||||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="capacity" /> is less than 0.</exception>
|
/// <exception cref="ArgumentOutOfRangeException"><paramref name="capacity" /> is less than or equal to 0.</exception>
|
||||||
public TargetString(int capacity) {
|
public TargetString(int capacity) {
|
||||||
if (capacity < 0) throw new ArgumentOutOfRangeException("capacity");
|
if (capacity <= 0) throw new ArgumentOutOfRangeException("capacity");
|
||||||
_arr = new char[capacity];
|
_arr = new char[capacity];
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -60,7 +60,7 @@ namespace Cryville.Common.Buffers {
|
|||||||
if (Length < 0) throw new ArgumentOutOfRangeException("length");
|
if (Length < 0) throw new ArgumentOutOfRangeException("length");
|
||||||
if (m_length == value) return;
|
if (m_length == value) return;
|
||||||
if (_arr.Length < value) {
|
if (_arr.Length < value) {
|
||||||
var len = m_length;
|
var len = _arr.Length;
|
||||||
while (len < value) len *= 2;
|
while (len < value) len *= 2;
|
||||||
var arr2 = new char[len];
|
var arr2 = new char[len];
|
||||||
Array.Copy(_arr, arr2, m_length);
|
Array.Copy(_arr, arr2, m_length);
|
||||||
@@ -79,6 +79,7 @@ namespace Cryville.Common.Buffers {
|
|||||||
var ev = OnUpdate;
|
var ev = OnUpdate;
|
||||||
if (ev != null) ev.Invoke();
|
if (ev != null) ev.Invoke();
|
||||||
}
|
}
|
||||||
|
internal char[] TrustedAsArray() { return _arr; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns an enumerator that iterates through the <see cref="TargetString" />.
|
/// Returns an enumerator that iterates through the <see cref="TargetString" />.
|
||||||
|
|||||||
Reference in New Issue
Block a user