The online community for software testing & quality assurance professionals
 
 
Calendar   Today's Topics
Sponsors:
Lost Password?

Home
BetaSoft
Blogs
Jobs
Training
News
Links
Downloads



Testing Tools >> HP/Mercury LoadRunner

thorwath
Veteran


Reged: 07/22/99
Posts: 3770
Loc: Grand Rapids, MI
yet more String conversion functions
      09/14/07 07:07 PM

There are already variations above on a one or two of these, but I just completed my first LR project where I had to correlate with two or three variations of the original string, both performing additional hex char conversions beyond that provided by web_convert_param(), as well as then stripping chars from those original correlations (we use Actuate's web app to produce some of our reports, which required these conversion variants).

At any rate all of these functions encapsulate the needed buffer allocations and are buffer safe--assuming you don't run out of memory. The output string is always saved to an LR parameter specified in the call. I tested all pretty thoroughly prior to using them without incident on my project.

-Terry Horwath

Code:


/******************************************************************************
*
* gEncodeHTMLString()
*
* Converts inStr to encoded HTML, which is saved in {outParmName} parameter.
* If the {outParmName} parameter does not exist it will be created; if it
* exists it will be overwritten.
*
* Example: gEncodeHTMLString("blah", "a+b=c++def=="));
*
* places "a%2Bb%3Dc%2B%2Bdef%3D%3D" in {blah} parameter
*
******************************************************************************
*/
void gEncodeHTMLString(char *outParmName, char *inStr)
{
char *srcString;
int bufSize=(strlen(inStr)*3)+100; //buffer overrun is impossible

srcString = (char *)calloc(bufSize, sizeof(char));

strcpy(srcString, "SourceString=");
strcat(srcString, inStr);

web_convert_param(outParmName, srcString, "SourceEncoding=HTML", "TargetEncoding=URL", LAST);

free(srcString);
}


/******************************************************************************
*
* gEncodeStringChar()
*
* Parses the string pointed to by *inStr, converting all cDelim chars
* to it's ASCII hex equivlent in the form:
*
* Example: when cDelim = '_', it is converted to "%5f"
*
* The converted string is saved to the *outParmName parameter. If the
* {outParmName} parameter does not exist it will be created; if it
* exists it will be overwritten.
*
******************************************************************************
*/
void gEncodeStringChar(char *outParmName, char *inStr, char cDelim) {

char c, *buf;
int i, j=0, bufSize=(strlen(inStr)*3)+100; //buffer overrun is impossible

buf = (char *)calloc(bufSize, sizeof(char));

//lr_output_message("buf[] size is: %d", bufSize);

for (i=0; j<bufSize; i++) {

if ((c=inStr[i]) == '\0') {
break; //input string has been fully converted
}
if (c == cDelim) {

sprintf(buf, "%s%%%02x", buf, cDelim);
j+=2;
} else {
buf[j] = c;
}
j++;
//lr_output_message("c: '%c', cDelim: '%c', buf[]: %s", c, cDelim, buf);
}
lr_save_string(buf, outParmName);
free(buf);
}


/******************************************************************************
*
* gStripStringChar()
*
* Parses the string pointed to by *inStr, deleting all its cDeleteMe chars
* from the string.
*
* The converted string is saved to the *outParmName parameter. If the
* {outParmName} parameter does not exist it will be created; if it
* exists it will be overwritten.
*
******************************************************************************
*/
void gStripStringChar(char *outParmName, char *inStr, char cDeleteMe) {

char c, *buf;
int i, j=0, bufSize=strlen(inStr)+1; //buffer overrun is impossible

buf = (char *)calloc(bufSize, sizeof(char));

for (i=0; j<bufSize; i++) {

if ((c=inStr[i]) == '\0') {
buf[j]='\0';
break; //input string has been fully parsed
}
if (c != cDeleteMe) {
buf[j++] = c;
}
//lr_output_message("c: '%c', cDeleteMe: '%c', buf[]: %s", c, cDeleteMe, buf);
}
lr_save_string(buf, outParmName);
free(buf);
}



Post Extras Print Post   Remind Me!     Notify Moderator


Entire topic
Subject Posted by Posted on
* = ** CODE SHARE ** = JakeBrakeModerator 05/09/07 06:02 AM
. * * Re: = ** CODE SHARE ** = Jagadish_S   05/12/10 02:32 AM
. * * Re: = ** CODE SHARE ** = JakeBrakeModerator   04/07/09 08:55 AM
. * * Re: = ** CODE SHARE ** = JakeBrakeModerator   05/07/09 03:24 AM
. * * Re: = ** CODE SHARE ** = TReddy   12/12/08 01:35 PM
. * * Re: = ** CODE SHARE ** = JakeBrakeModerator   12/13/08 09:42 AM
. * * Re: = ** CODE SHARE ** = TReddy   12/13/08 04:27 PM
. * * = ** CODE SHARE ** = JakeBrakeModerator   03/14/09 03:56 AM
. * * Re: = ** CODE SHARE ** = TReddy   03/15/09 07:25 AM
. * * yet more String conversion functions thorwath   09/14/07 07:07 PM
. * * Re: yet more String conversion functions thorwath   09/16/07 06:08 AM
. * * = ** CODE SHARE ** = terri cModerator   10/03/07 05:19 AM
. * * Better LR Support for strstr ptrussell_nc   10/31/08 08:44 AM
. * * Re: = ** CODE SHARE ** = JakeBrakeModerator   05/16/07 07:27 AM
. * * Re: = ** CODE SHARE ** = Chid   05/30/07 07:29 AM
. * * Re: = ** CODE SHARE ** = JakeBrakeModerator   06/05/07 11:07 AM
. * * Re: = ** CODE SHARE ** = minnal   06/08/07 10:43 AM
. * * Re: = ** CODE SHARE ** = minnal   06/14/07 07:57 AM
. * * = ** Code Share ** = JakeBrakeModerator   06/24/07 07:00 AM
. * * Re: = ** Code Share ** = Jagadish_S   05/12/10 02:28 AM
. * * ** Code Share ** JakeBrakeModerator   07/30/07 06:29 PM
. * * = ** Code Share ** = - Date Comparison ptrussell_nc   08/01/07 07:25 AM
. * * = ** Code Share ** = String Conversion ptrussell_nc   08/07/07 11:01 AM
. * * Re: = ** Code Share ** = VB mid Function ptrussell_nc   08/16/07 07:04 AM
. * * Re: = ** Code Share ** = Generating Time Stamp Chid   08/16/07 01:37 PM
. * * ** Code Share ** = Dynamic Array Handler Ver 3.0 Chid   08/17/07 02:08 PM
. * * Re: ** Code Share ** = Dynamic Array Handler Ver 3.0 jlesiak   12/30/08 09:16 AM
. * * Re: ** Code Share ** = Dynamic Array Handler Ver 3.0 pridge   08/18/10 09:19 AM
. * * Re: ** Code Share ** = Dynamic Array Handler Ver 3.0 JimHowell1970   08/19/10 06:57 AM
. * * Re: ** Code Share ** = Dynamic Array Handler Ver 3.0 pridge   08/19/10 09:44 AM
. * * Re: ** Code Share ** = Dynamic Array Handler Ver 3.0 JakeBrakeModerator   12/30/08 09:41 AM
. * * Re: ** Code Share ** = Dynamic Array Handler Ver 3.0 jlesiak   12/30/08 10:17 AM
. * * Code Share: Assert for LR ptrussell_nc   01/09/09 07:39 AM
. * * Re: ** Code Share ** = Dynamic Array Handler Ver TReddy   08/24/07 10:38 AM
. * * ** Code Share ** = Client Popup Win Handler JakeBrakeModerator   09/08/07 09:04 AM

Extra information
0 registered and 13 anonymous users are browsing this forum.

Moderator:  JakeBrake, TedZlat, AJ, James Pulley, terri c 



Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating: *****
Thread views: 12101

Rate this thread

Jump to

Contact Us | Privacy statement SQAForums

Powered by UBB.threads™ 6.5.5