LibreOffice Module tools (master) 1
Namespaces | Macros | Functions
stream.cxx File Reference
#include <sal/config.h>
#include <cassert>
#include <cstddef>
#include <memory>
#include <string.h>
#include <o3tl/safeint.hxx>
#include <osl/endian.h>
#include <osl/diagnose.h>
#include <rtl/strbuf.hxx>
#include <rtl/string.hxx>
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
#include <tools/long.hxx>
#include <comphelper/fileformat.h>
#include <comphelper/fileurl.hxx>
#include <tools/debug.hxx>
#include <tools/stream.hxx>
#include <osl/thread.h>
#include <algorithm>
Include dependency graph for stream.cxx:

Go to the source code of this file.

Namespaces

namespace  tools
 Note: this class is a true marvel of engineering: because the author could not decide whether it's better to have a closed or half-open interval, they just implemented both in the same class!
 

Macros

#define CRYPT_BUFSIZE   1024
 

Functions

static void swapNibbles (unsigned char &c)
 
template<typename T , std::enable_if_t< std::is_integral_v< T > &&sizeof(T)==2, int > = 0>
static void SwapNumber (T &r)
 
static void SwapFloat (float &r)
 
static void SwapDouble (double &r)
 
OString read_zeroTerminated_uInt8s_ToOString (SvStream &rStream)
 Attempt to write a pascal-style length (of type prefix) prefixed sequence of 16bit units from an OUString, returned value is number of bytes written (including byte-count of prefix) More...
 
OUString read_zeroTerminated_uInt8s_ToOUString (SvStream &rStream, rtl_TextEncoding eEnc)
 Attempt to read 8bit units assuming source encoding eEnc to an OUString until a zero terminator is encountered. More...
 
std::size_t write_uInt16s_FromOUString (SvStream &rStrm, std::u16string_view rStr, std::size_t nUnits)
 Attempt to write a prefixed sequence of nUnits 16bit units from an OUString, returned value is number of bytes written. More...
 
bool checkSeek (SvStream &rSt, sal_uInt64 nOffset)
 
bool tools::isEmptyFileUrl (const OUString &rUrl)
 Is rUrl a file:// URL with no contents? More...
 
static unsigned char implGetCryptMask (const char *pStr, sal_Int32 nLen, tools::Long nVersion)
 
SvStreamendl (SvStream &rStr)
 
SvStreamendlu (SvStream &rStrm)
 same as endl() but Unicode More...
 
SvStreamendlub (SvStream &rStrm)
 call endlu() if m_eStreamCharSet==RTL_TEXTECODING_UNICODE otherwise endl() More...
 
OString read_uInt8s_ToOString (SvStream &rStrm, std::size_t nLen)
 Attempt to read nUnits 8bit units to an OString, returned OString's length is number of units successfully read. More...
 
OUString read_uInt16s_ToOUString (SvStream &rStrm, std::size_t nLen)
 Attempt to read nUnits 16bit units to an OUString, returned OUString's length is number of units successfully read. More...
 
OString convertLineEnd (const OString &rIn, LineEnd eLineEnd)
 
OUString convertLineEnd (const OUString &rIn, LineEnd eLineEnd)
 
std::size_t write_uInt32_lenPrefixed_uInt16s_FromOUString (SvStream &rStrm, std::u16string_view rStr)
 Attempt to write a pascal-style length (of type prefix) prefixed sequence of 16bit units from an OUString, returned value is number of bytes written (including byte-count of prefix) More...
 
std::size_t write_uInt16_lenPrefixed_uInt16s_FromOUString (SvStream &rStrm, std::u16string_view rStr)
 
std::size_t write_uInt16_lenPrefixed_uInt8s_FromOString (SvStream &rStrm, std::string_view rStr)
 Attempt to write a pascal-style length (of type prefix) prefixed sequence of units from a string-type, returned value is number of bytes written (including byte-count of prefix) More...
 

Macro Definition Documentation

◆ CRYPT_BUFSIZE

#define CRYPT_BUFSIZE   1024

Definition at line 1356 of file stream.cxx.

Function Documentation

◆ checkSeek()

bool checkSeek ( SvStream rSt,
sal_uInt64  nOffset 
)

Definition at line 1292 of file stream.cxx.

References SvStream::Seek(), and SvStream::TellEnd().

◆ convertLineEnd() [1/2]

OString convertLineEnd ( const OString &  rIn,
LineEnd  eLineEnd 
)

Definition at line 1940 of file stream.cxx.

◆ convertLineEnd() [2/2]

OUString convertLineEnd ( const OUString &  rIn,
LineEnd  eLineEnd 
)

Definition at line 1945 of file stream.cxx.

◆ endl()

SvStream & endl ( SvStream rStr)

Definition at line 1465 of file stream.cxx.

References SvStream::GetLineDelimiter(), LINEEND_CR, LINEEND_LF, and SvStream::WriteChar().

Referenced by endlub(), and SvStream::WriteLine().

◆ endlu()

SvStream & endlu ( SvStream rStrm)

same as endl() but Unicode

Definition at line 1477 of file stream.cxx.

References SvStream::GetLineDelimiter(), LINEEND_CR, LINEEND_LF, rStrm, and SvStream::WriteUnicode().

Referenced by endlub().

◆ endlub()

SvStream & endlub ( SvStream rStrm)

call endlu() if m_eStreamCharSet==RTL_TEXTECODING_UNICODE otherwise endl()

Definition at line 1493 of file stream.cxx.

References endl(), endlu(), SvStream::GetStreamCharSet(), and rStrm.

◆ implGetCryptMask()

static unsigned char implGetCryptMask ( const char *  pStr,
sal_Int32  nLen,
tools::Long  nVersion 
)
static

