Kaydet (Commit) ded4dcbb authored tarafından Tamas Bunth's avatar Tamas Bunth Kaydeden (comit) Tamás Bunth

tdf#117115 dbahsql: respect unicode in columns

Change-Id: I6a1dcba0afda88eaf083f0d4c73c1e74b0c78f56
Reviewed-on: https://gerrit.libreoffice.org/54297Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTamás Bunth <btomi96@gmail.com>
üst 2f11ce06
......@@ -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)
......
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