tdf#117115 dbahsql: respect unicode in columns
Change-Id: I6a1dcba0afda88eaf083f0d4c73c1e74b0c78f56 Reviewed-on: https://gerrit.libreoffice.org/54297 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tamás Bunth <btomi96@gmail.com>
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user