hello experts
Her eis my problem, that I have been struggling with. I am writing a library (SO) on soalris to be used by some 3rd party application. It accepts calls to internal procedures using its own language given you pass it through their c function, which is run_code(arg);
So I have to pass in the internal call to this function run_code(arg). Thus I have a line that looks like
run_code(internalFunction/SubRoutine("arg1", "arg2", ..., "arg n"))
The problem is if any of the args to the internal function call have any of the following characters in its string (i.e " quote, ' single quote, \ backslash, or ) right parenthesis) then it has a problem. The run_code function, which is vendor propietary can not handle these characters, thus I need to replace any of these special characters with "entity refernece" and then replace it once we get through this wall (run_code)... Thus I want to do the following....
Given this call...
run_code(Class/Method("my argument with special chars is: )'"\", "next arg", "last arg"))
needs to be turned into this
run_code(Class/Method("my argument with special chars is: #rpar;#apos;#quot;#bksl;", "next arg", "last arg"))
were
) -> #rpar;
\ -> #bksl;
' -> #apos;
" -> #quot;
I have a wonderful substring replacement function that I wrote, that would work great if I could break this into tokens successfully... replacing the single quot and backslash really aren't a problem because they are not special within the function call itself... I can just do a substring replacement for single quot and backslash for the whole string... the problem is the " double quote and ) right parenthesis...
What I need is something that will read this string... and give me a substring that I can do replacements on, were the substring is delimited by "...", or "..."))
that is give me a sub string if it begins with " has some stuff and is followed by ", " (i include comma b/c there may be " in the argument) or " ... ")) and 2 parenthesis followed by no more characters or white space... (signaling end of call.. i.e. last argument)
Sorry if that is confusing.. it is confusing me too.. that is why I need help. In simple words I need a way to replace the following character " ' ) and \ when they are used as characters in the argument portion of the call below.
run_code(Class/Method("my argument with special chars is: )'"\", "next arg", "last arg"))
Any help, thoughts, or ideas...?? pseudo code, examples greatly welcomed... This should be highly flexible in case the user
Thanks in advance
rechard
boolean inEscape;
boolean collecting;
char* collector;
char* escapeseq;
int collidx;
int escapeidx;
inEscape = false;
collecting = false;
collidx = 0;
escidx = 0;
for( int i = 0; i < strlen; i++ )
{
// Check if we are a token delimiter
if( str[i] == ' ' || str[i] == '\t' || str[i] == '\n' )
{
// Assumes you are breaking tokens into a list
if( collecting )
{
// NULL Terminate
collector[ collidx ] = 0;
addToken( collector );
}
collecting = false;
collector = malloc( MAXTOKEN );
collidx = 0;
continue;
}
if( inEscape == false && str[i] == '#' )
{
inEscape = true;
escidx = 0;
}
if( inEscape == true && str[i] == ';' )
{
inEscape = false;
// NULL Terminate
escapeseq[escidx] = 0;
if( strcmp( escapeseq, "rpar" ) == 0 )
collector[ collidx ] == ')';
else if( strcmp( escapeseq, "bksl" ) == 0 )
collector[ collidx ] == '\\';
else if( strcmp( escapeseq, "apos" ) == 0 )
collector[ collidx ] == '\'';
else if( strcmp( escapeseq, "quot" ) == 0 )
collector[ collidx ] == '"';
else
return SYNTAX_ERROR;
collidx++;
continue;
}
else if( inEscape == true )
{
escapeseq[ escidx++ ] = str[ i ];
continue;
}
collector[ collidx++ ] = str[i];
collecting = true;
}