// File: gersteinlab[P]MUSIC/src/ms_ansi_string.cpp
// Function: t_string::tokenize_by_chars(char*, char const*)
t_string_tokens* t_string::tokenize_by_chars(char* string, 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 = t_string::string_length(string);
	int n_delimiters = string_length(delimiter_list);

	int i_str = 0;
	while(string[i_str] != 0)
	{
		//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])
			if(string[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)
				{
					// 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));
			current_token->concat_char(string[i_str]);
		}

		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 $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movl $0x18, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, 0x18(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
callq 0x4b800
movq 0x18(%rsp), %rax
movq %rax, 0x50(%rsp)
movl $0x8, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x20(%rsp)
callq 0x474d0
jmp 0x49989
movq 0x20(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x58(%rsp), %rdi
callq 0x47640
movl %eax, 0x38(%rsp)
movl $0x0, 0x34(%rsp)
movq 0x60(%rsp), %rax
movslq 0x34(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x49ae7
movb $0x0, 0x33(%rsp)
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0x38(%rsp), %eax
jge 0x49ab8
movq 0x60(%rsp), %rax
movslq 0x34(%rsp), %rcx
movsbl (%rax,%rcx), %eax
movq 0x58(%rsp), %rcx
movslq 0x2c(%rsp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0x49aa6
movb $0x1, 0x33(%rsp)
cmpq $0x0, 0x48(%rsp)
je 0x49a9a
movq 0x48(%rsp), %rdi
callq 0x481a0
cmpl $0x0, %eax
je 0x49a9a
movq 0x50(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x4b810
movl $0x8, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x10(%rsp)
callq 0x474d0
jmp 0x49a4a
movq 0x10(%rsp), %rax
movq %rax, 0x48(%rsp)
jmp 0x49aa4
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x40(%rsp)
movl %eax, 0x3c(%rsp)
movl $0x8, %esi
callq 0x21a0
jmp 0x49b44
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x40(%rsp)
movl %eax, 0x3c(%rsp)
movl $0x8, %esi
callq 0x21a0
jmp 0x49b44
movq 0x48(%rsp), %rdi
callq 0x47550
jmp 0x49ab8
jmp 0x49aa8
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x499cd
testb $0x1, 0x33(%rsp)
jne 0x49ad7
movq 0x48(%rsp), %rdi
movq 0x60(%rsp), %rax
movslq 0x34(%rsp), %rcx
movsbl (%rax,%rcx), %esi
callq 0x481d0
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x499a9
cmpq $0x0, 0x48(%rsp)
je 0x49b0f
movq 0x48(%rsp), %rdi
callq 0x481a0
cmpl $0x0, %eax
je 0x49b0f
movq 0x50(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x4b810
jmp 0x49b3a
movq 0x48(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x49b38
movq 0x8(%rsp), %rdi
callq 0x47f70
movq 0x8(%rsp), %rdi
movl $0x8, %esi
callq 0x21a0
jmp 0x49b3a
movq 0x50(%rsp), %rax
addq $0x68, %rsp
retq
movq 0x40(%rsp), %rdi
callq 0x2300
nop