Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need a simple FLL
Message
 
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Miscellaneous
Thread ID:
01154766
Message ID:
01155306
Views:
16
Mark,

Updated 23:44 CDT with corrected C++ code.

If you have Visual Studio available, snag the dequote example from my website and alter it to use a member function like this:
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).

* Update - this might be a tad faster:
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.

>I need a fast way to convert relatively large ascii strings to their "escaped" hex equivalent for use within dynamically generated javascript. Here I mean where "ABC" becomes "%41%42%43". This will be used as a support routine on a web server for generating portions of web pages that are intentionally obfuscated. It needs to be fast and callable from a VFP COM DLL that is working in conjunction with an ASP app to generate the web pages.
>
>The STRCONV function with opcode of 15 is very close in that it produces an ascii to hex conversion, but it does not include the javascript escape character "%".
>
>What I'm doing now is using STRCONV as above, then passing the result to the browser, and having a browser-side javascript function fix up the string so it can be passed to the unescape function as shown below. Whatever is passed back from the function is either document.written into the page or eval()'d if it's global-scope javascript code rather than HTML.
>function HtoE(cStr){
>var cNew="";
>for (var i=0; i<cStr.length; i=i+2){
>  cNew+= "%" + cStr.substr(i,2);
>  }
>return unescape(cNew);
>}
>
>Thanks very much for any suggestions.
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Reply
Map
View

Click here to load this message in the networking platform