// File: /workspace/github_cpp_makefile_star2_O2/rurban[P]dgnlib/cpl_string.cpp
// Function: CPLEscapeString
char *CPLEscapeString( const char *pszInput, int nLength, 
                       int nScheme )

{
    char        *pszOutput;
    char        *pszShortOutput;

    if( nLength == -1 )
        nLength = strlen(pszInput);

    pszOutput = (char *) CPLMalloc( nLength * 6 + 1 );
    
    if( nScheme == CPLES_BackslashQuotable )
    {
        int iOut = 0, iIn;

        for( iIn = 0; iIn < nLength; iIn++ )
        {
            if( pszInput[iIn] == '\0' )
            {
                pszOutput[iOut++] = '\\';
                pszOutput[iOut++] = '0';
            }
            else if( pszInput[iIn] == '\n' )
            {
                pszOutput[iOut++] = '\\';
                pszOutput[iOut++] = 'n';
            }
            else if( pszInput[iIn] == '"' )
            {
                pszOutput[iOut++] = '\\';
                pszOutput[iOut++] = '\"';
            }
            else if( pszInput[iIn] == '\\' )
            {
                pszOutput[iOut++] = '\\';
                pszOutput[iOut++] = '\\';
            }
            else
                pszOutput[iOut++] = pszInput[iIn];
        }
        pszOutput[iOut] = '\0';
    }
    else if( nScheme == CPLES_URL ) /* Untested at implementation */
    {
        int iOut = 0, iIn;

        for( iIn = 0; iIn < nLength; iIn++ )
        {
            if( (pszInput[iIn] >= 'a' && pszInput[iIn] <= 'z')
                || (pszInput[iIn] >= 'A' && pszInput[iIn] <= 'Z')
                || (pszInput[iIn] >= '0' && pszInput[iIn] <= '9')
                || pszInput[iIn] == '_' )
            {
                pszOutput[iOut++] = pszInput[iIn];
            }
            else
            {
                sprintf( pszOutput, "%%%02X", pszInput[iIn] );
                iOut += 3;
            }
        }
        pszOutput[iOut] = '\0';
    }
    else if( nScheme == CPLES_XML )
    {
        int iOut = 0, iIn;

        for( iIn = 0; iIn < nLength; iIn++ )
        {
            if( pszInput[iIn] == '<' )
            {
                pszOutput[iOut++] = '&';
                pszOutput[iOut++] = 'l';
                pszOutput[iOut++] = 't';
                pszOutput[iOut++] = ';';
            }
            else if( pszInput[iIn] == '>' )
            {
                pszOutput[iOut++] = '&';
                pszOutput[iOut++] = 'g';
                pszOutput[iOut++] = 't';
                pszOutput[iOut++] = ';';
            }
            else if( pszInput[iIn] == '&' )
            {
                pszOutput[iOut++] = '&';
                pszOutput[iOut++] = 'a';
                pszOutput[iOut++] = 'm';
                pszOutput[iOut++] = 'p';
                pszOutput[iOut++] = ';';
            }
            else if( pszInput[iIn] == '"' )
            {
                pszOutput[iOut++] = '&';
                pszOutput[iOut++] = 'q';
                pszOutput[iOut++] = 'u';
                pszOutput[iOut++] = 'o';
                pszOutput[iOut++] = 't';
                pszOutput[iOut++] = ';';
            }
            else
                pszOutput[iOut++] = pszInput[iIn];
        }
        pszOutput[iOut] = '\0';
    }
    else if( nScheme == CPLES_SQL )
    {
        int iOut = 0, iIn;

        for( iIn = 0; iIn < nLength; iIn++ )
        {
            if( pszInput[iIn] == '\'' )
            {
                pszOutput[iOut++] = '\'';
                pszOutput[iOut++] = '\'';
            }
            else
                pszOutput[iOut++] = pszInput[iIn];
        }
        pszOutput[iOut] = '\0';
    }
    else if( nScheme == CPLES_CSV )
    {
        if( strchr( pszInput, '\"' ) == NULL
            && strchr( pszInput, ',') == NULL
            && strchr( pszInput, 10) == NULL 
            && strchr( pszInput, 13) == NULL )
        {
            strcpy( pszOutput, pszInput );
        }
        else
        {
            int iOut = 1, iIn;

            pszOutput[0] = '\"';

            for( iIn = 0; iIn < nLength; iIn++ )
            {
                if( pszInput[iIn] == '\"' )
                {
                    pszOutput[iOut++] = '\"';
                    pszOutput[iOut++] = '\"';
                }
                else if( pszInput[iIn] == 13 )
                    /* drop DOS LF's in strings. */;
                else
                    pszOutput[iOut++] = pszInput[iIn];
            }
            pszOutput[iOut++] = '\"';
            pszOutput[iOut++] = '\0';
        }
    }
    else
    {
        pszOutput[0] = '\0';
        CPLError( CE_Failure, CPLE_AppDefined, 
                  "Undefined escaping scheme (%d) in CPLEscapeString()",
                  nScheme );
    }

    pszShortOutput = CPLStrdup( pszOutput );
    CPLFree( pszOutput );

    return pszShortOutput;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebp
movl %esi, %r15d
movq %rdi, %r14
cmpl $-0x1, %esi
jne 0x6317
movq %r14, %rdi
callq 0x2120
movq %rax, %r15
imull $0x6, %r15d, %eax
incl %eax
movslq %eax, %rdi
callq 0x2cb3
movq %rax, %rbx
cmpl $0x4, %ebp
ja 0x6542
movl %ebp, %eax
leaq 0x8342(%rip), %rcx      # 0xe67c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %eax, %eax
testl %r15d, %r15d
cmovlel %eax, %r15d
xorl %ecx, %ecx
movslq %ecx, %rcx
cmpq %rax, %r15
je 0x653c
movzbl (%r14,%rax), %edx
cmpl $0x5c, %edx
je 0x638a
cmpl $0xa, %edx
je 0x637a
cmpl $0x22, %edx
je 0x6382
testl %edx, %edx
jne 0x6398
movw $0x305c, (%rbx,%rcx)    # imm = 0x305C
jmp 0x6390
movw $0x6e5c, (%rbx,%rcx)    # imm = 0x6E5C
jmp 0x6390
movw $0x225c, (%rbx,%rcx)    # imm = 0x225C
jmp 0x6390
movw $0x5c5c, (%rbx,%rcx)    # imm = 0x5C5C
addl $0x2, %ecx
incq %rax
jmp 0x634e
movb %dl, (%rbx,%rcx)
incl %ecx
jmp 0x6393
pushq $0x22
popq %rsi
movq %r14, %rdi
callq 0x20e0
testq %rax, %rax
jne 0x63e3
pushq $0x2c
popq %rsi
movq %r14, %rdi
callq 0x20e0
testq %rax, %rax
jne 0x63e3
pushq $0xa
popq %rsi
movq %r14, %rdi
callq 0x20e0
testq %rax, %rax
jne 0x63e3
pushq $0xd
popq %rsi
movq %r14, %rdi
callq 0x20e0
testq %rax, %rax
je 0x6588
movb $0x22, (%rbx)
xorl %eax, %eax
testl %r15d, %r15d
cmovlel %eax, %r15d
pushq $0x1
popq %rcx
movslq %ecx, %rdx
cmpq %rax, %r15
je 0x655d
movzbl (%r14,%rax), %esi
cmpl $0xd, %esi
je 0x6421
cmpl $0x22, %esi
jne 0x641a
movw $0x2222, (%rbx,%rdx)    # imm = 0x2222
addl $0x2, %edx
movl %edx, %ecx
jmp 0x6421
leal 0x1(%rdx), %ecx
movb %sil, (%rbx,%rdx)
incq %rax
jmp 0x63f2
xorl %eax, %eax
testl %r15d, %r15d
cmovlel %eax, %r15d
leaq 0x8292(%rip), %r12      # 0xe6c8
xorl %r13d, %r13d
xorl %ebp, %ebp
movslq %ebp, %rax
cmpq %r13, %r15
je 0x6488
movb (%r14,%r13), %cl
movl %ecx, %edx
andb $-0x21, %dl
addb $-0x41, %dl
cmpb $0x1a, %dl
jb 0x6469
leal -0x30(%rcx), %edx
cmpb $0xa, %dl
setae %dl
cmpb $0x5f, %cl
setne %sil
testb %dl, %sil
jne 0x6470
incl %ebp
movb %cl, (%rbx,%rax)
jmp 0x6483
movsbl %cl, %edx
movq %rbx, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x20a0
addl $0x3, %ebp
incq %r13
jmp 0x643b
movb $0x0, (%rbx,%rax)
jmp 0x6563
xorl %eax, %eax
testl %r15d, %r15d
cmovlel %eax, %r15d
xorl %ecx, %ecx
movslq %ecx, %rcx
cmpq %rax, %r15
je 0x653c
movb (%r14,%rax), %dl
cmpb $0x27, %dl
jne 0x64bc
movw $0x2727, (%rbx,%rcx)    # imm = 0x2727
addl $0x2, %ecx
jmp 0x64c1
movb %dl, (%rbx,%rcx)
incl %ecx
incq %rax
jmp 0x649c
xorl %eax, %eax
testl %r15d, %r15d
cmovlel %eax, %r15d
xorl %edx, %edx
movslq %edx, %rcx
cmpq %rax, %r15
je 0x653c
movzbl (%r14,%rax), %esi
cmpl $0x22, %esi
je 0x651b
cmpl $0x26, %esi
je 0x64fe
cmpl $0x3e, %esi
je 0x650f
cmpl $0x3c, %esi
jne 0x6530
leal 0x4(%rcx), %edx
movl $0x3b746c26, (%rbx,%rcx) # imm = 0x3B746C26
jmp 0x6537
movl $0x706d6126, (%rbx,%rcx) # imm = 0x706D6126
leal 0x5(%rcx), %edx
movb $0x3b, 0x4(%rbx,%rcx)
jmp 0x6537
leal 0x4(%rcx), %edx
movl $0x3b746726, (%rbx,%rcx) # imm = 0x3B746726
jmp 0x6537
movl $0x6f757126, (%rbx,%rcx) # imm = 0x6F757126
movw $0x3b74, 0x4(%rbx,%rcx) # imm = 0x3B74
addl $0x6, %ecx
movl %ecx, %edx
jmp 0x6537
leal 0x1(%rcx), %edx
movb %sil, (%rbx,%rcx)
incq %rax
jmp 0x64d1
movb $0x0, (%rbx,%rcx)
jmp 0x6563
movb $0x0, (%rbx)
leaq 0x8183(%rip), %rdx      # 0xe6cf
pushq $0x3
popq %rdi
pushq $0x1
popq %rsi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x439c
jmp 0x6563
movw $0x22, (%rbx,%rdx)
movq %rbx, %rdi
callq 0x2d77
movq %rax, %r14
movq %rbx, %rdi
callq 0x6a49
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22a0
jmp 0x6563