// File: /workspace/github_c_makefile_star2_O3/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 0x57180
testl %eax, %eax
je 0x94b7d
movl %eax, %r12d
movq 0xd68aa(%rip), %rax     # 0x16b360
cmpb $0x1, (%rax)
jne 0x94bd0
movq %r13, %rdi
callq 0x57460
testb %al, %al
je 0x94bd0
leal 0x1(%r12), %eax
shlq $0x2, %rax
cmpl $-0x1, %r12d
movq $-0x1, %r15
cmovgeq %rax, %r15
movq %r15, %rdi
callq 0x56670
movq %rax, %r14
leaq 0x62314(%rip), %rsi     # 0xf6e0d
movq %r13, %rdi
callq 0x57940
movq %rax, %rdi
movl %r12d, %esi
movq %r14, %rdx
callq 0x57cc0
movq %r15, %rdi
callq 0x56670
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 0x622cc(%rip), %rsi     # 0xf6e0d
callq 0x57940
movq $0x0, (%rsp)
movq %rax, %rdi
movl %r12d, %esi
movq %rbp, %rdx
xorl %ecx, %ecx
movq %r15, %r8
xorl %r9d, %r9d
callq 0x56040
cmpl %ebx, %r12d
jne 0x94b81
movslq %ebx, %rax
movl -0x4(%r14,%rax,4), %ebx
notl %ebx
andl $0x1, %ebx
addl -0x4(%r15,%rax,4), %ebx
jmp 0x94bc0
xorl %ebx, %ebx
jmp 0x94bd0
testl %ebx, %ebx
je 0x94ba9
movslq %ebx, %rax
movl (%r14,%rax,4), %ecx
testb $0x1, %cl
jne 0x94bb4
leaq -0x1(%rax), %rdx
testb $0x1, -0x4(%r14,%rax,4)
jne 0x94bbc
btl $0xb, %ecx
jb 0x94be1
movl (%r15,%rax,4), %ebx
jmp 0x94bc0
movl (%r14), %ebx
andl $0x1, %ebx
addl (%r15), %ebx
jmp 0x94bc0
movl (%r15,%rax,4), %ebx
incl %ebx
jmp 0x94bc0
movl (%r15,%rdx,4), %ebx
movq %r14, %rdi
callq 0x561e0
movq %r15, %rdi
callq 0x561e0
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 0x94bb8
nop