// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebx
movq %rsi, %r13
movq %rdi, %rbp
movq %rsi, %rdi
callq 0x58370
testl %eax, %eax
je 0x91267
movl %eax, %r12d
movq 0xd01ba(%rip), %rax     # 0x161360
cmpb $0x1, (%rax)
jne 0x912ba
movq %r13, %rdi
callq 0x58660
testb %al, %al
je 0x912ba
leal 0x1(%r12), %eax
shlq $0x2, %rax
cmpl $-0x1, %r12d
pushq $-0x1
popq %r15
cmovgeq %rax, %r15
movq %r15, %rdi
callq 0x577a0
movq %rax, %r14
leaq 0x55b27(%rip), %rsi     # 0xe6d0d
movq %r13, %rdi
callq 0x58b90
movq %rax, %rdi
movl %r12d, %esi
movq %r14, %rdx
callq 0x58f40
movq %r15, %rdi
callq 0x577a0
movq %rax, %r15
movq (%rbp), %rax
movq %rbp, %rdi
callq *0x160(%rax)
movzbl %al, %eax
orl $0x110, %eax            # imm = 0x110
leaq 0x14(%rsp), %rbp
movl %eax, (%rbp)
movq %r13, %rdi
leaq 0x55adf(%rip), %rsi     # 0xe6d0d
callq 0x58b90
andq $0x0, (%rsp)
movq %rax, %rdi
movl %r12d, %esi
movq %rbp, %rdx
xorl %ecx, %ecx
movq %r15, %r8
xorl %r9d, %r9d
callq 0x57120
cmpl %ebx, %r12d
jne 0x9126b
movslq %ebx, %rax
movl -0x4(%r14,%rax,4), %ebx
notl %ebx
andl $0x1, %ebx
addl -0x4(%r15,%rax,4), %ebx
jmp 0x912aa
xorl %ebx, %ebx
jmp 0x912ba
testl %ebx, %ebx
je 0x91293
movslq %ebx, %rax
movl (%r14,%rax,4), %ecx
testb $0x1, %cl
jne 0x9129e
leaq -0x1(%rax), %rdx
testb $0x1, -0x4(%r14,%rax,4)
jne 0x912a6
btl $0xb, %ecx
jb 0x912cb
movl (%r15,%rax,4), %ebx
jmp 0x912aa
movl (%r14), %ebx
andl $0x1, %ebx
addl (%r15), %ebx
jmp 0x912aa
movl (%r15,%rax,4), %ebx
incl %ebx
jmp 0x912aa
movl (%r15,%rdx,4), %ebx
movq %r14, %rdi
callq 0x572d0
movq %r15, %rdi
callq 0x572d0
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl (%r15,%rdx,4), %ebx
jmp 0x912a2
nop