// File: /workspace/github_c_makefile_star2_O1/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, %r12
movq %rdi, %r13
movq %rsi, %rdi
callq 0x57180
testl %eax, %eax
je 0x951e5
movl %eax, %ebp
movq 0xd7241(%rip), %rax     # 0x16c360
cmpb $0x1, (%rax)
jne 0x95238
movq %r12, %rdi
callq 0x57460
testb %al, %al
je 0x95238
movslq %ebp, %rax
leaq 0x4(,%rax,4), %rax
cmpl $-0x1, %ebp
movq $-0x1, %r15
cmovgeq %rax, %r15
movq %r15, %rdi
callq 0x56670
movq %rax, %r14
leaq 0x62b06(%rip), %rsi     # 0xf7c69
movq %r12, %rdi
callq 0x57940
movq %rax, %rdi
movl %ebp, %esi
movq %r14, %rdx
callq 0x57cc0
movq %r15, %rdi
callq 0x56670
movq %rax, %r15
movq (%r13), %rax
movq %r13, %rdi
callq *0x160(%rax)
movzbl %al, %eax
orl $0x110, %eax            # imm = 0x110
leaq 0x14(%rsp), %r13
movl %eax, (%r13)
movq %r12, %rdi
leaq 0x62abe(%rip), %rsi     # 0xf7c69
callq 0x57940
movq $0x0, (%rsp)
movq %rax, %rdi
movl %ebp, %esi
movq %r13, %rdx
xorl %ecx, %ecx
movq %r15, %r8
xorl %r9d, %r9d
callq 0x56040
cmpl %ebx, %ebp
jne 0x951e9
movslq %ebx, %rax
movl -0x4(%r14,%rax,4), %ebx
notl %ebx
andl $0x1, %ebx
addl -0x4(%r15,%rax,4), %ebx
jmp 0x95228
xorl %ebx, %ebx
jmp 0x95238
testl %ebx, %ebx
je 0x95211
movslq %ebx, %rax
movl (%r14,%rax,4), %ecx
testb $0x1, %cl
jne 0x9521c
leaq -0x1(%rax), %rdx
testb $0x1, -0x4(%r14,%rax,4)
jne 0x95224
btl $0xb, %ecx
jb 0x95249
movl (%r15,%rax,4), %ebx
jmp 0x95228
movl (%r14), %ebx
andl $0x1, %ebx
addl (%r15), %ebx
jmp 0x95228
movl (%r15,%rax,4), %ebx
incl %ebx
jmp 0x95228
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 0x95220
nop