// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movq %rdi, 0x18(%rsp)
movl $0x18, %edi
callq 0x2180
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rax)
movl $0x8, %edi
callq 0x2180
movq %rax, %rbp
movl $0x10, %edi
callq 0x2180
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)
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl 0xc(%rax), %eax
movq %rax, 0x20(%rsp)
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
incl %r12d
cmpb $0x0, (%r14,%r12)
jne 0x280cb
cmpl $0x0, 0x20(%rsp)
jle 0x28229
movl %r12d, %r15d
xorl %ebx, %ebx
movabsq $0x100000600, %r13      # imm = 0x100000600
movq 0x18(%rsp), %rbp
movq (%rbp), %rax
movq (%rax), %rax
movb (%rax,%rbx), %al
testl %r12d, %r12d
jle 0x28113
xorl %ecx, %ecx
cmpb (%r14,%rcx), %al
je 0x28121
incq %rcx
cmpq %rcx, %r15
jne 0x28105
movq (%rsp), %rdi
movsbl %al, %esi
callq 0x2724c
jmp 0x28193
movq (%rsp), %rax
movq (%rax), %rcx
cmpl $0x0, 0xc(%rcx)
movq (%rcx), %rdx
je 0x28189
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
movl %r8d, %edi
incl %esi
leal 0x1(%rdi), %r8d
cmpb $0x0, (%rdx,%rsi)
jne 0x28139
testl %esi, %esi
jle 0x28189
movl %edi, %edi
negq %rdi
movl $0x1, %r9d
xorl %r8d, %r8d
movzbl -0x1(%rdx,%r9), %r10d
cmpq $0x20, %r10
ja 0x28183
btq %r10, %r13
jae 0x28183
cmpq %rsi, %r9
setae %r8b
leaq (%rdi,%r9), %r10
incq %r10
incq %r9
cmpq $0x1, %r10
jne 0x2815a
testb $0x1, %r8b
je 0x281a3
movl $0x0, 0xc(%rcx)
movb $0x0, (%rdx)
incq %rbx
cmpq 0x20(%rsp), %rbx
jne 0x280f4
jmp 0x28220
movq 0x8(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x281bc
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x281c4
movq %rsp, %rdx
callq 0x29d64
movl $0x8, %edi
callq 0x2180
movq %rax, 0x10(%rsp)
movl $0x10, %edi
callq 0x2180
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)
movq 0x18(%rsp), %rbp
jmp 0x28193
movq (%rsp), %rbp
testq %rbp, %rbp
je 0x28256
movq (%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x2824c
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x28267
movq %rbp, (%rsi)
addq $0x8, 0x8(%rax)
jmp 0x28279
movq %rbp, %rdi
callq 0x27096
jmp 0x28258
xorl %ebp, %ebp
movl $0x8, %esi
movq %rbp, %rdi
callq 0x2190
jmp 0x28274
movq %rsp, %rdx
movq 0x8(%rsp), %rdi
callq 0x29d64
movq 0x8(%rsp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x8, %esi
movq %rbp, %rdi
jmp 0x282a2
movq %rax, %rbx
movl $0x8, %esi
movq 0x10(%rsp), %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x22e0
nop