// File: /workspace/github_cpp_makefile_star2_O1/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 0x6881
movq %r14, %rdi
callq 0x2120
movq %rax, %r15
leal (%r15,%r15), %eax
leal (%rax,%rax,2), %eax
incl %eax
movslq %eax, %rdi
callq 0x2d9b
movq %rax, %rbx
cmpl $0x4, %ebp
ja 0x6b0a
movl %ebp, %eax
leaq 0x9db9(%rip), %rcx      # 0x10660
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %eax, %eax
testl %r15d, %r15d
jle 0x6ae1
movl %r15d, %ecx
xorl %edx, %edx
movb (%r14,%rdx), %sil
movzbl %sil, %edi
cmpl $0x21, %edi
jg 0x68e1
testl %edi, %edi
je 0x6900
cmpl $0xa, %edi
jne 0x68f5
movslq %eax, %rsi
movw $0x6e5c, (%rbx,%rsi)    # imm = 0x6E5C
jmp 0x6914
cmpl $0x22, %edi
je 0x690b
cmpl $0x5c, %edi
jne 0x68f5
cltq
movw $0x5c5c, (%rbx,%rax)    # imm = 0x5C5C
jmp 0x6914
movslq %eax, %rdi
incl %eax
movb %sil, (%rbx,%rdi)
jmp 0x6917
movslq %eax, %rsi
movw $0x305c, (%rbx,%rsi)    # imm = 0x305C
jmp 0x6914
movslq %eax, %rsi
movw $0x225c, (%rbx,%rsi)    # imm = 0x225C
addl $0x2, %eax
incq %rdx
cmpq %rdx, %rcx
jne 0x68c0
jmp 0x6adf
movq %r14, %rdi
movl $0x22, %esi
callq 0x20e0
testq %rax, %rax
jne 0x6970
movq %r14, %rdi
movl $0x2c, %esi
callq 0x20e0
testq %rax, %rax
jne 0x6970
movq %r14, %rdi
movl $0xa, %esi
callq 0x20e0
testq %rax, %rax
jne 0x6970
movq %r14, %rdi
movl $0xd, %esi
callq 0x20e0
testq %rax, %rax
je 0x6b36
movb $0x22, (%rbx)
testl %r15d, %r15d
jle 0x6b29
movl %r15d, %eax
movl $0x1, %ecx
xorl %edx, %edx
movzbl (%r14,%rdx), %esi
cmpl $0xd, %esi
je 0x69a9
movslq %ecx, %rcx
cmpl $0x22, %esi
jne 0x69a3
movw $0x2222, (%rbx,%rcx)    # imm = 0x2222
addl $0x2, %ecx
jmp 0x69a9
movb %sil, (%rbx,%rcx)
incl %ecx
incq %rdx
cmpq %rdx, %rax
jne 0x6986
movslq %ecx, %rax
jmp 0x6b2e
xorl %eax, %eax
testl %r15d, %r15d
jle 0x6ae1
movl %r15d, %r12d
leaq 0x9cde(%rip), %r15      # 0x106ac
xorl %r13d, %r13d
xorl %ebp, %ebp
movb (%r14,%r13), %al
movl %eax, %ecx
andb $-0x21, %cl
addb $-0x41, %cl
cmpb $0x1a, %cl
jb 0x69f6
leal -0x30(%rax), %ecx
cmpb $0xa, %cl
setae %cl
cmpb $0x5f, %al
setne %dl
testb %cl, %dl
jne 0x6a00
movslq %ebp, %rcx
incl %ebp
movb %al, (%rbx,%rcx)
jmp 0x6a13
movsbl %al, %edx
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x20a0
addl $0x3, %ebp
incq %r13
cmpq %r13, %r12
jne 0x69d3
movslq %ebp, %rax
jmp 0x6ae1
xorl %eax, %eax
testl %r15d, %r15d
jle 0x6ae1
movl %r15d, %ecx
xorl %edx, %edx
movb (%r14,%rdx), %sil
cltq
cmpb $0x27, %sil
jne 0x6a4a
movw $0x2727, (%rbx,%rax)    # imm = 0x2727
addl $0x2, %eax
jmp 0x6a50
movb %sil, (%rbx,%rax)
incl %eax
incq %rdx
cmpq %rdx, %rcx
jne 0x6a33
jmp 0x6adf
xorl %eax, %eax
testl %r15d, %r15d
jle 0x6ae1
movl %r15d, %ecx
xorl %edx, %edx
movb (%r14,%rdx), %sil
movzbl %sil, %edi
cmpl $0x3b, %edi
jg 0x6a94
cmpl $0x22, %edi
je 0x6ab5
cmpl $0x26, %edi
jne 0x6aaa
movslq %eax, %rsi
movl $0x706d6126, (%rbx,%rsi) # imm = 0x706D6126
addl $0x5, %eax
movb $0x3b, 0x4(%rbx,%rsi)
jmp 0x6ad7
cmpl $0x3e, %edi
je 0x6aca
cmpl $0x3c, %edi
jne 0x6aaa
movslq %eax, %rsi
movl $0x3b746c26, (%rbx,%rsi) # imm = 0x3B746C26
jmp 0x6ad4
movslq %eax, %rdi
incl %eax
movb %sil, (%rbx,%rdi)
jmp 0x6ad7
cltq
movl $0x6f757126, (%rbx,%rax) # imm = 0x6F757126
movw $0x3b74, 0x4(%rbx,%rax) # imm = 0x3B74
addl $0x6, %eax
jmp 0x6ad7
movslq %eax, %rsi
movl $0x3b746726, (%rbx,%rsi) # imm = 0x3B746726
addl $0x4, %eax
incq %rdx
cmpq %rdx, %rcx
jne 0x6a69
cltq
movb $0x0, (%rbx,%rax)
movq %rbx, %rdi
callq 0x2e6c
movq %rax, %r14
movq %rbx, %rdi
callq 0x701d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x0, (%rbx)
leaq 0x9b9f(%rip), %rdx      # 0x106b3
movl $0x3, %edi
movl $0x1, %esi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x46dc
jmp 0x6ae5
movl $0x1, %eax
movw $0x22, (%rbx,%rax)
jmp 0x6ae5
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22b0
jmp 0x6ae5