// File: /workspace/github_cpp_makefile_star2_O3/akdess[P]BAFExtract/src/ansi_string.cpp
// Function: t_string::tokenize_by_str(char*, char const*)
t_string_tokens* t_string::tokenize_by_str(char* string, const char* delimiter_string)
{
	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);
	for(int i_str = 0; i_str < str_len; i_str++)
	{
		// This is set to true if i_str'th character is a delimiter.
		bool is_delimiter = false;

		int i_str_search = i_str;

		// Check if current character in the string is a delimiter character.
		for(int i_del = 0; i_del < string_length(delimiter_string); i_del++)
		{
			if(i_str_search == str_len || 
				string[i_str_search] != delimiter_string[i_del])
			{
				is_delimiter = false;
				break;
			}				

			// If the current substring matches the delimiter string, set delimiter to true.
			if(i_del == string_length(delimiter_string) - 1)
			{
				// 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.
					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();
				}

				is_delimiter = true;

				// Note that the last char that is at i_str_search is the last char
				// of delimiter string but that will be jumped over by for loop.
				// This is the same in tokenize_by_chars function.
				i_str = i_str_search;
				break;
			}

			// Increment substring counter.
			i_str_search++;

		} // delimiter char loop.

		// If this character is not a delimiter, concatenate the character to the current_token.
		if(!is_delimiter)
		{
			current_token->concat_char(string[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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %r15
movl $0x18, %edi
callq 0x2160
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rax)
movl $0x8, %edi
callq 0x2160
movq %rax, %rbp
movl $0x10, %edi
callq 0x2160
movq %rax, %r13
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movq %rax, (%rbp)
movl $0x1f4, 0x8(%rax)       # imm = 0x1F4
movl $0x1f7, %edi            # imm = 0x1F7
callq 0x2040
movq %rax, (%r13)
movl $0x0, 0xc(%r13)
movb $0x0, (%rax)
movq %rbp, (%rsp)
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
incl %r12d
cmpb $0x0, (%r15,%r12)
jne 0x7a51
testl %r12d, %r12d
jle 0x7b6f
movl %r12d, %ebx
xorl %ebp, %ebp
movslq %ebp, %rax
xorl %ecx, %ecx
movq %rax, %r13
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
incl %edx
cmpb $0x0, (%r14,%rdx)
jne 0x7a76
movslq %edx, %rdx
cmpq %rdx, %rcx
jge 0x7ab6
cmpq %rbx, %r13
je 0x7ab6
movb (%r15,%r13), %dl
cmpb (%r14,%rcx), %dl
jne 0x7ab6
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
leal 0x2(%rdx), %esi
incl %edx
cmpb $0x0, (%r14,%rsi)
jne 0x7a9b
movl %edx, %edx
cmpq %rdx, %rcx
je 0x7ac9
incq %r13
incq %rcx
jmp 0x7a71
movq (%rsp), %rdi
movsbl (%r15,%rax), %esi
callq 0x5f5c
jmp 0x7b5b
movq (%rsp), %rax
movq (%rax), %rcx
cmpl $0x0, 0xc(%rcx)
je 0x7aef
movq 0x8(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x7afe
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x7b06
movl $0x0, 0xc(%rcx)
movq (%rcx), %rax
movb $0x0, (%rax)
jmp 0x7b58
movq %rsp, %rdx
callq 0x9190
movl $0x8, %edi
callq 0x2160
movq %rax, 0x10(%rsp)
movl $0x10, %edi
callq 0x2160
movq %rax, %rbp
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movq 0x10(%rsp), %rax
movq %rbp, (%rax)
movl $0x1f4, 0x8(%rbp)       # imm = 0x1F4
movl $0x1f7, %edi            # imm = 0x1F7
callq 0x2040
movq %rax, (%rbp)
movl $0x0, 0xc(%rbp)
movb $0x0, (%rax)
movq 0x10(%rsp), %rax
movq %rax, (%rsp)
movl %r13d, %ebp
incl %ebp
cmpl %r12d, %ebp
jl 0x7a69
movq (%rsp), %rbp
testq %rbp, %rbp
je 0x7b9c
movq (%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x7b92
movq 0x8(%rsp), %rbx
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x7bb2
movq %rbp, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x7bbd
movq %rbp, %rdi
callq 0x5db0
jmp 0x7b9e
xorl %ebp, %ebp
movl $0x8, %esi
movq %rbp, %rdi
callq 0x2170
movq 0x8(%rsp), %rax
jmp 0x7bc0
movq %rsp, %rdx
movq %rbx, %rdi
callq 0x9190
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x8, %esi
movq %rbp, %rdi
jmp 0x7be9
movq %rax, %rbx
movl $0x8, %esi
movq 0x10(%rsp), %rdi
callq 0x2170
movq %rbx, %rdi
callq 0x22a0