mirror of https://github.com/citusdata/citus.git
Use stringinfo for escaping/unescaping
parent
0744384bac
commit
0b06e64c3f
|
@ -28,6 +28,7 @@
|
||||||
#include "utils/json.h"
|
#include "utils/json.h"
|
||||||
#include "distributed/utils/attribute.h"
|
#include "distributed/utils/attribute.h"
|
||||||
#include "common/base64.h"
|
#include "common/base64.h"
|
||||||
|
#include "miscadmin.h"
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
@ -757,31 +758,28 @@ static char *
|
||||||
EscapeCommentChars(const char *str)
|
EscapeCommentChars(const char *str)
|
||||||
{
|
{
|
||||||
int originalStringLength = strlen(str);
|
int originalStringLength = strlen(str);
|
||||||
char *escapedString = (char *) palloc0((originalStringLength * 2 + 1) * sizeof(char));
|
StringInfo escapedString = makeStringInfo();
|
||||||
int escapedStringIndex = 0;
|
|
||||||
|
|
||||||
for (int originalStringIndex = 0; originalStringIndex < originalStringLength;
|
for (int originalStringIndex = 0; originalStringIndex < originalStringLength;
|
||||||
originalStringIndex++)
|
originalStringIndex++)
|
||||||
{
|
{
|
||||||
if (str[originalStringIndex] == '*' || str[originalStringIndex] == '/')
|
if (str[originalStringIndex] == '*' || str[originalStringIndex] == '/')
|
||||||
{
|
{
|
||||||
escapedString[escapedStringIndex++] = '\\';
|
appendStringInfoChar(escapedString, '\\');
|
||||||
}
|
|
||||||
escapedString[escapedStringIndex++] = str[originalStringIndex];
|
|
||||||
}
|
|
||||||
escapedString[escapedStringIndex] = '\0';
|
|
||||||
|
|
||||||
return escapedString;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
appendStringInfoChar(escapedString, str[originalStringIndex]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return escapedString->data;
|
||||||
|
}
|
||||||
|
|
||||||
/* UnescapeCommentChars removes the backslash that precedes '*' or '/' in the input string. */
|
/* UnescapeCommentChars removes the backslash that precedes '*' or '/' in the input string. */
|
||||||
static char *
|
static char *
|
||||||
UnescapeCommentChars(const char *str)
|
UnescapeCommentChars(const char *str)
|
||||||
{
|
{
|
||||||
int originalStringLength = strlen(str);
|
int originalStringLength = strlen(str);
|
||||||
char *unescapedString = (char *) palloc0((originalStringLength + 1) * sizeof(char));
|
StringInfo unescapedString = makeStringInfo();
|
||||||
int unescapedStringIndex = 0;
|
|
||||||
|
|
||||||
for (int originalStringindex = 0; originalStringindex < originalStringLength;
|
for (int originalStringindex = 0; originalStringindex < originalStringLength;
|
||||||
originalStringindex++)
|
originalStringindex++)
|
||||||
|
@ -793,9 +791,8 @@ UnescapeCommentChars(const char *str)
|
||||||
{
|
{
|
||||||
originalStringindex++;
|
originalStringindex++;
|
||||||
}
|
}
|
||||||
unescapedString[unescapedStringIndex++] = str[originalStringindex];
|
appendStringInfoChar(unescapedString, str[originalStringindex]);
|
||||||
}
|
}
|
||||||
unescapedString[unescapedStringIndex] = '\0';
|
|
||||||
|
|
||||||
return unescapedString;
|
return unescapedString->data;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue