Kaydet (Commit) 7c41a3e5 authored tarafından Noel Grandin's avatar Noel Grandin

simplify OSQLScanner::SQLyyerror

...buffer management

Change-Id: I649a93ed5bd9bd7d4ac8ec73fc956eb8532eac89
Reviewed-on: https://gerrit.libreoffice.org/38206Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 9956849c
...@@ -717,15 +717,10 @@ void OSQLScanner::SQLyyerror(char const *fmt) ...@@ -717,15 +717,10 @@ void OSQLScanner::SQLyyerror(char const *fmt)
m_sErrorMessage += ": "; m_sErrorMessage += ": ";
::rtl::OUString aError; ::rtl::OUString aError;
static sal_Int32 BUFFERSIZE = 256; OUStringBuffer Buffer(256);
static sal_Char* Buffer = nullptr;
if(!Buffer)
Buffer = new sal_Char[BUFFERSIZE];
sal_Char *s = Buffer;
sal_Int32 nPos = 1;
int ch = SQLyytext ? (SQLyytext[0] == 0 ? ' ' : SQLyytext[0]): ' '; int ch = SQLyytext ? (SQLyytext[0] == 0 ? ' ' : SQLyytext[0]): ' ';
*s++ = ch; Buffer.append((sal_Unicode)ch);
while (!checkeof(ch = yyinput())) while (!checkeof(ch = yyinput()))
{ {
if (ch == ' ') if (ch == ' ')
...@@ -735,31 +730,18 @@ void OSQLScanner::SQLyyerror(char const *fmt) ...@@ -735,31 +730,18 @@ void OSQLScanner::SQLyyerror(char const *fmt)
if (!checkeof(ch)) if (!checkeof(ch))
unput(ch); unput(ch);
} }
*s = '\0'; aError = Buffer.makeStringAndClear();
aError = ::rtl::OUString(Buffer,nPos,RTL_TEXTENCODING_UTF8);
break; break;
} }
else else
{ {
*s++ = ch; Buffer.append((sal_Unicode)ch);
if (++nPos == BUFFERSIZE) }
{ }
::rtl::OString aBuf(Buffer); m_sErrorMessage += aError;
delete[] Buffer; }
BUFFERSIZE *=2; IN_SQLyyerror = false;
Buffer = new sal_Char[BUFFERSIZE]; YY_FLUSH_BUFFER;
for(sal_Int32 i=0;i<aBuf.getLength();++i,++Buffer)
*Buffer = aBuf.getStr()[i];
s = &Buffer[nPos];
}
}
}
m_sErrorMessage += aError;
delete[] Buffer;
Buffer = nullptr;
}
IN_SQLyyerror = false;
YY_FLUSH_BUFFER;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment