src/Generic/common/LocatedString.cpp
/**
 * All the offsets for the new text are set to the offset of the
 * character immediately to the left, or immediately to the right
 * if the text is replaced at the beginning of the string (i.e.,
 * if <code>pos == 0</code>).
 *
 * For example:
 *
 * <pre>    ["six miles", {100,101,102,103,104,105,106,107,108}].replace(1, 2, "even")
 *    =>
 *    ["seven miles", {100,100,100,100,100,103,104,105,106,107,108}]</pre>
 *
 * <pre>    ["six miles", {100,101,102,103,104,105,106,107,108}].replace(0, 3, "ten")
 *    =>
 *    ["ten miles", {103,103,103,103,104,105,106,107,108}]</pre>
 *
 * @param pos the position at which to replace text.
 * @param len the number of characters to remove.
 * @param repl the text to replace characters with.
 */
All the offsets for the new text are set to the offset of the
character immediately to the left, or immediately to the right
if the text is replaced at the beginning of the string .

For example.





@param pos the position at which to replace text.
@param len the number of characters to remove.
@param repl the text to replace characters with.
All the offsets for the new text are set to the offset of the character immediately to the left or immediately to the right if the text is replaced at the beginning of the string . For example . @param pos the position at which to replace text . @param len the number of characters to remove . @param repl the text to replace characters with .
void LocatedString::replace(int pos, int len, const wchar_t *repl) {
	if (len <= 0)
		throw InternalInconsistencyException("LocatedString::replace()",
									   "negative length parameter");
	if ((pos + len) > length())
		throw InternalInconsistencyException::arrayIndexException(
			"LocatedString::replace()", length(), (pos + len));
	OffsetRange new_offset;
	if (length() > 0)
		new_offset = OffsetRange(startOffsetGroup(pos), endOffsetGroup(pos+len-1));
	remove(pos, pos+len);
	insert(repl, pos, new_offset);
}
void LocatedString :: replace ( int pos , int len , const wchar_t * repl ) { if ( len <= 0 ) throw InternalInconsistencyException ( " " , " " ) ; if ( ( pos + len ) > length ( ) ) throw InternalInconsistencyException :: arrayIndexException ( " " , length ( ) , ( pos + len ) ) ; OffsetRange new_offset ; if ( length ( ) > 0 ) new_offset = OffsetRange ( startOffsetGroup ( pos ) , endOffsetGroup ( pos + len - 1 ) ) ; remove ( pos , pos + len ) ; insert ( repl , pos , new_offset ) ; }
All the offsets for the new text are set to the offset of the
 character immediately to the left, or immediately to the right
 if the text is replaced at the beginning of the string (i.e.,
 if <code>pos == 0</code>).
All the offsets for the new text are set to the offset of the character immediately to the left or immediately to the right if the text is replaced at the beginning of the string ( i . e . if <code > pos == 0< / code > ) .
/*
	if (len <= 0)
		throw InternalInconsistencyException("LocatedString::replace()",
									   "negative length parameter");
	if ((pos + len) > length())
		throw InternalInconsistencyException::arrayIndexException(
			"LocatedString::replace()", length(), (pos + len));
	
	OffsetRange new_offset;
	if (length() > 0)
		new_offset = OffsetRange(_offsets[pos].start, _offsets[pos+len-1].end);

	// Replace the original text
	_text.replace(pos, len, repl);

	// Grow or shrink the offsets, if necessary.
	int length_change = static_cast<int>(_text.size()) - static_cast<int>(_offsets.size());
	if (length_change > 0) {
		_offsets.insert(_offsets.begin()+pos+len, length_change, new_offset);
	} else if (length_change < 0) {
		_offsets.erase(_offsets.begin()+pos, _offsets.begin()+pos-length_change);
	}

	// Set the offsets for the newly replaced text.
	for (int i=pos; i<pos+(len+length_change); ++i)
		_offsets[i] = new_offset;
	*/