[Libreoffice-commits] core.git: dbaccess/source
Tamas Bunth
tamas.bunth at collabora.co.uk
Fri May 25 13:27:42 UTC 2018
dbaccess/source/filter/hsqldb/createparser.cxx | 39 ++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
New commits:
commit ded4dcbbce875efeffba7e894a6dea1f584e8e9b
Author: Tamas Bunth <tamas.bunth at collabora.co.uk>
Date: Mon May 14 09:19:56 2018 +0200
tdf#117115 dbahsql: respect unicode in columns
Change-Id: I6a1dcba0afda88eaf083f0d4c73c1e74b0c78f56
Reviewed-on: https://gerrit.libreoffice.org/54297
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Tamás Bunth <btomi96 at gmail.com>
diff --git a/dbaccess/source/filter/hsqldb/createparser.cxx b/dbaccess/source/filter/hsqldb/createparser.cxx
index 893cfa93330a..9054a2f9bf72 100644
--- a/dbaccess/source/filter/hsqldb/createparser.cxx
+++ b/dbaccess/source/filter/hsqldb/createparser.cxx
@@ -27,6 +27,42 @@ using namespace css::sdbc;
namespace
{
+//Find ascii escaped unicode
+sal_Int32 lcl_IndexOfUnicode(const OString& rSource, const sal_Int32 nFrom = 0)
+{
+ const OString sHexDigits = "0123456789abcdefABCDEF";
+ sal_Int32 nIndex = rSource.indexOf("\\u", nFrom);
+ if (nIndex == -1)
+ {
+ return -1;
+ }
+ bool bIsUnicode = true;
+ for (short nDist = 2; nDist <= 5; ++nDist)
+ {
+ if (sHexDigits.indexOf(rSource[nIndex + nDist]) == -1)
+ {
+ bIsUnicode = false;
+ }
+ }
+ return bIsUnicode ? nIndex : -1;
+}
+
+//Convert ascii escaped unicode to utf-8
+OUString lcl_ConvertToUTF8(const OString& rText)
+{
+ OString sResult = rText;
+ sal_Int32 nIndex = lcl_IndexOfUnicode(sResult);
+ while (nIndex != -1 && nIndex < rText.getLength())
+ {
+ const OString sHex = sResult.copy(nIndex + 2, 4);
+ const sal_Unicode cDec = static_cast<sal_Unicode>(strtol(sHex.getStr(), nullptr, 16));
+ const OString sNewChar = OString(&cDec, 1, RTL_TEXTENCODING_UTF8);
+ sResult = sResult.replaceAll("\\u" + sHex, sNewChar);
+ nIndex = lcl_IndexOfUnicode(sResult, nIndex);
+ }
+ return OStringToOUString(sResult, RTL_TEXTENCODING_UTF8);
+}
+
/// Returns substring of sSql from the first occurrence of '(' until the
/// last occurrence of ')' (excluding the parenthesis)
OUString lcl_getColumnPart(const OUString& sSql)
@@ -192,7 +228,7 @@ void CreateStmtParser::parseColumnPart(const OUString& sColumnPart)
// to fetch the whole column name, including quotes
auto nEndColumnName
= bIsQuoteUsedForColumnName ? sColumn.indexOf("\"", 1) : sColumn.indexOf(" ");
- const OUString& rColumnName
+ OUString rColumnName
= sColumn.copy(0, bIsQuoteUsedForColumnName ? nEndColumnName + 1 : nEndColumnName);
// create a buffer which begins on column type
@@ -232,6 +268,7 @@ void CreateStmtParser::parseColumnPart(const OUString& sColumnPart)
}
bool bCaseInsensitive = sTypeName.indexOf("IGNORECASE") >= 0;
+ rColumnName = lcl_ConvertToUTF8(OUStringToOString(rColumnName, RTL_TEXTENCODING_UTF8));
bool isPrimaryKey = lcl_isPrimaryKey(sColumn);
if (isPrimaryKey)
More information about the Libreoffice-commits
mailing list