Definition at line 1404 of file stream.cxx.

References i, nVersion, and SOFFICE_FILEFORMAT_31.

Referenced by SvStream::SetCryptMaskKey().

◆ read_uInt16s_ToOUString()

OUString read_uInt16s_ToOUString ( SvStream rStrm,
std::size_t  nLen 
)

Attempt to read nUnits 16bit units to an OUString, returned OUString's length is number of units successfully read.

Definition at line 1823 of file stream.cxx.

References i, SvStream::IsEndianSwap(), SvStream::ReadBytes(), SvStream::remainingSize(), rStrm, SAL_MAX_INT32, and SAL_WARN_IF.

Referenced by read_uInt16_lenPrefixed_uInt16s_ToOUString(), and read_uInt32_lenPrefixed_uInt16s_ToOUString().

◆ read_uInt8s_ToOString()

OString read_uInt8s_ToOString ( SvStream rStrm,
std::size_t  nLen 
)

Attempt to read nUnits 8bit units to an OString, returned OString's length is number of units successfully read.

Definition at line 1791 of file stream.cxx.

References SvStream::ReadBytes(), SvStream::remainingSize(), rStrm, SAL_MAX_INT32, and SAL_WARN_IF.

Referenced by read_uInt16_lenPrefixed_uInt8s_ToOString(), read_uInt32_lenPrefixed_uInt8s_ToOString(), read_uInt8_lenPrefixed_uInt8s_ToOString(), and read_uInt8s_ToOUString().

◆ read_zeroTerminated_uInt8s_ToOString()

OString read_zeroTerminated_uInt8s_ToOString ( SvStream rStrm)

Attempt to write a pascal-style length (of type prefix) prefixed sequence of 16bit units from an OUString, returned value is number of bytes written (including byte-count of prefix)

Attempt to read 8bit units to an OString until a zero terminator is encountered, returned OString's length is number of units definitely successfully read, check SvStream::good() to see if null terminator was successfully read

Definition at line 608 of file stream.cxx.

References SvStream::GetError(), SvStream::ReadBytes(), SvStream::Seek(), and SvStream::Tell().

Referenced by read_zeroTerminated_uInt8s_ToOUString().

◆ read_zeroTerminated_uInt8s_ToOUString()

OUString read_zeroTerminated_uInt8s_ToOUString ( SvStream rStrm,
rtl_TextEncoding  eEnc 
)

Attempt to read 8bit units assuming source encoding eEnc to an OUString until a zero terminator is encountered.

Check SvStream::good() to see if null terminator was successfully read

Definition at line 644 of file stream.cxx.

References read_zeroTerminated_uInt8s_ToOString().

◆ SwapDouble()

static void SwapDouble ( double &  r)
static

Definition at line 93 of file stream.cxx.

References d, and SAL_WARN.

Referenced by SvStream::ReadDouble(), and SvStream::WriteDouble().

◆ SwapFloat()

static void SwapFloat ( float &  r)
static

Definition at line 80 of file stream.cxx.

Referenced by SvStream::ReadFloat(), and SvStream::WriteFloat().

◆ swapNibbles()

static void swapNibbles ( unsigned char &  c)
static

Definition at line 42 of file stream.cxx.

Referenced by SvStream::CryptAndWriteBuffer(), and SvStream::EncryptBuffer().

◆ SwapNumber()

template<typename T , std::enable_if_t< std::is_integral_v< T > &&sizeof(T)==2, int > = 0>
static void SwapNumber ( T &  r)
static

◆ write_uInt16_lenPrefixed_uInt16s_FromOUString()

std::size_t write_uInt16_lenPrefixed_uInt16s_FromOUString ( SvStream rStrm,
std::u16string_view  rStr 
)

◆ write_uInt16_lenPrefixed_uInt8s_FromOString()

std::size_t write_uInt16_lenPrefixed_uInt8s_FromOString ( SvStream rStrm,
std::string_view  rStr 
)

Attempt to write a pascal-style length (of type prefix) prefixed sequence of units from a string-type, returned value is number of bytes written (including byte-count of prefix)

Definition at line 1984 of file stream.cxx.

References SvStream::good(), rStrm, SAL_WARN_IF, write_uInt8s_FromOString(), and SvStream::WriteUInt16().

Referenced by write_uInt16_lenPrefixed_uInt8s_FromOUString().

◆ write_uInt16s_FromOUString()

std::size_t write_uInt16s_FromOUString ( SvStream rStrm,
std::u16string_view  rStr,
std::size_t  nUnits 
)

Attempt to write a prefixed sequence of nUnits 16bit units from an OUString, returned value is number of bytes written.

Definition at line 652 of file stream.cxx.

References aBuf, DBG_ASSERT, SvStream::IsEndianSwap(), p, rStrm, SwapNumber(), and SvStream::WriteBytes().

Referenced by write_uInt16_lenPrefixed_uInt16s_FromOUString(), write_uInt16s_FromOUString(), write_uInt32_lenPrefixed_uInt16s_FromOUString(), and SvStream::WriteUnicodeOrByteText().

◆ write_uInt32_lenPrefixed_uInt16s_FromOUString()

std::size_t write_uInt32_lenPrefixed_uInt16s_FromOUString ( SvStream rStrm,
std::u16string_view  rStr 
)

Attempt to write a pascal-style length (of type prefix) prefixed sequence of 16bit units from an OUString, returned value is number of bytes written (including byte-count of prefix)

Definition at line 1950 of file stream.cxx.

References SvStream::good(), rStrm, SAL_WARN_IF, write_uInt16s_FromOUString(), and SvStream::WriteUInt32().

Referenced by SvStream::WriteUniOrByteString().