// File: /workspace/github_cpp_makefile_star2_O3/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 0x6766
movq %r14, %rdi
callq 0x2120
movq %rax, %r15
leal (%r15,%r15), %eax
leal (%rax,%rax,2), %eax
incl %eax
movslq %eax, %rdi
callq 0x2d6b
movq %rax, %rbx
cmpl $0x4, %ebp
ja 0x69f6
movl %ebp, %eax
leaq 0x8ef0(%rip), %rcx      # 0xf67c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %eax, %eax
testl %r15d, %r15d
jle 0x69cd
movl %r15d, %ecx
xorl %edx, %edx
movb (%r14,%rdx), %sil
movzbl %sil, %edi
cmpl $0x21, %edi
jg 0x67c6
testl %edi, %edi
je 0x67e5
cmpl $0xa, %edi
jne 0x67da
movslq %eax, %rsi
movw $0x6e5c, (%rbx,%rsi)    # imm = 0x6E5C
jmp 0x67f9
cmpl $0x22, %edi
je 0x67f0
cmpl $0x5c, %edi
jne 0x67da
cltq
movw $0x5c5c, (%rbx,%rax)    # imm = 0x5C5C
jmp 0x67f9
movslq %eax, %rdi
incl %eax
movb %sil, (%rbx,%rdi)
jmp 0x67fc
movslq %eax, %rsi
movw $0x305c, (%rbx,%rsi)    # imm = 0x305C
jmp 0x67f9
movslq %eax, %rsi
movw $0x225c, (%rbx,%rsi)    # imm = 0x225C
addl $0x2, %eax
incq %rdx
cmpq %rdx, %rcx
jne 0x67a5
jmp 0x69cb
movq %r14, %rdi
movl $0x22, %esi
callq 0x20e0
testq %rax, %rax
jne 0x6855
movq %r14, %rdi
movl $0x2c, %esi
callq 0x20e0
testq %rax, %rax
jne 0x6855
movq %r14, %rdi
movl $0xa, %esi
callq 0x20e0
testq %rax, %rax
jne 0x6855
movq %r14, %rdi
movl $0xd, %esi
callq 0x20e0
testq %rax, %rax
je 0x6a22
movb $0x22, (%rbx)
testl %r15d, %r15d
jle 0x6a15
movl %r15d, %eax
movl $0x1, %ecx
xorl %edx, %edx
movzbl (%r14,%rdx), %esi
cmpl $0xd, %esi
je 0x688e
movslq %ecx, %rcx
cmpl $0x22, %esi
jne 0x6888
movw $0x2222, (%rbx,%rcx)    # imm = 0x2222
addl $0x2, %ecx
jmp 0x688e
movb %sil, (%rbx,%rcx)
incl %ecx
incq %rdx
cmpq %rdx, %rax
jne 0x686b
movslq %ecx, %rax
jmp 0x6a1a
xorl %eax, %eax
testl %r15d, %r15d
jle 0x69cd
movl %r15d, %r12d
leaq 0x8e15(%rip), %r15      # 0xf6c8
xorl %r13d, %r13d
xorl %ebp, %ebp
movb (%r14,%r13), %al
movl %eax, %ecx
andb $-0x21, %cl
addb $-0x41, %cl
cmpb $0x1a, %cl
jb 0x68db
leal -0x30(%rax), %ecx
cmpb $0xa, %cl
setae %cl
cmpb $0x5f, %al
setne %dl
testb %cl, %dl
jne 0x68e5
movslq %ebp, %rcx
incl %ebp
movb %al, (%rbx,%rcx)
jmp 0x68f8
movsbl %al, %edx
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x20a0
addl $0x3, %ebp
incq %r13
cmpq %r13, %r12
jne 0x68b8
movslq %ebp, %rax
jmp 0x69cd
xorl %eax, %eax
testl %r15d, %r15d
jle 0x69cd
movl %r15d, %ecx
xorl %edx, %edx
movb (%r14,%rdx), %sil
cltq
cmpb $0x27, %sil
jne 0x692f
movw $0x2727, (%rbx,%rax)    # imm = 0x2727
addl $0x2, %eax
jmp 0x6935
movb %sil, (%rbx,%rax)
incl %eax
incq %rdx
cmpq %rdx, %rcx
jne 0x6918
jmp 0x69cb
xorl %eax, %eax
testl %r15d, %r15d
jle 0x69cd
movl %r15d, %ecx
xorl %edx, %edx
movb (%r14,%rdx), %sil
movzbl %sil, %edi
cmpl $0x3b, %edi
jg 0x697d
cmpl $0x22, %edi
je 0x69a1
cmpl $0x26, %edi
jne 0x6996
movslq %eax, %rsi
movl $0x706d6126, (%rbx,%rsi) # imm = 0x706D6126
addl $0x5, %eax
movb $0x3b, 0x4(%rbx,%rsi)
jmp 0x69c3
cmpl $0x3e, %edi
je 0x69b6
cmpl $0x3c, %edi
jne 0x6996
movslq %eax, %rsi
addl $0x4, %eax
movl $0x3b746c26, (%rbx,%rsi) # imm = 0x3B746C26
jmp 0x69c3
movslq %eax, %rdi
incl %eax
movb %sil, (%rbx,%rdi)
jmp 0x69c3
cltq
movl $0x6f757126, (%rbx,%rax) # imm = 0x6F757126
movw $0x3b74, 0x4(%rbx,%rax) # imm = 0x3B74
addl $0x6, %eax
jmp 0x69c3
movslq %eax, %rsi
addl $0x4, %eax
movl $0x3b746726, (%rbx,%rsi) # imm = 0x3B746726
incq %rdx
cmpq %rdx, %rcx
jne 0x6952
cltq
movb $0x0, (%rbx,%rax)
movq %rbx, %rdi
callq 0x2e41
movq %rax, %r14
movq %rbx, %rdi
callq 0x6edd
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x0, (%rbx)
leaq 0x8ccf(%rip), %rdx      # 0xf6cf
movl $0x3, %edi
movl $0x1, %esi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x460c
jmp 0x69d1
movl $0x1, %eax
movw $0x22, (%rbx,%rax)
jmp 0x69d1
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22a0
jmp 0x69d1