int CEscapeApp::EscapeX(int nBufferLength, LPSTR cInBuffer, LPSTR cOutBuffer ) { char *cpIn; char *cpOut; cpIn = cBuffer; cpOut = cOutBuffer; for ( int i = 0; i < nBufferLength / 2; i++ ) { *cpOut++ = '%' // insert the escape character *cpOut++ = *cpIn++; // copy the character and advance the pointers *cpOut++ = *cpIn++; // copy the character and advance the pointers } return ( cpOut - cOutBuffer ); }call it like this:
lcInput = strconv( TheData, 15 ) lcOutput = space( len(lcInput) / 2 * 3 ) Escape( len(lcInput), lcInput, @lcOutput )It should be pretty darned fast (I can't test it right now).
int CEscapeApp::EscapeX(int nBufferLength, LPSTR cInBuffer, LPSTR cOutBuffer ) { char *cpIn; char *cpOut; cpIn = cBuffer; cpOut = cOutBuffer; for ( int i = 0; i < nBufferLength / 2; i++ ) { cpOut++; // skip the % already in the buffer *cpOut++ = *cpIn++; // copy the character and advance the pointers *cpOut++ = *cpIn++; // copy the character and advance the pointers // if you want to obfuscate it a little *g* pre and post increment cpOut // *++cpOut++ = *cpIn++; // skip the %, copy the character and advance the pointers // *cpOut++ = *cpIn++; // copy the character and advance the pointers } return ( cpOut - cOutBuffer ); }call it like this:
declare integer EscapeX in C:\VFP8App\df_foxpro\dequote\release\dequote.dll ; integer nBufferLength, ; string cInputBuffer, ; string @cOutputBuffer lcStr = strconv( replicate( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+", 10000 ), 15 ) ? left( lcStr, 30 ) lnLength = len( lcStr ) lnStart = seconds() lcEscape = replicate( "%", lnLength / 2 * 3 ) ? EscapeX( lnLength, lcStr, @lcEscape ) lnStart = seconds() - lnStart ? lnStart, len( lcStr ), left( lcEscape, 40 )On a P4M 2.5gz box it averages 0.06 seconds to allocate the output buffer and % escape the 1,480,000 characters.
>function HtoE(cStr){ >var cNew=""; >for (var i=0; i<cStr.length; i=i+2){ > cNew+= "%" + cStr.substr(i,2); > } >return unescape(cNew); >}>