diff options
author | tobias <tobias.schulz@hotmail.com> | 2021-06-06 15:47:06 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-06-06 18:52:52 +0200 |
commit | 162f5a20095c6937030d23ee03fb8f72c51eefa1 (patch) | |
tree | 5113e0775353231d359b8cd0d19a6425c7da3d9c /sw/source/filter/basflt | |
parent | 89aaa17a0a4413f07da2bc5084b0164f15dc01ac (diff) |
tdf#142669 Consider BOM on text encoding detection
Return a flag if the auto detected text has a BOM.
Save the flag in SwAsciiOptions so that BOM gets set correctly when
file is written.
Change-Id: I358c3ba243bc326a552c2dc24773c94f8319c700
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116759
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw/source/filter/basflt')
-rw-r--r-- | sw/source/filter/basflt/iodetect.cxx | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/sw/source/filter/basflt/iodetect.cxx b/sw/source/filter/basflt/iodetect.cxx index 2f49b2b199d1..e4d214391f2c 100644 --- a/sw/source/filter/basflt/iodetect.cxx +++ b/sw/source/filter/basflt/iodetect.cxx @@ -239,11 +239,12 @@ std::shared_ptr<const SfxFilter> SwIoSystem::GetFileFilter(const OUString& rFile } bool SwIoSystem::IsDetectableText(const char* pBuf, sal_uLong &rLen, - rtl_TextEncoding *pCharSet, bool *pSwap, LineEnd *pLineEnd) + rtl_TextEncoding *pCharSet, bool *pSwap, LineEnd *pLineEnd, bool *pBom) { bool bSwap = false; rtl_TextEncoding eCharSet = RTL_TEXTENCODING_DONTKNOW; bool bLE = true; + bool bBom = false; /*See if it's a known unicode type*/ if (rLen >= 2) { @@ -253,17 +254,20 @@ bool SwIoSystem::IsDetectableText(const char* pBuf, sal_uLong &rLen, { eCharSet = RTL_TEXTENCODING_UTF8; nHead = 3; + bBom = true; } else if (sal_uInt8(pBuf[0]) == 0xFE && sal_uInt8(pBuf[1]) == 0xFF) { eCharSet = RTL_TEXTENCODING_UCS2; bLE = false; nHead = 2; + bBom = true; } else if (sal_uInt8(pBuf[1]) == 0xFE && sal_uInt8(pBuf[0]) == 0xFF) { eCharSet = RTL_TEXTENCODING_UCS2; nHead = 2; + bBom = true; } pBuf+=nHead; rLen-=nHead; @@ -400,6 +404,8 @@ bool SwIoSystem::IsDetectableText(const char* pBuf, sal_uLong &rLen, *pSwap = bSwap; if (pLineEnd) *pLineEnd = eLineEnd; + if (pBom) + *pBom = bBom; return !bIsBareUnicode; } |