LibreOffice Module sc (master) 1
|
#include <comphelper/processfactory.hxx>
#include <i18nlangtag/languagetag.hxx>
#include <i18nutil/unicode.hxx>
#include <sot/formats.hxx>
#include <sfx2/mieclip.hxx>
#include <com/sun/star/i18n/CalendarFieldIndex.hpp>
#include <sal/log.hxx>
#include <unotools/charclass.hxx>
#include <osl/module.hxx>
#include <o3tl/string_view.hxx>
#include <global.hxx>
#include <docsh.hxx>
#include <undoblk.hxx>
#include <rangenam.hxx>
#include <tabvwsh.hxx>
#include <filter.hxx>
#include <asciiopt.hxx>
#include <formulacell.hxx>
#include <cellform.hxx>
#include <progress.hxx>
#include <scitems.hxx>
#include <editable.hxx>
#include <compiler.hxx>
#include <warnbox.hxx>
#include <clipparam.hxx>
#include <impex.hxx>
#include <editutil.hxx>
#include <patattr.hxx>
#include <docpool.hxx>
#include <stringutil.hxx>
#include <cellvalue.hxx>
#include <tokenarray.hxx>
#include <documentimport.hxx>
#include <refundo.hxx>
#include <mtvelements.hxx>
#include <globstr.hrc>
#include <scresid.hxx>
#include <o3tl/safeint.hxx>
#include <tools/svlibrary.h>
#include <unotools/configmgr.hxx>
#include <vcl/svapp.hxx>
#include <vcl/weld.hxx>
#include <editeng/editobj.hxx>
#include <svl/numformat.hxx>
#include <rtl/character.hxx>
#include <rtl/math.hxx>
#include <sax/tools/converter.hxx>
#include <memory>
#include <string_view>
#include <unicode/uchar.h>
#include <osl/endian.h>
Go to the source code of this file.
Typedefs | |
typedef ScFormatFilterPlugin *(* | FilterFn) () |
Functions | |
static bool | lcl_isFieldEnd (sal_Unicode c, const sal_Unicode *pSeps) |
static QuoteType | lcl_isFieldEndQuote (const sal_Unicode *p, const sal_Unicode *pSeps, sal_Unicode &rcDetectSep) |
Determine if *p is a quote that ends a quoted field. More... | |
static QuoteType | lcl_isEscapedOrFieldEndQuote (sal_Int32 nQuotes, const sal_Unicode *p, const sal_Unicode *pSeps, sal_Unicode cStr, sal_Unicode &rcDetectSep) |
Determine if *p is a quote that is escaped by being doubled or ends a quoted field. More... | |
static bool | lcl_appendLineData (OUString &rField, const sal_Unicode *p1, const sal_Unicode *p2) |
Append characters of [p1,p2) to rField. More... | |
static const sal_Unicode * | lcl_ScanString (const sal_Unicode *p, OUString &rField, const sal_Unicode *pSeps, sal_Unicode cStr, DoubledQuoteMode eMode, bool &rbOverflowCell) |
Scan for a quoted string. More... | |
static void | lcl_UnescapeSylk (OUString &rString, SylkVersion eVersion) |
static const sal_Unicode * | lcl_ScanSylkString (const sal_Unicode *p, OUString &rString, SylkVersion eVersion) |
static const sal_Unicode * | lcl_ScanSylkFormula (const sal_Unicode *p, OUString &rString, SylkVersion eVersion) |
static void | lcl_WriteString (SvStream &rStrm, OUString &rString, sal_Unicode cQuote, sal_Unicode cEsc) |
static void | lcl_WriteSimpleString (SvStream &rStrm, std::u16string_view rString) |
static bool | lcl_PutString (ScDocumentImport &rDocImport, bool bUseDocImport, SCCOL nCol, SCROW nRow, SCTAB nTab, const OUString &rStr, sal_uInt8 nColFormat, SvNumberFormatter *pFormatter, bool bDetectNumFormat, bool bDetectSciNumFormat, bool bEvaluateFormulas, bool bSkipEmptyCells, const ::utl::TransliterationWrapper &rTransliteration, CalendarWrapper &rCalendar, const ::utl::TransliterationWrapper *pSecondTransliteration, CalendarWrapper *pSecondCalendar) |
static OUString | lcl_GetFixed (const OUString &rLine, sal_Int32 nStart, sal_Int32 nNext, bool &rbIsQuoted, bool &rbOverflowCell) |
static void | thisModule () |
static const sal_Unicode * | lcl_UnicodeStrChr (const sal_Unicode *pStr, sal_Unicode c) |
OUString | ReadCsvLine (SvStream &rStream, bool bEmbeddedLineBreak, OUString &rFieldSeparators, sal_Unicode cFieldQuote, sal_Unicode &rcDetectSep, sal_uInt32 nMaxSourceLines) |
Read a CSV (comma separated values) data line using ReadUniOrByteStringLine(). More... | |
Variables | |
constexpr sal_Int32 | nArbitraryCellLengthLimit = SAL_MAX_UINT16 |
constexpr sal_Int32 | nArbitraryLineLengthLimit = 2 * MAXCOLCOUNT * nArbitraryCellLengthLimit |
typedef ScFormatFilterPlugin *(* FilterFn) () |
|
static |
Append characters of [p1,p2) to rField.
Definition at line 710 of file impex.cxx.
References nArbitraryCellLengthLimit, and SAL_WARN.
Referenced by lcl_ScanString(), ScImportExport::ScanNextFieldFromString(), and ScImportExport::Text2Doc().
|
static |
Definition at line 1535 of file impex.cxx.
Referenced by ScImportExport::ExtText2Doc().
|
static |
Determine if *p is a quote that is escaped by being doubled or ends a quoted field.
Precondition: *p is a quote.
nQuotes | Quote characters encountered so far. Odd (after opening quote) means either no embedded quotes or only quote pairs so far. Even means either not in a quoted field or already one quote encountered, the first of a pair. |
Definition at line 688 of file impex.cxx.
References lcl_isFieldEndQuote(), p, and SAL_WARN.
Referenced by ReadCsvLine().
|
inlinestatic |
Definition at line 599 of file impex.cxx.
References ScGlobal::UnicodeStrChr().
Referenced by lcl_isFieldEndQuote(), and ScImportExport::ScanNextFieldFromString().
|
static |
Determine if *p is a quote that ends a quoted field.
Precondition: we are parsing a quoted field already and *p is a quote.
Definition at line 625 of file impex.cxx.
References lcl_isFieldEnd(), p, and ScGlobal::UnicodeStrChr().
Referenced by lcl_isEscapedOrFieldEndQuote(), and lcl_ScanString().
|
static |
SetString with Extra-Flag ???
which language for date formats?
Definition at line 1072 of file impex.cxx.
References ScDocument::ApplyPattern(), ATTR_VALUE_FORMAT(), EditEngine::CreateTextObject(), SvNumberFormatter::ExpandTwoDigitYear(), ScGlobal::getCharClass(), ScDocumentImport::getDoc(), ScDocument::GetEditEngine(), ScDocument::GetFormatTable(), ScPatternAttr::GetItemSet(), CalendarWrapper::getMonths(), CalendarWrapper::getNumberOfMonthsInYear(), ScDocument::GetPool(), SvNumberFormatter::GetStandardFormat(), SvNumberFormatter::GetStandardIndex(), SvNumberFormatter::GetType(), i, CharClass::isLetterNumeric(), ScStringUtil::isMultiline(), SvNumberFormatter::IsNumberFormat(), LANGUAGE_ENGLISH_US, n, nIndex, nPos, SfxItemSet::Put(), rSet, SC_COL_DMY, SC_COL_ENGLISH, SC_COL_MDY, SC_COL_SKIP, SC_COL_STANDARD, SC_COL_TEXT, SC_COL_YMD, ScDocumentImport::setAutoInput(), ScDocumentImport::setEditCell(), ScDocument::SetNumberFormat(), ScDocumentImport::setNumericCell(), ScDocument::SetString(), ScDocumentImport::setStringCell(), ScDocument::SetTextCell(), ScEditEngineDefaulter::SetTextCurrentDefaults(), CalendarWrapper::setValue(), ScDocument::SetValue(), o3tl::toInt32(), u, ScDocument::ValidCol(), and ScDocument::ValidRow().
Referenced by ScImportExport::ExtText2Doc().
|
static |
Scan for a quoted string.
Precondition: initial current position *p is a cStr quote.
For DoubledQuoteMode::ESCAPE, if after the closing quote there is a field end (with or without trailing blanks and as determined by lcl_isFieldEndQuote()), then the content is appended to rField with quotes processed and removed. Else if no field end after the quoted string was detected, nothing is appended and processing continues and is repeated until the next quote. If no closing quote at a field end was found at all, nothing is appended and the initial position is returned and caller has to decide, usually just taking all as literal data.
For DoubledQuoteMode::KEEP_ALL, the string up to and including the closing quote is appended to rField and the next position returned, regardless whether there is a field separator following or not.
jump over opening quote
Definition at line 753 of file impex.cxx.
References eMode, lcl_appendLineData(), lcl_isFieldEndQuote(), and p.
Referenced by ScImportExport::ScanNextFieldFromString(), and ScImportExport::Text2Doc().
|
static |
Definition at line 888 of file impex.cxx.
References lcl_ScanSylkString(), lcl_UnescapeSylk(), and p.
Referenced by ScImportExport::Sylk2Doc().
|
static |
Definition at line 846 of file impex.cxx.
References lcl_UnescapeSylk(), and p.
Referenced by lcl_ScanSylkFormula(), and ScImportExport::Sylk2Doc().
|
static |
Definition at line 833 of file impex.cxx.
Referenced by lcl_ScanSylkFormula(), and lcl_ScanSylkString().
|
static |
Definition at line 2714 of file impex.cxx.
Referenced by ReadCsvLine().
|
static |
Definition at line 970 of file impex.cxx.
References rStrm, and ScImportExport::WriteUnicodeOrByteString().
Referenced by ScImportExport::Doc2Sylk(), and ScImportExport::Doc2Text().
|
static |
Definition at line 952 of file impex.cxx.
References rStrm, and ScImportExport::WriteUnicodeOrByteString().
Referenced by ScImportExport::Doc2Sylk(), and ScImportExport::Doc2Text().
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().
bEmbeddedLineBreak | If 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().
rFieldSeparators | A 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. |
cFieldQuote | The quote character used. |
rcDetectSep | If 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 |
nMaxSourceLines | Maximum 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().
|
static |
Definition at line 2673 of file impex.cxx.
References thisModule().
Referenced by ScFormatFilter::Get(), and thisModule().
|
constexpr |
Definition at line 82 of file impex.cxx.
Referenced by lcl_appendLineData().
|
constexpr |
Definition at line 83 of file impex.cxx.
Referenced by ReadCsvLine(), and ScImportExport::Text2Doc().