HomeForumSourceResearchGuide
Sign in to contribute to source. how it works
Component data.StringBuilder by barry
expand copy to clipboardexpand
data Item {
	char str[]
	Item next
	}

component provides StringBuilder(AdaptEvents) {
	
	Item list
	Item last
	int length
	
	void copyChars(char into[], int start, char src[])
		{
		for (int i = 0; i < src.arrayLength; i++)
			{
			into[start+i] = src[i]
			}
		}
	
	void StringBuilder:add(char str[])
		{
		Item i = new Item(str)
		if (list == null)
			list = i
			else
			last.next = i
		
		last = i
		length += str.arrayLength
		}
	
	char[] StringBuilder:get()
		{
		if (length == 0) return null
		
		char result[] = new char[length]
		int offset = 0
		
		for (Item i = list; i != null; i = i.next)
			{
			copyChars(result, offset, i.str)
			offset += i.str.arrayLength
			}
		
		return result
		}
	
	void AdaptEvents:active()
		{
		list = null
		last = null
		
		add(builderContent)
		length = builderContent.arrayLength
		
		builderContent = null
		}
	
	void AdaptEvents:inactive()
		{
		builderContent = get()
		}
	
	}
Revision history
To propose a new revision to this entity, use dana source put -uc your/new/version.dn -n data.StringBuilder -m "reason for update" -u yourUsername
Version 1 (this version) by barry
Notes for this version: Standard Library Initialisation