// File: gersteinlab[P]MUSIC/src/ms_ansi_string.cpp
// Function: t_string::tokenize_by_chars(char const*)
t_string_tokens* t_string::tokenize_by_chars(const char* delimiter_list)
{
	//printf("String: %sFIN\n", this->str());
	t_string_tokens* token_vector = new vector<t_string*>();

	// Current token is nothing at the beginning.
	t_string* current_token = new t_string();

	// Go over the obj_string.
	int str_len = this->length();
	int n_delimiters = string_length(delimiter_list);
	for(int i_str = 0; i_str < str_len; i_str++)
	{
		//printf("Processing: %c\n", this->x(i_str));
		// This is set to true if i_str'th character is a delimiter.
		bool is_delimiter = false;

		// Check if current character in the string is a delimiter character.
		for(int i_del = 0; i_del < n_delimiters; i_del++)
		{
			if(this->x(i_str) == delimiter_list[i_del])
			{
				is_delimiter = true;

				// Push current token to vector (if it is appropriate for pushing.) and start a new token.
				// Push the previous token. Cannot push the next token since there is no way of knowing that
				// it is a valid token beforehand.
				if(current_token != NULL && current_token->length() != 0 && !t_string::is_empty(current_token->str()))
				{
					// Push this token to token vector.
					//printf("pushing %s\n", current_token->obj_string);
					token_vector->push_back(current_token);

					// Do not free current token now, allocate a new one.
					current_token = new t_string();
				}
				else // The token is not a good token (i.e., an empty token), free its memory and 
				{
					current_token->empty();
				}

				break; // Break from the delimiter char loop.
			}
		} // delimiter char loop.

		// If this character is not a delimiter, concatenate the character to the current_token.
		if(!is_delimiter)
		{
			current_token->concat_char(this->x(i_str));
		}

	} // string char loop.

	// The last token is added to the tokens vector after whole loop is finished.
	if(current_token != NULL && current_token->length() != 0)
	{
		// Push this token to token vector.
		token_vector->push_back(current_token);
		//printf("pushing %s\n", current_token->obj_string);
	}
	else	
	{
		delete(current_token);
	}

	return(token_vector);
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x20(%rsp)
movl $0x18, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, 0x28(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
callq 0x4b800
movq 0x28(%rsp), %rax
movq %rax, 0x60(%rsp)
movl $0x8, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x30(%rsp)
callq 0x474d0
jmp 0x49733
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %rax
movq %rax, 0x58(%rsp)
callq 0x481a0
movl %eax, 0x48(%rsp)
movq 0x68(%rsp), %rdi
callq 0x47640
movl %eax, 0x44(%rsp)
movl $0x0, 0x40(%rsp)
movl 0x40(%rsp), %eax
cmpl 0x48(%rsp), %eax
jge 0x498c2
movb $0x0, 0x3f(%rsp)
movl $0x0, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0x49884
movq 0x20(%rsp), %rdi
movl 0x40(%rsp), %esi
callq 0x481b0
movsbl (%rax), %eax
movq 0x68(%rsp), %rcx
movslq 0x38(%rsp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0x49872
movb $0x1, 0x3f(%rsp)
cmpq $0x0, 0x58(%rsp)
je 0x49866
movq 0x58(%rsp), %rdi
callq 0x481a0
cmpl $0x0, %eax
je 0x49866
movq 0x58(%rsp), %rdi
callq 0x47e10
movq %rax, %rdi
callq 0x48670
testb $0x1, %al
jne 0x49866
movq 0x60(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x4b810
movl $0x8, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x18(%rsp)
callq 0x474d0
jmp 0x49816
movq 0x18(%rsp), %rax
movq %rax, 0x58(%rsp)
jmp 0x49870
movq 0x30(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
movl $0x8, %esi
callq 0x21a0
jmp 0x4991f
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x50(%rsp)
movl %eax, 0x4c(%rsp)
movl $0x8, %esi
callq 0x21a0
jmp 0x4991f
movq 0x58(%rsp), %rdi
callq 0x47550
jmp 0x49884
jmp 0x49874
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x4977c
testb $0x1, 0x3f(%rsp)
jne 0x498b0
movq 0x20(%rsp), %rdi
movq 0x58(%rsp), %rax
movq %rax, 0x10(%rsp)
movl 0x40(%rsp), %esi
callq 0x481b0
movq 0x10(%rsp), %rdi
movsbl (%rax), %esi
callq 0x481d0
jmp 0x498b2
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x49761
cmpq $0x0, 0x58(%rsp)
je 0x498ea
movq 0x58(%rsp), %rdi
callq 0x481a0
cmpl $0x0, %eax
je 0x498ea
movq 0x60(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x4b810
jmp 0x49915
movq 0x58(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x49913
movq 0x8(%rsp), %rdi
callq 0x47f70
movq 0x8(%rsp), %rdi
movl $0x8, %esi
callq 0x21a0
jmp 0x49915
movq 0x60(%rsp), %rax
addq $0x78, %rsp
retq
movq 0x50(%rsp), %rdi
callq 0x2300
nopl (%rax)