LibreOffice Module sc (master) 1
Classes | Functions
impex.hxx File Reference
#include <o3tl/deleter.hxx>
#include <sot/formats.hxx>
#include <address.hxx>
#include <tools/stream.hxx>
#include <com/sun/star/uno/Any.hxx>
Include dependency graph for impex.hxx:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


struct  ScExportTextOptions
 These options control how multi-line cells are converted during export in certain lossy formats (such as csv). More...
class  ScImportExport
class  ScImportStringStream


SC_DLLPUBLIC OUString ReadCsvLine (SvStream &rStream, bool bEmbeddedLineBreak, OUString &rFieldSeparators, sal_Unicode cFieldQuote, sal_Unicode &rcDetectSep, sal_uInt32 nMaxSourceLines=0)
 Read a CSV (comma separated values) data line using ReadUniOrByteStringLine(). More...

Function Documentation

◆ ReadCsvLine()

SC_DLLPUBLIC OUString ReadCsvLine ( SvStream rStream,
bool  bEmbeddedLineBreak,
OUString &  rFieldSeparators,
sal_Unicode  cFieldQuote,
sal_Unicode rcDetectSep,
sal_uInt32  nMaxSourceLines = 0 

Read a CSV (comma separated values) data line using ReadUniOrByteStringLine().

bEmbeddedLineBreakIf TRUE and a line-break occurs inside a field of data, a line feed LF '
' and the next line are appended. Repeats until a line-break is not in a field. A field is determined by delimiting rFieldSeparators and optionally surrounded by a pair of cFieldQuote characters. For a line-break to be within a field, the field content MUST be surrounded by cFieldQuote characters, and the opening cFieldQuote MUST be at the very start of a line or follow right behind a field separator with no extra characters in between, with the exception of blanks contradictory to RFC 4180. Anything, including field separators and escaped quotes (by doubling them) may appear in a quoted field.

If bEmbeddedLineBreak==FALSE, nothing is parsed and the string returned is simply one ReadUniOrByteStringLine().

rFieldSeparatorsA list of characters that each may act as a field separator. If rcDetectSep was 0 and a separator is detected then it is appended to rFieldSeparators.
cFieldQuoteThe quote character used.
rcDetectSepIf 0 then attempt to detect a possible separator if rFieldSeparators doesn't include it already. This can be necessary because of the "accept broken misquoted CSV fields" feature that tries to ignore trailing blanks after a quoted field and if no separator follows continues to add content to the field assuming the single double quote was in error. It is also necessary if the only possible separator was not selected and not included in rFieldSeparators and a line starts with a quoted field, in which case appending lines is tried until end of file. If a separator is detected it is added to rFieldSeparators and the line is reread with the new separators
nMaxSourceLinesMaximum source lines to read and combine into one logical line for embedded new line purpose. Should be limited for the preview dialog because only non-matching separators selected otherwise would lead to trying to concatenate lines until file end. If 0 no limit other than the internal arbitrary resulting line length limit.

check Stream::good() to detect IO problems during read

@ATTENTION Note that the string returned may be truncated even inside a quoted field if some (arbitrary) maximum length was reached. There currently is no way to exactly determine the conditions, whether this was at a line end, or whether open quotes would have closed the field before the line end, as even a ReadUniOrByteStringLine() may return prematurely but the stream was positioned ahead until the real end of line. Additionally, due to character encoding conversions, string length and bytes read don't necessarily match, and resyncing to a previous position matching the string's length isn't always possible. As a result, a logical line with embedded line breaks and more than the maximum length characters will be spoiled, and a subsequent ReadCsvLine() may start under false preconditions.

Definition at line 2738 of file impex.cxx.

References aStr, SvStream::eof(), SvStream::GetStreamCharSet(), lcl_isEscapedOrFieldEndQuote(), lcl_UnicodeStrChr(), nArbitraryLineLengthLimit, p, SvStream::ReadUniOrByteStringLine(), SvStream::Seek(), and SvStream::Tell().

Referenced by ScImportExport::ExtText2Doc(), and ScImportAsciiDlg::GetLine().