// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/classes/gui/widgets/special/cursor.cpp
// Function: smooth::GUI::Cursor::GetVisualCursorPositionFromLogical(smooth::String const&, int) const
S::Int S::GUI::Cursor::GetVisualCursorPositionFromLogical(const String &line, Int n) const
{
	FriBidiStrIndex	 length = line.Length();

	if (length == 0) return 0;

	Int		 position = n;

	/* Check if the input string contains RTL characters.
	 */
	if (Setup::useIconv && ContainsRTLCharacters(line))
	{
		/* Get BiDi types for input string.
		 */
		FriBidiCharType	*types = new FriBidiCharType [length + 1];

		fribidi_get_bidi_types((FriBidiChar *) line.ConvertTo("UCS-4LE"), length, types);

		/* Get visual cursor position.
		 */
		FriBidiStrIndex	*positions = new FriBidiStrIndex [length + 1];
		FriBidiParType	 type = (IsRightToLeft() ? FRIBIDI_PAR_RTL : FRIBIDI_PAR_LTR);

		fribidi_log2vis((FriBidiChar *) line.ConvertTo("UCS-4LE"), length, &type, NIL, positions, NIL, NIL);

		if (n == length)
		{
			if	( FRIBIDI_IS_RTL(types[n - 1])) position = positions[n - 1];
			else					position = positions[n - 1] + 1;
		}
		else if (n == 0)
		{
			if	( FRIBIDI_IS_RTL(types[n    ]))	position = positions[n    ] + 1;
			else					position = positions[n    ];
		}
		else
		{
			if	( FRIBIDI_IS_RTL(types[n    ]))	position = positions[n    ] + 1;
			else if ( FRIBIDI_IS_RTL(types[n - 1])) position = positions[n - 1];
			else if ( FRIBIDI_IS_SPACE(types[n]) &&
				 !FRIBIDI_IS_RTL(types[n - 1])) position = positions[n - 1] + 1;
			else					position = positions[n    ];
		}

		delete [] types;
		delete [] positions;
	}

	return position;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rdi
callq 0x5b800
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jne 0xd0579
movl $0x0, -0x4(%rbp)
jmp 0xd07f2
movl -0x1c(%rbp), %eax
movl %eax, -0x24(%rbp)
movq 0x137daa(%rip), %rax    # 0x208330
testb $0x1, (%rax)
je 0xd07ec
movq -0x18(%rbp), %rdi
callq 0x5bb50
testb $0x1, %al
jne 0xd05a1
jmp 0xd07ec
movl -0x20(%rbp), %eax
addl $0x1, %eax
cltq
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x5ab20
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
leaq 0xba6c0(%rip), %rsi     # 0x18ac99
callq 0x5c120
movq %rax, %rdi
movl -0x20(%rbp), %esi
movq -0x30(%rbp), %rdx
callq 0x5c580
movl -0x20(%rbp), %eax
addl $0x1, %eax
cltq
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x5ab20
movq -0x48(%rbp), %rdi
movq %rax, -0x38(%rbp)
movq (%rdi), %rax
callq *0x160(%rax)
movb %al, %dl
movl $0x110, %eax            # imm = 0x110
movl $0x111, %ecx            # imm = 0x111
testb $0x1, %dl
cmovneq %rcx, %rax
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rdi
leaq 0xba651(%rip), %rsi     # 0x18ac99
callq 0x5c120
movq %rax, %rdi
movl -0x20(%rbp), %esi
movq -0x38(%rbp), %r8
leaq -0x3c(%rbp), %rdx
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %rcx
movq $0x0, (%rsp)
callq 0x5a370
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jne 0xd06c2
movq -0x30(%rbp), %rax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
andq $0x1, %rax
cmpq $0x0, %rax
je 0xd06a7
movq -0x38(%rbp), %rax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
jmp 0xd06bd
movq -0x38(%rbp), %rax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xd07bc
cmpl $0x0, -0x1c(%rbp)
jne 0xd0703
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andq $0x1, %rax
cmpq $0x0, %rax
je 0xd06f0
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xd06fe
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
jmp 0xd07ba
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andq $0x1, %rax
cmpq $0x0, %rax
je 0xd072e
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xd07b8
movq -0x30(%rbp), %rax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
andq $0x1, %rax
cmpq $0x0, %rax
je 0xd075d
movq -0x38(%rbp), %rax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
jmp 0xd07b6
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andq $0x800, %rax            # imm = 0x800
cmpq $0x0, %rax
je 0xd07a6
movq -0x30(%rbp), %rax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
andq $0x1, %rax
cmpq $0x0, %rax
jne 0xd07a6
movq -0x38(%rbp), %rax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xd07b4
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
jmp 0xd07b6
jmp 0xd07b8
jmp 0xd07ba
jmp 0xd07bc
movq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
je 0xd07d3
movq -0x50(%rbp), %rdi
callq 0x5a5e0
movq -0x38(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0xd07ea
movq -0x58(%rbp), %rdi
callq 0x5a5e0
jmp 0xd07ec
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)