Kaydet (Commit) 94e3f3e5 authored tarafından Matteo Casalin's avatar Matteo Casalin

Simplify sw_GetCellPosition

Change-Id: If672256b85c1e0a6534055844c3df936c0636c3f
üst 541dcc5b
...@@ -352,32 +352,31 @@ void sw_GetCellPosition(const OUString &rCellName, ...@@ -352,32 +352,31 @@ void sw_GetCellPosition(const OUString &rCellName,
sal_Int32 &rColumn, sal_Int32 &rRow) sal_Int32 &rColumn, sal_Int32 &rRow)
{ {
rColumn = rRow = -1; // default return values indicating failure rColumn = rRow = -1; // default return values indicating failure
sal_Int32 nLen = rCellName.getLength(); const sal_Int32 nLen = rCellName.getLength();
if (nLen) if (nLen)
{ {
const sal_Unicode *pBuf = rCellName.getStr(); sal_Int32 nRowPos = 0;
const sal_Unicode *pEnd = pBuf + nLen; while (nRowPos<nLen)
while (pBuf < pEnd && !('0' <= *pBuf && *pBuf <= '9'))
++pBuf;
// start of number found?
if (pBuf < pEnd && ('0' <= *pBuf && *pBuf <= '9'))
{ {
OUString aColTxt(rCellName.getStr(), pBuf - rCellName.getStr()); if (rCellName[nRowPos]>='0' && rCellName[nRowPos]<='9')
OUString aRowTxt(pBuf, (rCellName.getStr() + nLen - pBuf)); {
if (!aColTxt.isEmpty() && !aRowTxt.isEmpty()) break;
}
++nRowPos;
}
if (nRowPos>0 && nRowPos<nLen)
{ {
sal_Int32 nColIdx = 0; sal_Int32 nColIdx = 0;
sal_Int32 nLength = aColTxt.getLength(); for (sal_Int32 i = 0; i < nRowPos; ++i)
for (sal_Int32 i = 0; i < nLength; ++i)
{ {
nColIdx = 52 * nColIdx; nColIdx *= 52;
if (i < nLength - 1) if (i < nRowPos - 1)
++nColIdx; ++nColIdx;
sal_Unicode cChar = aColTxt[i]; const sal_Unicode cChar = rCellName[i];
if ('A' <= cChar && cChar <= 'Z') if ('A' <= cChar && cChar <= 'Z')
nColIdx = nColIdx + (cChar - 'A'); nColIdx += cChar - 'A';
else if ('a' <= cChar && cChar <= 'z') else if ('a' <= cChar && cChar <= 'z')
nColIdx = nColIdx + (26 + cChar - 'a'); nColIdx += 26 + cChar - 'a';
else else
{ {
nColIdx = -1; // sth failed nColIdx = -1; // sth failed
...@@ -386,8 +385,7 @@ void sw_GetCellPosition(const OUString &rCellName, ...@@ -386,8 +385,7 @@ void sw_GetCellPosition(const OUString &rCellName,
} }
rColumn = nColIdx; rColumn = nColIdx;
rRow = aRowTxt.toInt32() - 1; // - 1 because indices ought to be 0 based rRow = rCellName.copy(nRowPos).toInt32() - 1; // - 1 because indices ought to be 0 based
}
} }
} }
OSL_ENSURE( rColumn != -1 && rRow != -1, "failed to get column or row index" ); OSL_ENSURE( rColumn != -1 && rRow != -1, "failed to get column or row index" );
......
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