Function BasicString.insert

Inserts additional characters into the BasicString right before the character indicated by pos or ptr.

size_t insert (
  const size_t pos,
  scope const BasicString.CharType[] val,
  const size_t count = 1
) scope;

size_t insert(Val) (
  const size_t pos,
  auto scope const ref Val val,
  const size_t count = 1
) scope
if (isBasicString!Val || isSomeChar!Val || isSomeString!Val || isIntegral!Val);

size_t insert (
  const BasicString.CharType* ptr,
  scope const BasicString.CharType[] val,
  const size_t count = 1
) scope;

size_t insert(Val) (
  const BasicString.CharType* ptr,
  auto scope const ref Val val,
  const size_t count = 1
) scope
if (isBasicString!Val || isSomeChar!Val || isSomeString!Val || isIntegral!Val);

Return number of inserted characters.

If parameters are out of range then there is no inserted value and in debug mode assert throw error.

Parameters are out of range if pos is larger then .length or ptr is smaller then this.ptr or ptr point to address larger then this.ptr + this.length

Parameters

pos Insertion point, the new contents are inserted before the character at position pos.

ptr Pointer pointing to the insertion point, the new contents are inserted before the character pointed by ptr.

val Value inserted before insertion point pos or ptr.

count Number of times val is inserted.

Examples

{
	BasicString!char str = "123456";

	str.insert(2, 'x', 2);
	assert(str == "12xx3456");
}

{
	BasicString!char str = "123456";

	str.insert(2, "abc");
	assert(str == "12abc3456");
}

{
	BasicString!char str = "123456";
	BasicString!char str2 = "abc";

	str.insert(2, str2);
	assert(str == "12abc3456");
}

{
	BasicString!char str = "123456";

	str.insert(str.ptr + 2, 'x', 2);
	assert(str == "12xx3456");
}

{
	BasicString!char str = "123456";

	str.insert(str.ptr + 2, "abc");
	assert(str == "12abc3456");
}

{
	BasicString!char str = "123456";
	BasicString!char str2 = "abc";

	str.insert(str.ptr + 2, str2);
	assert(str == "12abc3456");
}