// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0x18
popq %rdi
callq 0x2170
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %rax, 0x10(%rsp)
andq $0x0, 0x10(%rax)
pushq $0x8
popq %rdi
callq 0x2170
movq %rax, %r13
movq %rax, %rdi
callq 0x4e00
leaq 0x8(%rsp), %rax
movq %r13, (%rax)
movq %r15, %rdi
callq 0x4eb4
movl %eax, %ebp
movslq %eax, %r12
xorl %r13d, %r13d
cmpl %ebp, %r13d
jge 0x6bd4
movq %r14, %rdi
callq 0x4eb4
movslq %r13d, %rcx
movslq %eax, %rdx
decl %eax
leal (%rdx,%r13), %ebx
decl %ebx
movq %r12, %rsi
subq %rcx, %rsi
leaq (%r15,%rcx), %rdi
xorl %r8d, %r8d
cmpq %rdx, %r8
jge 0x6b77
cmpq %r8, %rsi
je 0x6b77
movb (%rdi,%r8), %r9b
cmpb (%r14,%r8), %r9b
jne 0x6b77
cmpq %r8, %rax
je 0x6b88
incq %r8
jmp 0x6b59
movq 0x8(%rsp), %rdi
movsbl (%r15,%rcx), %esi
callq 0x57c2
jmp 0x6bcc
movq 0x8(%rsp), %rax
movq (%rax), %rax
cmpl $0x0, 0xc(%rax)
je 0x6bbf
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x75a8
pushq $0x8
popq %rdi
callq 0x2170
movq %rax, %r13
movq %rax, %rdi
callq 0x4e00
movq %r13, 0x8(%rsp)
jmp 0x6bc9
andl $0x0, 0xc(%rax)
movq (%rax), %rax
movb $0x0, (%rax)
movl %ebx, %r13d
incl %r13d
jmp 0x6b2d
movq 0x8(%rsp), %r14
testq %r14, %r14
je 0x6c03
movq (%r14), %rax
cmpl $0x0, 0xc(%rax)
je 0x6bfb
leaq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x75a8
jmp 0x6c13
movq %r14, %rdi
callq 0x5692
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x2180
movq 0x10(%rsp), %rbx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6c27
movq %rax, %rbx
pushq $0x8
popq %rsi
movq %r13, %rdi
callq 0x2180
movq %rbx, %rdi
callq 0x22b0
nop