1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-17 21:25:58 +02:00

Correct escaped quotations.

This commit is contained in:
Alain Magloire 2003-01-23 20:58:31 +00:00
parent 7420278c4c
commit f0c97590fa
2 changed files with 12 additions and 26 deletions

View file

@ -733,25 +733,16 @@ unsigned int _stdcall waitProcTermination(void* pv)
// Return number of bytes in target or -1 in case of error // Return number of bytes in target or -1 in case of error
int copyTo(char * target, const char * source, int cpyLength, int availSpace) int copyTo(char * target, const char * source, int cpyLength, int availSpace)
{ {
#ifdef DEBUG_MONITOR
char buffer[1000];
#endif
BOOL bSlash = FALSE; BOOL bSlash = FALSE;
int i = 0, j = 0; int i = 0, j = 0;
int totCpyLength = cpyLength; int totCpyLength = cpyLength;
BOOL bQoutedTerm = FALSE; BOOL bQoutedTerm = FALSE;
#ifdef DEBUG_MONITOR
sprintf(buffer, "copyTo start: %s %d %d\n", source, cpyLength, availSpace);
OutputDebugString(buffer);
#endif
if(availSpace <= cpyLength) // = to reserve space for final '\0' if(availSpace <= cpyLength) // = to reserve space for final '\0'
return -1; return -1;
//strncpy(target, source, cpyLength);
//return cpyLength;
if(('\"' == *source) && ('\"' == *(source + cpyLength))) if(('\"' == *source) && ('\"' == *(source + cpyLength - 1)))
bQoutedTerm = TRUE; // Already quoted bQoutedTerm = TRUE; // Already quoted
else else
if(strchr(source, ' ') == NULL) if(strchr(source, ' ') == NULL)
@ -768,19 +759,19 @@ int copyTo(char * target, const char * source, int cpyLength, int availSpace)
if(source[i] == '\\') if(source[i] == '\\')
bSlash = TRUE; bSlash = TRUE;
else else
if((source[i] == '\"') && (!bQoutedTerm || (i != 0) || i != (cpyLength)) )
{ {
if(!bSlash) if(source[i] == '\"' && (!bQoutedTerm || ((i != 0) && (i != (cpyLength - 1))) ) )
{ {
if(j == availSpace) if(!bSlash) // If still not escaped
return -1; {
target[j] = '\\'; if(j == availSpace)
++j; return -1;
target[j] = '\\';
++j;
}
} }
bSlash = FALSE; bSlash = FALSE;
} }
else
bSlash = FALSE;
if(j == availSpace) if(j == availSpace)
return -1; return -1;
@ -795,10 +786,6 @@ int copyTo(char * target, const char * source, int cpyLength, int availSpace)
++j; ++j;
} }
#ifdef DEBUG_MONITOR
sprintf(buffer, "copyTo: %s %d %d\n", source, j, cpyLength);
OutputDebugString(buffer);
#endif
return j; return j;
} }

View file

@ -188,11 +188,10 @@ int copyTo(LPTSTR target, LPCTSTR source, int cpyLength, int availSpace)
int i = 0, j = 0; int i = 0, j = 0;
int totCpyLength = cpyLength; int totCpyLength = cpyLength;
BOOL bQoutedTerm = FALSE; BOOL bQoutedTerm = FALSE;
if(availSpace <= cpyLength) // = to reserve space for '\0' if(availSpace <= cpyLength) // = to reserve space for '\0'
return -1; return -1;
if((_T('\"') == *source) && (_T('\"') == *(source + cpyLength))) if((_T('\"') == *source) && (_T('\"') == *(source + cpyLength - 1)))
bQoutedTerm = TRUE; // Already quoted bQoutedTerm = TRUE; // Already quoted
else else
if(_tcschr(source, _T(' ')) == NULL) if(_tcschr(source, _T(' ')) == NULL)
@ -209,7 +208,8 @@ int copyTo(LPTSTR target, LPCTSTR source, int cpyLength, int availSpace)
if(source[i] == _T('\\')) if(source[i] == _T('\\'))
bSlash = TRUE; bSlash = TRUE;
else else
if((source[i] == _T('\"')) && (!bQoutedTerm || (i != 0) || i != (cpyLength)) ) // Escape double quote only if quotation mark is not start or end character
if((source[i] == _T('\"')) && (!bQoutedTerm || ((i != 0) && (i != (cpyLength - 1)))) )
{ {
if(!bSlash) if(!bSlash)
{ {
@ -235,7 +235,6 @@ int copyTo(LPTSTR target, LPCTSTR source, int cpyLength, int availSpace)
target[j] = _T('\"'); target[j] = _T('\"');
++j; ++j;
} }
return j; return j;
} }