summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-05-30 11:52:34 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-05-31 08:33:03 +0200
commit7c41a3e50433fe67eb361f79121d103929946d23 (patch)
treedb46e3c482a924b25a9eb455d4c094bb935d8a38
parent9956849c2ea6049582e2ccf04c355542c1ef00a1 (diff)
simplify OSQLScanner::SQLyyerror
...buffer management Change-Id: I649a93ed5bd9bd7d4ac8ec73fc956eb8532eac89 Reviewed-on: https://gerrit.libreoffice.org/38206 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--connectivity/source/parse/sqlflex.l38
1 files changed, 10 insertions, 28 deletions
diff --git a/connectivity/source/parse/sqlflex.l b/connectivity/source/parse/sqlflex.l
index e5008c120ff4..9d9f119fd640 100644
--- a/connectivity/source/parse/sqlflex.l
+++ b/connectivity/source/parse/sqlflex.l
@@ -717,15 +717,10 @@ void OSQLScanner::SQLyyerror(char const *fmt)
m_sErrorMessage += ": ";
::rtl::OUString aError;
- static sal_Int32 BUFFERSIZE = 256;
- static sal_Char* Buffer = nullptr;
- if(!Buffer)
- Buffer = new sal_Char[BUFFERSIZE];
+ OUStringBuffer Buffer(256);
- sal_Char *s = Buffer;
- sal_Int32 nPos = 1;
int ch = SQLyytext ? (SQLyytext[0] == 0 ? ' ' : SQLyytext[0]): ' ';
- *s++ = ch;
+ Buffer.append((sal_Unicode)ch);
while (!checkeof(ch = yyinput()))
{
if (ch == ' ')
@@ -735,31 +730,18 @@ void OSQLScanner::SQLyyerror(char const *fmt)
if (!checkeof(ch))
unput(ch);
}
- *s = '\0';
- aError = ::rtl::OUString(Buffer,nPos,RTL_TEXTENCODING_UTF8);
+ aError = Buffer.makeStringAndClear();
break;
}
else
{
- *s++ = ch;
- if (++nPos == BUFFERSIZE)
- {
- ::rtl::OString aBuf(Buffer);
- delete[] Buffer;
- BUFFERSIZE *=2;
- Buffer = new sal_Char[BUFFERSIZE];
- 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;
+ Buffer.append((sal_Unicode)ch);
+ }
+ }
+ m_sErrorMessage += aError;
+ }
+ IN_SQLyyerror = false;
+ YY_FLUSH_BUFFER;
}
//------------------------------------------------------------------------------