Add comment chars escaping

pull/6763/head^2
Gokhan Gulbiz 2023-03-15 08:09:24 +03:00
parent 89e6623960
commit dbc26cacb5
No known key found for this signature in database
GPG Key ID: 608EF06B6BD1B45B
1 changed files with 49 additions and 2 deletions

View File

@ -64,8 +64,8 @@ static void MultiTenantMonitorSMInit(void);
static int CreateTenantStats(MultiTenantMonitor *monitor, time_t queryTime);
static int FindTenantStats(MultiTenantMonitor *monitor);
static size_t MultiTenantMonitorshmemSize(void);
static char * extractTopComment(const char *inputString);
static char * get_substring(const char *str, int start, int end);
static char * EscapeCommentChars(const char *str);
static char * UnescapeCommentChars(const char *str);
int MultiTenantMonitoringLogLevel = CITUS_LOG_LEVEL_OFF;
int CitusStatsTenantsPeriod = (time_t) 60;
@ -726,3 +726,50 @@ get_substring(const char *str, int start, int end)
return substr;
}
/* EscapeCommentChars adds a backslash before each occurrence of '*' or '/' in the input string */
static char *
EscapeCommentChars(const char *str)
{
int len = strlen(str);
char *new_str = (char *) malloc(len * 2 + 1);
int j = 0;
for (int i = 0; i < len; i++)
{
if (str[i] == '*' || str[i] == '/')
{
new_str[j++] = '\\';
}
new_str[j++] = str[i];
}
new_str[j] = '\0';
return new_str;
}
/* UnescapeCommentChars removes the backslash that precedes '*' or '/' in the input string. */
static char *
UnescapeCommentChars(const char *str)
{
int len = strlen(str);
char *new_str = (char *) malloc(len + 1);
int j = 0;
for (int i = 0; i < len; i++)
{
if (str[i] == '\\' && i < len - 1)
{
if (str[i + 1] == '*' || str[i + 1] == '/')
{
i++;
}
}
new_str[j++] = str[i];
}
new_str[j] = '\0';
return new_str;
}