/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// Read each segment, and calculate it's size by interpreting it as a // character stream. Assume that no characters are split by the segments. bool bLastSegmRead = false;
std::vector<char> aSegmentBytes; do
{
bLastSegmRead = m_aBlob->readOneSegment( aSegmentBytes );
OUString sSegment(aSegmentBytes.data(), aSegmentBytes.size(), RTL_TEXTENCODING_UTF8);
m_aBlob->closeInput(); // reset position return m_nCharCount;
}
OUString SAL_CALL Clob::getSubString(sal_Int64 nPosition,
sal_Int32 nLength)
{ if (nPosition < 1) // XClob is indexed from 1 throw lang::IllegalArgumentException(u"nPosition < 1"_ustr, *this, 0);
--nPosition; // make 0-based
if (nLength < 0) throw lang::IllegalArgumentException(u"nLength < 0"_ustr, *this, 0);
MutexGuard aGuard(m_aMutex);
checkDisposed(Clob_BASE::rBHelper.bDisposed); // TODO do not reset position if it is not necessary
m_aBlob->closeInput(); // reset position
for (;;)
{ bool bLastRead = m_aBlob->readOneSegment( aSegmentBytes ); // TODO: handle possible case of split UTF-8 character
OUString sSegment(aSegmentBytes.data(), aSegmentBytes.size(), RTL_TEXTENCODING_UTF8);
// skip irrelevant parts if (sSegment.getLength() < nPosition)
{ if (bLastRead) throw lang::IllegalArgumentException(u"nPosition out of range"_ustr, *this, 0);
nPosition -= sSegment.getLength(); continue;
}
// Getting here for the first time, nPosition may be > 0, meaning copy start offset. // This also handles sSegment.getLength() == nPosition case, including nLength == 0. const sal_Int32 nCharsToCopy = std::min<sal_Int32>(sSegment.getLength() - nPosition,
nLength - sSegmentBuffer.getLength());
sSegmentBuffer.append(sSegment.subView(nPosition, nCharsToCopy)); if (sSegmentBuffer.getLength() == nLength) return sSegmentBuffer.makeStringAndClear();
assert(sSegmentBuffer.getLength() < nLength);
if (bLastRead) throw lang::IllegalArgumentException(u"out of range"_ustr, *this, 0);
nPosition = 0; // No offset after first append
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.