[Libreoffice-commits] .: 4 commits - sal/Library_sal.mk sal/Library_sal_textenc.mk sal/textenc
Stephan Bergmann
sbergmann at kemper.freedesktop.org
Thu Jan 5 14:25:30 PST 2012
sal/Library_sal.mk | 17
sal/Library_sal_textenc.mk | 8
sal/textenc/context.c | 50 -
sal/textenc/context.cxx | 52 +
sal/textenc/context.h | 55 -
sal/textenc/context.hxx | 49 +
sal/textenc/convertadobe.tab | 10
sal/textenc/convertbig5hkscs.c | 494 ------------
sal/textenc/convertbig5hkscs.cxx | 501 +++++++++++++
sal/textenc/convertbig5hkscs.h | 84 --
sal/textenc/convertbig5hkscs.hxx | 75 +
sal/textenc/convertbig5hkscs.tab | 14
sal/textenc/converter.c | 167 ----
sal/textenc/converter.cxx | 170 ++++
sal/textenc/converter.h | 69 -
sal/textenc/converter.hxx | 61 +
sal/textenc/converteuctw.c | 455 -----------
sal/textenc/converteuctw.cxx | 460 +++++++++++
sal/textenc/converteuctw.h | 81 --
sal/textenc/converteuctw.hxx | 74 +
sal/textenc/converteuctw.tab | 14
sal/textenc/convertgb18030.c | 471 ------------
sal/textenc/convertgb18030.cxx | 475 ++++++++++++
sal/textenc/convertgb18030.h | 95 --
sal/textenc/convertgb18030.hxx | 88 ++
sal/textenc/convertgb18030.tab | 13
sal/textenc/convertiscii.tab | 6
sal/textenc/convertiso2022cn.c | 865 ----------------------
sal/textenc/convertiso2022cn.cxx | 868 ++++++++++++++++++++++
sal/textenc/convertiso2022cn.h | 87 --
sal/textenc/convertiso2022cn.hxx | 80 ++
sal/textenc/convertiso2022cn.tab | 18
sal/textenc/convertiso2022jp.c | 572 --------------
sal/textenc/convertiso2022jp.cxx | 577 ++++++++++++++
sal/textenc/convertiso2022jp.h | 81 --
sal/textenc/convertiso2022jp.hxx | 74 +
sal/textenc/convertiso2022jp.tab | 18
sal/textenc/convertiso2022kr.c | 530 -------------
sal/textenc/convertiso2022kr.cxx | 534 +++++++++++++
sal/textenc/convertiso2022kr.h | 81 --
sal/textenc/convertiso2022kr.hxx | 74 +
sal/textenc/convertiso2022kr.tab | 18
sal/textenc/convertsinglebytetobmpunicode.cxx | 11
sal/textenc/convertsinglebytetobmpunicode.hxx | 10
sal/textenc/generate/gb180302000.tab | 8
sal/textenc/gettextencodingdata.h | 49 -
sal/textenc/gettextencodingdata.hxx | 43 +
sal/textenc/tables.cxx | 32
sal/textenc/tcvtbyte.c | 858 ----------------------
sal/textenc/tcvtbyte.cxx | 848 ++++++++++++++++++++++
sal/textenc/tcvtlat1.tab | 220 -----
sal/textenc/tcvtmb.c | 695 ------------------
sal/textenc/tcvtmb.cxx | 690 +++++++++++++++++
sal/textenc/tcvtuni1.tab | 49 -
sal/textenc/tcvtutf7.c | 591 ---------------
sal/textenc/tcvtutf7.cxx | 583 +++++++++++++++
sal/textenc/tcvtutf8.c | 422 ----------
sal/textenc/tcvtutf8.cxx | 422 ++++++++++
sal/textenc/tenchelp.c | 215 -----
sal/textenc/tenchelp.cxx | 216 +++++
sal/textenc/tenchelp.h | 305 -------
sal/textenc/tenchelp.hxx | 297 +++++++
sal/textenc/tencinfo.c | 1002 --------------------------
sal/textenc/tencinfo.cxx | 994 +++++++++++++++++++++++++
sal/textenc/textcvt.c | 267 ------
sal/textenc/textcvt.cxx | 266 ++++++
sal/textenc/textenc.cxx | 306 +++++++
sal/textenc/unichars.c | 139 ---
sal/textenc/unichars.cxx | 140 +++
sal/textenc/unichars.h | 65 -
sal/textenc/unichars.hxx | 58 +
71 files changed, 9119 insertions(+), 9267 deletions(-)
New commits:
commit b234008ba5096f251fffec4c467f2103f4ba3cc0
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Jan 5 23:18:19 2012 +0100
Changed C files to C++.
diff --git a/sal/Library_sal.mk b/sal/Library_sal.mk
index f039ca7..c844634 100644
--- a/sal/Library_sal.mk
+++ b/sal/Library_sal.mk
@@ -119,10 +119,6 @@ $(eval $(call gb_Library_add_exception_objects,sal,\
sal/rtl/source/ustrbuf \
sal/rtl/source/ustring \
sal/rtl/source/uuid \
- sal/textenc/textenc \
-))
-$(eval $(call gb_Library_add_cobjects,sal,\
- sal/osl/all/filepath \
sal/textenc/context \
sal/textenc/converter \
sal/textenc/tcvtbyte \
@@ -130,8 +126,12 @@ $(eval $(call gb_Library_add_cobjects,sal,\
sal/textenc/tenchelp \
sal/textenc/tencinfo \
sal/textenc/textcvt \
+ sal/textenc/textenc \
sal/textenc/unichars \
))
+$(eval $(call gb_Library_add_cobjects,sal,\
+ sal/osl/all/filepath \
+))
ifeq ($(GUI),UNX)
$(eval $(call gb_Library_add_exception_objects,sal,\
diff --git a/sal/Library_sal_textenc.mk b/sal/Library_sal_textenc.mk
index 1280e87..27ff5c0 100644
--- a/sal/Library_sal_textenc.mk
+++ b/sal/Library_sal_textenc.mk
@@ -39,11 +39,6 @@ $(eval $(call gb_Library_add_defs,sal_textenc,\
))
$(eval $(call gb_Library_add_exception_objects,sal_textenc,\
- sal/textenc/convertsinglebytetobmpunicode \
- sal/textenc/tables \
-))
-
-$(eval $(call gb_Library_add_cobjects,sal_textenc,\
sal/textenc/context \
sal/textenc/convertbig5hkscs \
sal/textenc/converter \
@@ -52,6 +47,8 @@ $(eval $(call gb_Library_add_cobjects,sal_textenc,\
sal/textenc/convertiso2022cn \
sal/textenc/convertiso2022jp \
sal/textenc/convertiso2022kr \
+ sal/textenc/convertsinglebytetobmpunicode \
+ sal/textenc/tables \
sal/textenc/tcvtbyte \
sal/textenc/tcvtmb \
sal/textenc/tcvtutf7 \
diff --git a/sal/textenc/context.c b/sal/textenc/context.c
deleted file mode 100644
index 26232cb..0000000
--- a/sal/textenc/context.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-#include "context.h"
-#include "rtl/alloc.h"
-
-void * ImplCreateUnicodeToTextContext(void)
-{
- void * pContext = rtl_allocateMemory(sizeof (ImplUnicodeToTextContext));
- ((ImplUnicodeToTextContext *) pContext)->m_nHighSurrogate = 0;
- return pContext;
-}
-
-void ImplResetUnicodeToTextContext(void * pContext)
-{
- if (pContext)
- ((ImplUnicodeToTextContext *) pContext)->m_nHighSurrogate = 0;
-}
-
-void ImplDestroyContext(void * pContext)
-{
- rtl_freeMemory(pContext);
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/textenc/context.cxx b/sal/textenc/context.cxx
new file mode 100644
index 0000000..4770727
--- /dev/null
+++ b/sal/textenc/context.cxx
@@ -0,0 +1,52 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "sal/config.h"
+
+#include "context.hxx"
+
+void * ImplCreateUnicodeToTextContext()
+{
+ ImplUnicodeToTextContext * pContext = new ImplUnicodeToTextContext;
+ pContext->m_nHighSurrogate = 0;
+ return pContext;
+}
+
+void ImplResetUnicodeToTextContext(void * pContext)
+{
+ if (pContext)
+ static_cast< ImplUnicodeToTextContext * >(pContext)->m_nHighSurrogate =
+ 0;
+}
+
+void ImplDestroyContext(void * pContext)
+{
+ delete static_cast< ImplUnicodeToTextContext * >(pContext);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/textenc/context.h b/sal/textenc/context.h
deleted file mode 100644
index 6b7740e..0000000
--- a/sal/textenc/context.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-#ifndef INCLUDED_RTL_TEXTENC_CONTEXT_H
-#define INCLUDED_RTL_TEXTENC_CONTEXT_H
-
-#include "sal/types.h"
-
-#if defined __cplusplus
-extern "C" {
-#endif /* __cpluscplus */
-
-typedef struct
-{
- sal_Unicode m_nHighSurrogate;
-} ImplUnicodeToTextContext;
-
-void * ImplCreateUnicodeToTextContext(void) SAL_THROW_EXTERN_C();
-
-void ImplResetUnicodeToTextContext(void * pContext) SAL_THROW_EXTERN_C();
-
-void ImplDestroyContext(void * pContext) SAL_THROW_EXTERN_C();
-
-#if defined __cplusplus
-}
-#endif /* __cpluscplus */
-
-#endif /* INCLUDED_RTL_TEXTENC_CONTEXT_H */
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/textenc/context.hxx b/sal/textenc/context.hxx
new file mode 100644
index 0000000..a83006e
--- /dev/null
+++ b/sal/textenc/context.hxx
@@ -0,0 +1,49 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_SAL_TEXTENC_CONTEXT_HXX
+#define INCLUDED_SAL_TEXTENC_CONTEXT_HXX
+
+#include "sal/config.h"
+
+#include "sal/types.h"
+
+struct ImplUnicodeToTextContext
+{
+ sal_Unicode m_nHighSurrogate;
+};
+
+void * ImplCreateUnicodeToTextContext();
+
+void ImplResetUnicodeToTextContext(void * pContext);
+
+void ImplDestroyContext(void * pContext);
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/textenc/convertadobe.tab b/sal/textenc/convertadobe.tab
index 4267aa1..98633bb 100644
--- a/sal/textenc/convertadobe.tab
+++ b/sal/textenc/convertadobe.tab
@@ -25,12 +25,14 @@
*
************************************************************************/
-#include "context.h"
-#include "convertsinglebytetobmpunicode.hxx"
-#include "tenchelp.h"
+#include "sal/config.h"
#include "rtl/tencinfo.h"
-#include <sal/macros.h>
+#include "sal/macros.h"
+
+#include "context.hxx"
+#include "convertsinglebytetobmpunicode.hxx"
+#include "tenchelp.hxx"
namespace {
diff --git a/sal/textenc/convertbig5hkscs.c b/sal/textenc/convertbig5hkscs.c
deleted file mode 100644
index 0839e56..0000000
--- a/sal/textenc/convertbig5hkscs.c
+++ /dev/null
@@ -1,494 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-#include "convertbig5hkscs.h"
-#include "context.h"
-#include "converter.h"
-#include "tenchelp.h"
-#include "unichars.h"
-#include "osl/diagnose.h"
-#include "rtl/alloc.h"
-#include "rtl/textcvt.h"
-#include "sal/types.h"
-
-typedef struct
-{
- sal_Int32 m_nRow; /* 0--255; 0 means none */
-} ImplBig5HkscsToUnicodeContext;
-
-void * ImplCreateBig5HkscsToUnicodeContext(void)
-{
- void * pContext
- = rtl_allocateMemory(sizeof (ImplBig5HkscsToUnicodeContext));
- ((ImplBig5HkscsToUnicodeContext *) pContext)->m_nRow = 0;
- return pContext;
-}
-
-void ImplResetBig5HkscsToUnicodeContext(void * pContext)
-{
- if (pContext)
- ((ImplBig5HkscsToUnicodeContext *) pContext)->m_nRow = 0;
-}
-
-sal_Size ImplConvertBig5HkscsToUnicode(ImplTextConverterData const * pData,
- void * pContext,
- sal_Char const * pSrcBuf,
- sal_Size nSrcBytes,
- sal_Unicode * pDestBuf,
- sal_Size nDestChars,
- sal_uInt32 nFlags,
- sal_uInt32 * pInfo,
- sal_Size * pSrcCvtBytes)
-{
- sal_uInt16 const * pBig5Hkscs2001Data
- = ((ImplBig5HkscsConverterData const *) pData)->
- m_pBig5Hkscs2001ToUnicodeData;
- sal_Int32 const * pBig5Hkscs2001RowOffsets
- = ((ImplBig5HkscsConverterData const *) pData)->
- m_pBig5Hkscs2001ToUnicodeRowOffsets;
- ImplDBCSToUniLeadTab const * pBig5Data
- = ((ImplBig5HkscsConverterData const *) pData)->
- m_pBig5ToUnicodeData;
- sal_Int32 nRow = 0;
- sal_uInt32 nInfo = 0;
- sal_Size nConverted = 0;
- sal_Unicode * pDestBufPtr = pDestBuf;
- sal_Unicode * pDestBufEnd = pDestBuf + nDestChars;
-
- if (pContext)
- nRow = ((ImplBig5HkscsToUnicodeContext *) pContext)->m_nRow;
-
- for (; nConverted < nSrcBytes; ++nConverted)
- {
- sal_Bool bUndefined = sal_True;
- sal_uInt32 nChar = *(sal_uChar const *) pSrcBuf++;
- if (nRow == 0)
- if (nChar < 0x80)
- if (pDestBufPtr != pDestBufEnd)
- *pDestBufPtr++ = (sal_Unicode) nChar;
- else
- goto no_output;
- else if (nChar >= 0x81 && nChar <= 0xFE)
- nRow = nChar;
- else
- {
- bUndefined = sal_False;
- goto bad_input;
- }
- else
- if ((nChar >= 0x40 && nChar <= 0x7E)
- || (nChar >= 0xA1 && nChar <= 0xFE))
- {
- sal_uInt32 nUnicode = 0xFFFF;
- sal_Int32 nOffset = pBig5Hkscs2001RowOffsets[nRow];
- sal_uInt32 nFirst=0;
- sal_uInt32 nLast=0;
- if (nOffset != -1)
- {
- sal_uInt32 nFirstLast = pBig5Hkscs2001Data[nOffset++];
- nFirst = nFirstLast & 0xFF;
- nLast = nFirstLast >> 8;
- if (nChar >= nFirst && nChar <= nLast)
- nUnicode
- = pBig5Hkscs2001Data[nOffset + (nChar - nFirst)];
- }
- if (nUnicode == 0xFFFF)
- {
- sal_uInt32 n = pBig5Data[nRow].mnTrailStart;
- if (nChar >= n && nChar <= pBig5Data[nRow].mnTrailEnd)
- {
- nUnicode = pBig5Data[nRow].mpToUniTrailTab[nChar - n];
- if (nUnicode == 0)
- nUnicode = 0xFFFF;
- OSL_VERIFY(!ImplIsHighSurrogate(nUnicode));
- }
- }
- if (nUnicode == 0xFFFF)
- {
- ImplDBCSEUDCData const * p
- = ((ImplBig5HkscsConverterData const *) pData)->
- m_pEudcData;
- sal_uInt32 nCount
- = ((ImplBig5HkscsConverterData const *) pData)->
- m_nEudcCount;
- sal_uInt32 i;
- for (i = 0; i < nCount; ++i)
- {
- if (nRow >= p->mnLeadStart && nRow <= p->mnLeadEnd)
- {
- if (nChar < p->mnTrail1Start)
- break;
- if (nChar <= p->mnTrail1End)
- {
- nUnicode
- = p->mnUniStart
- + (nRow - p->mnLeadStart)
- * p->mnTrailRangeCount
- + (nChar - p->mnTrail1Start);
- break;
- }
- if (p->mnTrailCount < 2
- || nChar < p->mnTrail2Start)
- break;
- if (nChar <= p->mnTrail2End)
- {
- nUnicode
- = p->mnUniStart
- + (nRow - p->mnLeadStart)
- * p->mnTrailRangeCount
- + (nChar - p->mnTrail2Start)
- + (p->mnTrail1End - p->mnTrail1Start
- + 1);
- break;
- }
- if (p->mnTrailCount < 3
- || nChar < p->mnTrail3Start)
- break;
- if (nChar <= p->mnTrail3End)
- {
- nUnicode
- = p->mnUniStart
- + (nRow - p->mnLeadStart)
- * p->mnTrailRangeCount
- + (nChar - p->mnTrail3Start)
- + (p->mnTrail1End - p->mnTrail1Start
- + 1)
- + (p->mnTrail2End - p->mnTrail2Start
- + 1);
- break;
- }
- break;
- }
- ++p;
- }
- OSL_VERIFY(!ImplIsHighSurrogate(nUnicode));
- }
- if (nUnicode == 0xFFFF)
- goto bad_input;
- if (ImplIsHighSurrogate(nUnicode))
- if (pDestBufEnd - pDestBufPtr >= 2)
- {
- nOffset += nLast - nFirst + 1;
- nFirst = pBig5Hkscs2001Data[nOffset++];
- *pDestBufPtr++ = (sal_Unicode) nUnicode;
- *pDestBufPtr++
- = (sal_Unicode) pBig5Hkscs2001Data[
- nOffset + (nChar - nFirst)];
- }
- else
- goto no_output;
- else
- if (pDestBufPtr != pDestBufEnd)
- *pDestBufPtr++ = (sal_Unicode) nUnicode;
- else
- goto no_output;
- nRow = 0;
- }
- else
- {
- bUndefined = sal_False;
- goto bad_input;
- }
- continue;
-
- bad_input:
- switch (ImplHandleBadInputTextToUnicodeConversion(
- bUndefined, sal_True, 0, nFlags, &pDestBufPtr, pDestBufEnd,
- &nInfo))
- {
- case IMPL_BAD_INPUT_STOP:
- nRow = 0;
- break;
-
- case IMPL_BAD_INPUT_CONTINUE:
- nRow = 0;
- continue;
-
- case IMPL_BAD_INPUT_NO_OUTPUT:
- goto no_output;
- }
- break;
-
- no_output:
- --pSrcBuf;
- nInfo |= RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
- break;
- }
-
- if (nRow != 0
- && (nInfo & (RTL_TEXTTOUNICODE_INFO_ERROR
- | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL))
- == 0)
- {
- if ((nFlags & RTL_TEXTTOUNICODE_FLAGS_FLUSH) == 0)
- nInfo |= RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL;
- else
- switch (ImplHandleBadInputTextToUnicodeConversion(
- sal_False, sal_True, 0, nFlags, &pDestBufPtr,
- pDestBufEnd, &nInfo))
- {
- case IMPL_BAD_INPUT_STOP:
- case IMPL_BAD_INPUT_CONTINUE:
- nRow = 0;
- break;
-
- case IMPL_BAD_INPUT_NO_OUTPUT:
- nInfo |= RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
- break;
- }
- }
-
- if (pContext)
- ((ImplBig5HkscsToUnicodeContext *) pContext)->m_nRow = nRow;
- if (pInfo)
- *pInfo = nInfo;
- if (pSrcCvtBytes)
- *pSrcCvtBytes = nConverted;
-
- return pDestBufPtr - pDestBuf;
-}
-
-sal_Size ImplConvertUnicodeToBig5Hkscs(ImplTextConverterData const * pData,
- void * pContext,
- sal_Unicode const * pSrcBuf,
- sal_Size nSrcChars,
- sal_Char * pDestBuf,
- sal_Size nDestBytes,
- sal_uInt32 nFlags,
- sal_uInt32 * pInfo,
- sal_Size * pSrcCvtChars)
-{
- sal_uInt16 const * pBig5Hkscs2001Data
- = ((ImplBig5HkscsConverterData const *) pData)->
- m_pUnicodeToBig5Hkscs2001Data;
- sal_Int32 const * pBig5Hkscs2001PageOffsets
- = ((ImplBig5HkscsConverterData const *) pData)->
- m_pUnicodeToBig5Hkscs2001PageOffsets;
- sal_Int32 const * pBig5Hkscs2001PlaneOffsets
- = ((ImplBig5HkscsConverterData const *) pData)->
- m_pUnicodeToBig5Hkscs2001PlaneOffsets;
- ImplUniToDBCSHighTab const * pBig5Data
- = ((ImplBig5HkscsConverterData const *) pData)->
- m_pUnicodeToBig5Data;
- sal_Unicode nHighSurrogate = 0;
- sal_uInt32 nInfo = 0;
- sal_Size nConverted = 0;
- sal_Char * pDestBufPtr = pDestBuf;
- sal_Char * pDestBufEnd = pDestBuf + nDestBytes;
-
- if (pContext)
- nHighSurrogate
- = ((ImplUnicodeToTextContext *) pContext)->m_nHighSurrogate;
-
- for (; nConverted < nSrcChars; ++nConverted)
- {
- sal_Bool bUndefined = sal_True;
- sal_uInt32 nChar = *pSrcBuf++;
- if (nHighSurrogate == 0)
- {
- if (ImplIsHighSurrogate(nChar))
- {
- nHighSurrogate = (sal_Unicode) nChar;
- continue;
- }
- }
- else if (ImplIsLowSurrogate(nChar))
- nChar = ImplCombineSurrogates(nHighSurrogate, nChar);
- else
- {
- bUndefined = sal_False;
- goto bad_input;
- }
-
- if (ImplIsLowSurrogate(nChar) || ImplIsNoncharacter(nChar))
- {
- bUndefined = sal_False;
- goto bad_input;
- }
-
- if (nChar < 0x80)
- if (pDestBufPtr != pDestBufEnd)
- *pDestBufPtr++ = (sal_Char) nChar;
- else
- goto no_output;
- else
- {
- sal_uInt32 nBytes = 0;
- sal_Int32 nOffset = pBig5Hkscs2001PlaneOffsets[nChar >> 16];
- if (nOffset != -1)
- {
- nOffset
- = pBig5Hkscs2001PageOffsets[nOffset + ((nChar & 0xFF00)
- >> 8)];
- if (nOffset != -1)
- {
- sal_uInt32 nFirstLast = pBig5Hkscs2001Data[nOffset++];
- sal_uInt32 nFirst = nFirstLast & 0xFF;
- sal_uInt32 nLast = nFirstLast >> 8;
- sal_uInt32 nIndex = nChar & 0xFF;
- if (nIndex >= nFirst && nIndex <= nLast)
- {
- nBytes
- = pBig5Hkscs2001Data[nOffset + (nIndex - nFirst)];
- }
- }
- }
- if (nBytes == 0)
- {
- sal_uInt32 nIndex1 = nChar >> 8;
- if (nIndex1 < 0x100)
- {
- sal_uInt32 nIndex2 = nChar & 0xFF;
- sal_uInt32 nFirst = pBig5Data[nIndex1].mnLowStart;
- if (nIndex2 >= nFirst
- && nIndex2 <= pBig5Data[nIndex1].mnLowEnd)
- nBytes = pBig5Data[nIndex1].
- mpToUniTrailTab[nIndex2 - nFirst];
- }
- }
- if (nBytes == 0)
- {
- ImplDBCSEUDCData const * p
- = ((ImplBig5HkscsConverterData const *) pData)->
- m_pEudcData;
- sal_uInt32 nCount
- = ((ImplBig5HkscsConverterData const *) pData)->
- m_nEudcCount;
- sal_uInt32 i;
- for (i = 0; i < nCount; ++i) {
- if (nChar >= p->mnUniStart && nChar <= p->mnUniEnd)
- {
- sal_uInt32 nIndex = nChar - p->mnUniStart;
- sal_uInt32 nLeadOff = nIndex / p->mnTrailRangeCount;
- sal_uInt32 nTrailOff = nIndex % p->mnTrailRangeCount;
- sal_uInt32 nSize;
- nBytes = (p->mnLeadStart + nLeadOff) << 8;
- nSize = p->mnTrail1End - p->mnTrail1Start + 1;
- if (nTrailOff < nSize)
- {
- nBytes |= p->mnTrail1Start + nTrailOff;
- break;
- }
- nTrailOff -= nSize;
- nSize = p->mnTrail2End - p->mnTrail2Start + 1;
- if (nTrailOff < nSize)
- {
- nBytes |= p->mnTrail2Start + nTrailOff;
- break;
- }
- nTrailOff -= nSize;
- nBytes |= p->mnTrail3Start + nTrailOff;
- break;
- }
- ++p;
- }
- }
- if (nBytes == 0)
- goto bad_input;
- if (pDestBufEnd - pDestBufPtr >= 2)
- {
- *pDestBufPtr++ = (sal_Char) (nBytes >> 8);
- *pDestBufPtr++ = (sal_Char) (nBytes & 0xFF);
- }
- else
- goto no_output;
- }
- nHighSurrogate = 0;
- continue;
-
- bad_input:
- switch (ImplHandleBadInputUnicodeToTextConversion(bUndefined,
- nChar,
- nFlags,
- &pDestBufPtr,
- pDestBufEnd,
- &nInfo,
- NULL,
- 0,
- NULL))
- {
- case IMPL_BAD_INPUT_STOP:
- nHighSurrogate = 0;
- break;
-
- case IMPL_BAD_INPUT_CONTINUE:
- nHighSurrogate = 0;
- continue;
-
- case IMPL_BAD_INPUT_NO_OUTPUT:
- goto no_output;
- }
- break;
-
- no_output:
- --pSrcBuf;
- nInfo |= RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
- break;
- }
-
- if (nHighSurrogate != 0
- && (nInfo & (RTL_UNICODETOTEXT_INFO_ERROR
- | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL))
- == 0)
- {
- if ((nFlags & RTL_UNICODETOTEXT_FLAGS_FLUSH) != 0)
- nInfo |= RTL_UNICODETOTEXT_INFO_SRCBUFFERTOSMALL;
- else
- switch (ImplHandleBadInputUnicodeToTextConversion(sal_False,
- 0,
- nFlags,
- &pDestBufPtr,
- pDestBufEnd,
- &nInfo,
- NULL,
- 0,
- NULL))
- {
- case IMPL_BAD_INPUT_STOP:
- case IMPL_BAD_INPUT_CONTINUE:
- nHighSurrogate = 0;
- break;
-
- case IMPL_BAD_INPUT_NO_OUTPUT:
- nInfo |= RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
- break;
- }
- }
-
- if (pContext)
- ((ImplUnicodeToTextContext *) pContext)->m_nHighSurrogate
- = nHighSurrogate;
- if (pInfo)
- *pInfo = nInfo;
- if (pSrcCvtChars)
- *pSrcCvtChars = nConverted;
-
- return pDestBufPtr - pDestBuf;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/textenc/convertbig5hkscs.cxx b/sal/textenc/convertbig5hkscs.cxx
new file mode 100644
index 0000000..113a90e
--- /dev/null
+++ b/sal/textenc/convertbig5hkscs.cxx
@@ -0,0 +1,501 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "sal/config.h"
+
+#include <cassert>
+
+#include "rtl/textcvt.h"
+#include "sal/types.h"
+
+#include "context.hxx"
+#include "convertbig5hkscs.hxx"
+#include "converter.hxx"
+#include "tenchelp.hxx"
+#include "unichars.hxx"
+
+namespace {
+
+struct ImplBig5HkscsToUnicodeContext
+{
+ sal_Int32 m_nRow; // 0--255; 0 means none
+};
+
+}
+
+void * ImplCreateBig5HkscsToUnicodeContext()
+{
+ ImplBig5HkscsToUnicodeContext * pContext =
+ new ImplBig5HkscsToUnicodeContext;
+ pContext->m_nRow = 0;
+ return pContext;
+}
+
+void ImplResetBig5HkscsToUnicodeContext(void * pContext)
+{
+ if (pContext)
+ static_cast< ImplBig5HkscsToUnicodeContext * >(pContext)->m_nRow = 0;
+}
+
+sal_Size ImplConvertBig5HkscsToUnicode(ImplTextConverterData const * pData,
+ void * pContext,
+ char const * pSrcBuf,
+ sal_Size nSrcBytes,
+ sal_Unicode * pDestBuf,
+ sal_Size nDestChars,
+ sal_uInt32 nFlags,
+ sal_uInt32 * pInfo,
+ sal_Size * pSrcCvtBytes)
+{
+ sal_uInt16 const * pBig5Hkscs2001Data
+ = static_cast< ImplBig5HkscsConverterData const * >(pData)->
+ m_pBig5Hkscs2001ToUnicodeData;
+ sal_Int32 const * pBig5Hkscs2001RowOffsets
+ = static_cast< ImplBig5HkscsConverterData const * >(pData)->
+ m_pBig5Hkscs2001ToUnicodeRowOffsets;
+ ImplDBCSToUniLeadTab const * pBig5Data
+ = static_cast< ImplBig5HkscsConverterData const * >(pData)->
+ m_pBig5ToUnicodeData;
+ sal_Int32 nRow = 0;
+ sal_uInt32 nInfo = 0;
+ sal_Size nConverted = 0;
+ sal_Unicode * pDestBufPtr = pDestBuf;
+ sal_Unicode * pDestBufEnd = pDestBuf + nDestChars;
+
+ if (pContext)
+ nRow = static_cast< ImplBig5HkscsToUnicodeContext * >(pContext)->m_nRow;
+
+ for (; nConverted < nSrcBytes; ++nConverted)
+ {
+ bool bUndefined = true;
+ sal_uInt32 nChar = *(sal_uChar const *) pSrcBuf++;
+ if (nRow == 0)
+ if (nChar < 0x80)
+ if (pDestBufPtr != pDestBufEnd)
+ *pDestBufPtr++ = (sal_Unicode) nChar;
+ else
+ goto no_output;
+ else if (nChar >= 0x81 && nChar <= 0xFE)
+ nRow = nChar;
+ else
+ {
+ bUndefined = false;
+ goto bad_input;
+ }
+ else
+ if ((nChar >= 0x40 && nChar <= 0x7E)
+ || (nChar >= 0xA1 && nChar <= 0xFE))
+ {
+ sal_uInt32 nUnicode = 0xFFFF;
+ sal_Int32 nOffset = pBig5Hkscs2001RowOffsets[nRow];
+ sal_uInt32 nFirst=0;
+ sal_uInt32 nLast=0;
+ if (nOffset != -1)
+ {
+ sal_uInt32 nFirstLast = pBig5Hkscs2001Data[nOffset++];
+ nFirst = nFirstLast & 0xFF;
+ nLast = nFirstLast >> 8;
+ if (nChar >= nFirst && nChar <= nLast)
+ nUnicode
+ = pBig5Hkscs2001Data[nOffset + (nChar - nFirst)];
+ }
+ if (nUnicode == 0xFFFF)
+ {
+ sal_uInt32 n = pBig5Data[nRow].mnTrailStart;
+ if (nChar >= n && nChar <= pBig5Data[nRow].mnTrailEnd)
+ {
+ nUnicode = pBig5Data[nRow].mpToUniTrailTab[nChar - n];
+ if (nUnicode == 0)
+ nUnicode = 0xFFFF;
+ assert(!ImplIsHighSurrogate(nUnicode));
+ }
+ }
+ if (nUnicode == 0xFFFF)
+ {
+ ImplDBCSEUDCData const * p
+ = static_cast< ImplBig5HkscsConverterData const * >(pData)->
+ m_pEudcData;
+ sal_uInt32 nCount
+ = static_cast< ImplBig5HkscsConverterData const * >(pData)->
+ m_nEudcCount;
+ sal_uInt32 i;
+ for (i = 0; i < nCount; ++i)
+ {
+ if (nRow >= p->mnLeadStart && nRow <= p->mnLeadEnd)
+ {
+ if (nChar < p->mnTrail1Start)
+ break;
+ if (nChar <= p->mnTrail1End)
+ {
+ nUnicode
+ = p->mnUniStart
+ + (nRow - p->mnLeadStart)
+ * p->mnTrailRangeCount
+ + (nChar - p->mnTrail1Start);
+ break;
+ }
+ if (p->mnTrailCount < 2
+ || nChar < p->mnTrail2Start)
+ break;
+ if (nChar <= p->mnTrail2End)
+ {
+ nUnicode
+ = p->mnUniStart
+ + (nRow - p->mnLeadStart)
+ * p->mnTrailRangeCount
+ + (nChar - p->mnTrail2Start)
+ + (p->mnTrail1End - p->mnTrail1Start
+ + 1);
+ break;
+ }
+ if (p->mnTrailCount < 3
+ || nChar < p->mnTrail3Start)
+ break;
+ if (nChar <= p->mnTrail3End)
+ {
+ nUnicode
+ = p->mnUniStart
+ + (nRow - p->mnLeadStart)
+ * p->mnTrailRangeCount
+ + (nChar - p->mnTrail3Start)
+ + (p->mnTrail1End - p->mnTrail1Start
+ + 1)
+ + (p->mnTrail2End - p->mnTrail2Start
+ + 1);
+ break;
+ }
+ break;
+ }
+ ++p;
+ }
+ assert(!ImplIsHighSurrogate(nUnicode));
+ }
+ if (nUnicode == 0xFFFF)
+ goto bad_input;
+ if (ImplIsHighSurrogate(nUnicode))
+ if (pDestBufEnd - pDestBufPtr >= 2)
+ {
+ nOffset += nLast - nFirst + 1;
+ nFirst = pBig5Hkscs2001Data[nOffset++];
+ *pDestBufPtr++ = (sal_Unicode) nUnicode;
+ *pDestBufPtr++
+ = (sal_Unicode) pBig5Hkscs2001Data[
+ nOffset + (nChar - nFirst)];
+ }
+ else
+ goto no_output;
+ else
+ if (pDestBufPtr != pDestBufEnd)
+ *pDestBufPtr++ = (sal_Unicode) nUnicode;
+ else
+ goto no_output;
+ nRow = 0;
+ }
+ else
+ {
+ bUndefined = false;
+ goto bad_input;
+ }
+ continue;
+
+ bad_input:
+ switch (ImplHandleBadInputTextToUnicodeConversion(
+ bUndefined, true, 0, nFlags, &pDestBufPtr, pDestBufEnd,
+ &nInfo))
+ {
+ case IMPL_BAD_INPUT_STOP:
+ nRow = 0;
+ break;
+
+ case IMPL_BAD_INPUT_CONTINUE:
+ nRow = 0;
+ continue;
+
+ case IMPL_BAD_INPUT_NO_OUTPUT:
+ goto no_output;
+ }
+ break;
+
+ no_output:
+ --pSrcBuf;
+ nInfo |= RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
+ break;
+ }
+
+ if (nRow != 0
+ && (nInfo & (RTL_TEXTTOUNICODE_INFO_ERROR
+ | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL))
+ == 0)
+ {
+ if ((nFlags & RTL_TEXTTOUNICODE_FLAGS_FLUSH) == 0)
+ nInfo |= RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL;
+ else
+ switch (ImplHandleBadInputTextToUnicodeConversion(
+ false, true, 0, nFlags, &pDestBufPtr, pDestBufEnd,
+ &nInfo))
+ {
+ case IMPL_BAD_INPUT_STOP:
+ case IMPL_BAD_INPUT_CONTINUE:
+ nRow = 0;
+ break;
+
+ case IMPL_BAD_INPUT_NO_OUTPUT:
+ nInfo |= RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
+ break;
+ }
+ }
+
+ if (pContext)
+ static_cast< ImplBig5HkscsToUnicodeContext * >(pContext)->m_nRow = nRow;
+ if (pInfo)
+ *pInfo = nInfo;
+ if (pSrcCvtBytes)
+ *pSrcCvtBytes = nConverted;
+
+ return pDestBufPtr - pDestBuf;
+}
+
+sal_Size ImplConvertUnicodeToBig5Hkscs(ImplTextConverterData const * pData,
+ void * pContext,
+ sal_Unicode const * pSrcBuf,
+ sal_Size nSrcChars,
+ char * pDestBuf,
+ sal_Size nDestBytes,
+ sal_uInt32 nFlags,
+ sal_uInt32 * pInfo,
+ sal_Size * pSrcCvtChars)
+{
+ sal_uInt16 const * pBig5Hkscs2001Data
+ = static_cast< ImplBig5HkscsConverterData const * >(pData)->
+ m_pUnicodeToBig5Hkscs2001Data;
+ sal_Int32 const * pBig5Hkscs2001PageOffsets
+ = static_cast< ImplBig5HkscsConverterData const * >(pData)->
+ m_pUnicodeToBig5Hkscs2001PageOffsets;
+ sal_Int32 const * pBig5Hkscs2001PlaneOffsets
+ = static_cast< ImplBig5HkscsConverterData const * >(pData)->
+ m_pUnicodeToBig5Hkscs2001PlaneOffsets;
+ ImplUniToDBCSHighTab const * pBig5Data
+ = static_cast< ImplBig5HkscsConverterData const * >(pData)->
+ m_pUnicodeToBig5Data;
+ sal_Unicode nHighSurrogate = 0;
+ sal_uInt32 nInfo = 0;
+ sal_Size nConverted = 0;
+ char * pDestBufPtr = pDestBuf;
+ char * pDestBufEnd = pDestBuf + nDestBytes;
+
+ if (pContext)
+ nHighSurrogate
+ = ((ImplUnicodeToTextContext *) pContext)->m_nHighSurrogate;
+
+ for (; nConverted < nSrcChars; ++nConverted)
+ {
+ bool bUndefined = true;
+ sal_uInt32 nChar = *pSrcBuf++;
+ if (nHighSurrogate == 0)
+ {
+ if (ImplIsHighSurrogate(nChar))
+ {
+ nHighSurrogate = (sal_Unicode) nChar;
+ continue;
+ }
+ }
+ else if (ImplIsLowSurrogate(nChar))
+ nChar = ImplCombineSurrogates(nHighSurrogate, nChar);
+ else
+ {
+ bUndefined = false;
+ goto bad_input;
+ }
+
+ if (ImplIsLowSurrogate(nChar) || ImplIsNoncharacter(nChar))
+ {
+ bUndefined = false;
+ goto bad_input;
+ }
+
+ if (nChar < 0x80)
+ if (pDestBufPtr != pDestBufEnd)
+ *pDestBufPtr++ = static_cast< char >(nChar);
+ else
+ goto no_output;
+ else
+ {
+ sal_uInt32 nBytes = 0;
+ sal_Int32 nOffset = pBig5Hkscs2001PlaneOffsets[nChar >> 16];
+ if (nOffset != -1)
+ {
+ nOffset
+ = pBig5Hkscs2001PageOffsets[nOffset + ((nChar & 0xFF00)
+ >> 8)];
+ if (nOffset != -1)
+ {
+ sal_uInt32 nFirstLast = pBig5Hkscs2001Data[nOffset++];
+ sal_uInt32 nFirst = nFirstLast & 0xFF;
+ sal_uInt32 nLast = nFirstLast >> 8;
+ sal_uInt32 nIndex = nChar & 0xFF;
+ if (nIndex >= nFirst && nIndex <= nLast)
+ {
+ nBytes
+ = pBig5Hkscs2001Data[nOffset + (nIndex - nFirst)];
+ }
+ }
+ }
+ if (nBytes == 0)
+ {
+ sal_uInt32 nIndex1 = nChar >> 8;
+ if (nIndex1 < 0x100)
+ {
+ sal_uInt32 nIndex2 = nChar & 0xFF;
+ sal_uInt32 nFirst = pBig5Data[nIndex1].mnLowStart;
+ if (nIndex2 >= nFirst
+ && nIndex2 <= pBig5Data[nIndex1].mnLowEnd)
+ nBytes = pBig5Data[nIndex1].
+ mpToUniTrailTab[nIndex2 - nFirst];
+ }
+ }
+ if (nBytes == 0)
+ {
+ ImplDBCSEUDCData const * p
+ = static_cast< ImplBig5HkscsConverterData const * >(pData)->
+ m_pEudcData;
+ sal_uInt32 nCount
+ = static_cast< ImplBig5HkscsConverterData const * >(pData)->
+ m_nEudcCount;
+ sal_uInt32 i;
+ for (i = 0; i < nCount; ++i) {
+ if (nChar >= p->mnUniStart && nChar <= p->mnUniEnd)
+ {
+ sal_uInt32 nIndex = nChar - p->mnUniStart;
+ sal_uInt32 nLeadOff = nIndex / p->mnTrailRangeCount;
+ sal_uInt32 nTrailOff = nIndex % p->mnTrailRangeCount;
+ sal_uInt32 nSize;
+ nBytes = (p->mnLeadStart + nLeadOff) << 8;
+ nSize = p->mnTrail1End - p->mnTrail1Start + 1;
+ if (nTrailOff < nSize)
+ {
+ nBytes |= p->mnTrail1Start + nTrailOff;
+ break;
+ }
+ nTrailOff -= nSize;
+ nSize = p->mnTrail2End - p->mnTrail2Start + 1;
+ if (nTrailOff < nSize)
+ {
+ nBytes |= p->mnTrail2Start + nTrailOff;
+ break;
+ }
+ nTrailOff -= nSize;
+ nBytes |= p->mnTrail3Start + nTrailOff;
+ break;
+ }
+ ++p;
+ }
+ }
+ if (nBytes == 0)
+ goto bad_input;
+ if (pDestBufEnd - pDestBufPtr >= 2)
+ {
+ *pDestBufPtr++ = static_cast< char >(nBytes >> 8);
+ *pDestBufPtr++ = static_cast< char >(nBytes & 0xFF);
+ }
+ else
+ goto no_output;
+ }
+ nHighSurrogate = 0;
+ continue;
+
+ bad_input:
+ switch (ImplHandleBadInputUnicodeToTextConversion(bUndefined,
+ nChar,
+ nFlags,
+ &pDestBufPtr,
+ pDestBufEnd,
+ &nInfo,
+ NULL,
+ 0,
+ NULL))
+ {
+ case IMPL_BAD_INPUT_STOP:
+ nHighSurrogate = 0;
+ break;
+
+ case IMPL_BAD_INPUT_CONTINUE:
+ nHighSurrogate = 0;
+ continue;
+
+ case IMPL_BAD_INPUT_NO_OUTPUT:
+ goto no_output;
+ }
+ break;
+
+ no_output:
+ --pSrcBuf;
+ nInfo |= RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
+ break;
+ }
+
+ if (nHighSurrogate != 0
+ && (nInfo & (RTL_UNICODETOTEXT_INFO_ERROR
+ | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL))
+ == 0)
+ {
+ if ((nFlags & RTL_UNICODETOTEXT_FLAGS_FLUSH) != 0)
+ nInfo |= RTL_UNICODETOTEXT_INFO_SRCBUFFERTOSMALL;
+ else
+ switch (ImplHandleBadInputUnicodeToTextConversion(false,
+ 0,
+ nFlags,
+ &pDestBufPtr,
+ pDestBufEnd,
+ &nInfo,
+ NULL,
+ 0,
+ NULL))
+ {
+ case IMPL_BAD_INPUT_STOP:
+ case IMPL_BAD_INPUT_CONTINUE:
+ nHighSurrogate = 0;
+ break;
+
+ case IMPL_BAD_INPUT_NO_OUTPUT:
+ nInfo |= RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
+ break;
+ }
+ }
+
+ if (pContext)
+ ((ImplUnicodeToTextContext *) pContext)->m_nHighSurrogate
+ = nHighSurrogate;
+ if (pInfo)
+ *pInfo = nInfo;
+ if (pSrcCvtChars)
+ *pSrcCvtChars = nConverted;
+
+ return pDestBufPtr - pDestBuf;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/textenc/convertbig5hkscs.h b/sal/textenc/convertbig5hkscs.h
deleted file mode 100644
index e7e6643..0000000
--- a/sal/textenc/convertbig5hkscs.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-#ifndef INCLUDED_RTL_TEXTENC_CONVERTBIG5HKSCS_H
-#define INCLUDED_RTL_TEXTENC_CONVERTBIG5HKSCS_H
-
-#include "tenchelp.h"
-#include "sal/types.h"
-
-#if defined __cplusplus
-extern "C" {
-#endif /* __cpluscplus */
-
-typedef struct
-{
- sal_uInt16 const * m_pBig5Hkscs2001ToUnicodeData;
- sal_Int32 const * m_pBig5Hkscs2001ToUnicodeRowOffsets;
- ImplDBCSToUniLeadTab const * m_pBig5ToUnicodeData;
- sal_uInt16 const * m_pUnicodeToBig5Hkscs2001Data;
- sal_Int32 const * m_pUnicodeToBig5Hkscs2001PageOffsets;
- sal_Int32 const * m_pUnicodeToBig5Hkscs2001PlaneOffsets;
- ImplUniToDBCSHighTab const * m_pUnicodeToBig5Data;
- ImplDBCSEUDCData const * m_pEudcData;
- int m_nEudcCount;
-} ImplBig5HkscsConverterData;
-
-void * ImplCreateBig5HkscsToUnicodeContext(void) SAL_THROW_EXTERN_C();
-
-void ImplResetBig5HkscsToUnicodeContext(void * pContext) SAL_THROW_EXTERN_C();
-
-sal_Size ImplConvertBig5HkscsToUnicode(ImplTextConverterData const * pData,
- void * pContext,
- sal_Char const * pSrcBuf,
- sal_Size nSrcBytes,
- sal_Unicode * pDestBuf,
- sal_Size nDestChars,
- sal_uInt32 nFlags,
- sal_uInt32 * pInfo,
- sal_Size * pSrcCvtBytes)
- SAL_THROW_EXTERN_C();
-
-sal_Size ImplConvertUnicodeToBig5Hkscs(ImplTextConverterData const * pData,
- void * pContext,
- sal_Unicode const * pSrcBuf,
- sal_Size nSrcChars,
- sal_Char * pDestBuf,
- sal_Size nDestBytes,
- sal_uInt32 nFlags,
- sal_uInt32 * pInfo,
- sal_Size * pSrcCvtChars)
- SAL_THROW_EXTERN_C();
-
-#if defined __cplusplus
-}
-#endif /* __cpluscplus */
-
-#endif /* INCLUDED_RTL_TEXTENC_CONVERTBIG5HKSCS_H */
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/textenc/convertbig5hkscs.hxx b/sal/textenc/convertbig5hkscs.hxx
new file mode 100644
index 0000000..92fc372
--- /dev/null
+++ b/sal/textenc/convertbig5hkscs.hxx
@@ -0,0 +1,75 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_SAL_TEXTENC_CONVERTBIG5HKSCS_HXX
+#define INCLUDED_SAL_TEXTENC_CONVERTBIG5HKSCS_HXX
+
+#include "sal/types.h"
+
+#include "tenchelp.hxx"
+
+struct ImplBig5HkscsConverterData
+{
+ sal_uInt16 const * m_pBig5Hkscs2001ToUnicodeData;
+ sal_Int32 const * m_pBig5Hkscs2001ToUnicodeRowOffsets;
+ ImplDBCSToUniLeadTab const * m_pBig5ToUnicodeData;
+ sal_uInt16 const * m_pUnicodeToBig5Hkscs2001Data;
+ sal_Int32 const * m_pUnicodeToBig5Hkscs2001PageOffsets;
+ sal_Int32 const * m_pUnicodeToBig5Hkscs2001PlaneOffsets;
+ ImplUniToDBCSHighTab const * m_pUnicodeToBig5Data;
+ ImplDBCSEUDCData const * m_pEudcData;
+ int m_nEudcCount;
+};
+
+void * ImplCreateBig5HkscsToUnicodeContext();
+
+void ImplResetBig5HkscsToUnicodeContext(void * pContext);
+
+sal_Size ImplConvertBig5HkscsToUnicode(ImplTextConverterData const * pData,
+ void * pContext,
+ char const * pSrcBuf,
+ sal_Size nSrcBytes,
+ sal_Unicode * pDestBuf,
+ sal_Size nDestChars,
+ sal_uInt32 nFlags,
+ sal_uInt32 * pInfo,
+ sal_Size * pSrcCvtBytes);
+
+sal_Size ImplConvertUnicodeToBig5Hkscs(ImplTextConverterData const * pData,
+ void * pContext,
+ sal_Unicode const * pSrcBuf,
+ sal_Size nSrcChars,
+ char * pDestBuf,
+ sal_Size nDestBytes,
+ sal_uInt32 nFlags,
+ sal_uInt32 * pInfo,
+ sal_Size * pSrcCvtChars);
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/textenc/convertbig5hkscs.tab b/sal/textenc/convertbig5hkscs.tab
index 9fe2a47..29720a8 100644
--- a/sal/textenc/convertbig5hkscs.tab
+++ b/sal/textenc/convertbig5hkscs.tab
@@ -25,19 +25,13 @@
*
************************************************************************/
-#ifndef INCLUDED_RTL_TEXTENC_CONTEXT_H
-#include "context.h"
-#endif
-#ifndef INCLUDED_RTL_TEXTENC_CONVERTBIG5HKSCS_H
-#include "convertbig5hkscs.h"
-#endif
+#include "sal/config.h"
-#ifndef _RTL_TENCINFO_H
#include "rtl/tencinfo.h"
-#endif
-#ifndef _RTL_TEXTENC_H
#include "rtl/textenc.h"
-#endif
+
+#include "context.hxx"
+#include "convertbig5hkscs.hxx"
#include "generate/big5hkscs2001.tab"
diff --git a/sal/textenc/converter.c b/sal/textenc/converter.c
deleted file mode 100644
index 07c1e04..0000000
--- a/sal/textenc/converter.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-#include "converter.h"
-#include "tenchelp.h"
-#include "unichars.h"
-#include "rtl/textcvt.h"
-#include "sal/types.h"
-
-ImplBadInputConversionAction ImplHandleBadInputTextToUnicodeConversion(
- sal_Bool bUndefined, sal_Bool bMultiByte, sal_Char cByte, sal_uInt32 nFlags,
- sal_Unicode ** pDestBufPtr, sal_Unicode * pDestBufEnd, sal_uInt32 * pInfo)
-{
- *pInfo |= bUndefined
- ? (bMultiByte
- ? RTL_TEXTTOUNICODE_INFO_MBUNDEFINED
- : RTL_TEXTTOUNICODE_INFO_UNDEFINED)
- : RTL_TEXTTOUNICODE_INFO_INVALID;
- switch (nFlags
- & (bUndefined
- ? (bMultiByte
- ? RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_MASK
- : RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MASK)
- : RTL_TEXTTOUNICODE_FLAGS_INVALID_MASK))
- {
- case RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR:
- case RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR:
- case RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR:
- *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR;
- return IMPL_BAD_INPUT_STOP;
-
- case RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_IGNORE:
- case RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_IGNORE:
- case RTL_TEXTTOUNICODE_FLAGS_INVALID_IGNORE:
- return IMPL_BAD_INPUT_CONTINUE;
-
- case RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MAPTOPRIVATE:
- if (*pDestBufPtr != pDestBufEnd)
- {
- *(*pDestBufPtr)++ = RTL_TEXTCVT_BYTE_PRIVATE_START
- | ((sal_uChar) cByte);
- return IMPL_BAD_INPUT_CONTINUE;
- }
- else
- return IMPL_BAD_INPUT_NO_OUTPUT;
-
- default: /* RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_DEFAULT,
- RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT,
- RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT */
- if (*pDestBufPtr != pDestBufEnd)
- {
- *(*pDestBufPtr)++ = RTL_TEXTENC_UNICODE_REPLACEMENT_CHARACTER;
- return IMPL_BAD_INPUT_CONTINUE;
- }
- else
- return IMPL_BAD_INPUT_NO_OUTPUT;
- }
-}
-
-ImplBadInputConversionAction
-ImplHandleBadInputUnicodeToTextConversion(sal_Bool bUndefined,
- sal_uInt32 nUtf32,
- sal_uInt32 nFlags,
- sal_Char ** pDestBufPtr,
- sal_Char * pDestBufEnd,
- sal_uInt32 * pInfo,
- sal_Char const * pPrefix,
- sal_Size nPrefixLen,
- sal_Bool * pPrefixWritten)
-{
- /* TODO! RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE
- RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACESTR */
-
- sal_Char cReplace;
-
- if (bUndefined)
- {
- if (ImplIsControlOrFormat(nUtf32))
- {
- if ((nFlags & RTL_UNICODETOTEXT_FLAGS_CONTROL_IGNORE) != 0)
- nFlags = RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE;
- }
- else if (ImplIsPrivateUse(nUtf32))
- {
- if ((nFlags & RTL_UNICODETOTEXT_FLAGS_PRIVATE_IGNORE) != 0)
- nFlags = RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE;
- else if ((nFlags & RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0) != 0)
- nFlags = RTL_UNICODETOTEXT_FLAGS_UNDEFINED_0;
- }
- else if (ImplIsZeroWidth(nUtf32))
- {
- if ((nFlags & RTL_UNICODETOTEXT_FLAGS_NONSPACING_IGNORE) != 0)
- nFlags = RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE;
- }
- }
- *pInfo |= bUndefined ? RTL_UNICODETOTEXT_INFO_UNDEFINED :
- RTL_UNICODETOTEXT_INFO_INVALID;
- switch (nFlags & (bUndefined ? RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK :
- RTL_UNICODETOTEXT_FLAGS_INVALID_MASK))
- {
- case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR:
- case RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR:
- *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR;
- return IMPL_BAD_INPUT_STOP;
-
- case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE:
- case RTL_UNICODETOTEXT_FLAGS_INVALID_IGNORE:
- if (pPrefixWritten)
- *pPrefixWritten = sal_False;
- return IMPL_BAD_INPUT_CONTINUE;
-
- case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_0:
- case RTL_UNICODETOTEXT_FLAGS_INVALID_0:
- cReplace = 0;
- break;
-
- case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_QUESTIONMARK:
- case RTL_UNICODETOTEXT_FLAGS_INVALID_QUESTIONMARK:
- default: /* RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT,
- RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT */
- cReplace = '?';
- break;
-
- case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_UNDERLINE:
- case RTL_UNICODETOTEXT_FLAGS_INVALID_UNDERLINE:
- cReplace = '_';
- break;
- }
- if ((sal_Size) (pDestBufEnd - *pDestBufPtr) > nPrefixLen)
- {
- while (nPrefixLen-- > 0)
- *(*pDestBufPtr)++ = *pPrefix++;
- *(*pDestBufPtr)++ = cReplace;
- if (pPrefixWritten)
- *pPrefixWritten = sal_True;
- return IMPL_BAD_INPUT_CONTINUE;
- }
- else
- return IMPL_BAD_INPUT_NO_OUTPUT;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/textenc/converter.cxx b/sal/textenc/converter.cxx
new file mode 100644
index 0000000..cde368c
--- /dev/null
+++ b/sal/textenc/converter.cxx
@@ -0,0 +1,170 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "sal/config.h"
+
+#include "rtl/textcvt.h"
+#include "sal/types.h"
+
+#include "converter.hxx"
+#include "tenchelp.hxx"
+#include "unichars.hxx"
+
+ImplBadInputConversionAction ImplHandleBadInputTextToUnicodeConversion(
+ bool bUndefined, bool bMultiByte, char cByte, sal_uInt32 nFlags,
+ sal_Unicode ** pDestBufPtr, sal_Unicode * pDestBufEnd, sal_uInt32 * pInfo)
+{
+ *pInfo |= bUndefined
+ ? (bMultiByte
+ ? RTL_TEXTTOUNICODE_INFO_MBUNDEFINED
+ : RTL_TEXTTOUNICODE_INFO_UNDEFINED)
+ : RTL_TEXTTOUNICODE_INFO_INVALID;
+ switch (nFlags
+ & (bUndefined
+ ? (bMultiByte
+ ? RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_MASK
+ : RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MASK)
+ : RTL_TEXTTOUNICODE_FLAGS_INVALID_MASK))
+ {
+ case RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR:
+ case RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR:
+ case RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR:
+ *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR;
+ return IMPL_BAD_INPUT_STOP;
+
+ case RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_IGNORE:
+ case RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_IGNORE:
+ case RTL_TEXTTOUNICODE_FLAGS_INVALID_IGNORE:
+ return IMPL_BAD_INPUT_CONTINUE;
+
+ case RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MAPTOPRIVATE:
+ if (*pDestBufPtr != pDestBufEnd)
+ {
+ *(*pDestBufPtr)++ = RTL_TEXTCVT_BYTE_PRIVATE_START
+ | ((sal_uChar) cByte);
+ return IMPL_BAD_INPUT_CONTINUE;
+ }
+ else
+ return IMPL_BAD_INPUT_NO_OUTPUT;
+
+ default: // RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_DEFAULT,
+ // RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT,
+ // RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT
+ if (*pDestBufPtr != pDestBufEnd)
+ {
+ *(*pDestBufPtr)++ = RTL_TEXTENC_UNICODE_REPLACEMENT_CHARACTER;
+ return IMPL_BAD_INPUT_CONTINUE;
+ }
+ else
+ return IMPL_BAD_INPUT_NO_OUTPUT;
+ }
+}
+
+ImplBadInputConversionAction
+ImplHandleBadInputUnicodeToTextConversion(bool bUndefined,
+ sal_uInt32 nUtf32,
+ sal_uInt32 nFlags,
+ char ** pDestBufPtr,
+ char * pDestBufEnd,
+ sal_uInt32 * pInfo,
+ char const * pPrefix,
+ sal_Size nPrefixLen,
+ bool * pPrefixWritten)
+{
+ // TODO! RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE
+ // RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACESTR
+
+ char cReplace;
+
+ if (bUndefined)
+ {
+ if (ImplIsControlOrFormat(nUtf32))
+ {
+ if ((nFlags & RTL_UNICODETOTEXT_FLAGS_CONTROL_IGNORE) != 0)
+ nFlags = RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE;
+ }
+ else if (ImplIsPrivateUse(nUtf32))
+ {
+ if ((nFlags & RTL_UNICODETOTEXT_FLAGS_PRIVATE_IGNORE) != 0)
+ nFlags = RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE;
+ else if ((nFlags & RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0) != 0)
+ nFlags = RTL_UNICODETOTEXT_FLAGS_UNDEFINED_0;
+ }
+ else if (ImplIsZeroWidth(nUtf32))
+ {
+ if ((nFlags & RTL_UNICODETOTEXT_FLAGS_NONSPACING_IGNORE) != 0)
+ nFlags = RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE;
+ }
+ }
+ *pInfo |= bUndefined ? RTL_UNICODETOTEXT_INFO_UNDEFINED :
+ RTL_UNICODETOTEXT_INFO_INVALID;
+ switch (nFlags & (bUndefined ? RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK :
+ RTL_UNICODETOTEXT_FLAGS_INVALID_MASK))
+ {
+ case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR:
+ case RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR:
+ *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR;
+ return IMPL_BAD_INPUT_STOP;
+
+ case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE:
+ case RTL_UNICODETOTEXT_FLAGS_INVALID_IGNORE:
+ if (pPrefixWritten)
+ *pPrefixWritten = false;
+ return IMPL_BAD_INPUT_CONTINUE;
+
+ case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_0:
+ case RTL_UNICODETOTEXT_FLAGS_INVALID_0:
+ cReplace = 0;
+ break;
+
+ case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_QUESTIONMARK:
+ case RTL_UNICODETOTEXT_FLAGS_INVALID_QUESTIONMARK:
+ default: // RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT,
+ // RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT
+ cReplace = '?';
+ break;
+
+ case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_UNDERLINE:
+ case RTL_UNICODETOTEXT_FLAGS_INVALID_UNDERLINE:
+ cReplace = '_';
+ break;
+ }
+ if ((sal_Size) (pDestBufEnd - *pDestBufPtr) > nPrefixLen)
+ {
+ while (nPrefixLen-- > 0)
+ *(*pDestBufPtr)++ = *pPrefix++;
+ *(*pDestBufPtr)++ = cReplace;
+ if (pPrefixWritten)
+ *pPrefixWritten = true;
+ return IMPL_BAD_INPUT_CONTINUE;
+ }
+ else
+ return IMPL_BAD_INPUT_NO_OUTPUT;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/textenc/converter.h b/sal/textenc/converter.h
deleted file mode 100644
index c746527..0000000
--- a/sal/textenc/converter.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-#ifndef INCLUDED_RTL_TEXTENC_CONVERTER_H
-#define INCLUDED_RTL_TEXTENC_CONVERTER_H
-
-#include "sal/types.h"
-
-#if defined __cplusplus
-extern "C" {
-#endif /* __cpluscplus */
-
-typedef enum
-{
- IMPL_BAD_INPUT_STOP,
- IMPL_BAD_INPUT_CONTINUE,
- IMPL_BAD_INPUT_NO_OUTPUT
-} ImplBadInputConversionAction;
-
-ImplBadInputConversionAction
-ImplHandleBadInputTextToUnicodeConversion(
- sal_Bool bUndefined, sal_Bool bMultiByte, sal_Char cByte, sal_uInt32 nFlags,
- sal_Unicode ** pDestBufPtr, sal_Unicode * pDestBufEnd, sal_uInt32 * pInfo)
- SAL_THROW_EXTERN_C();
-
-ImplBadInputConversionAction
-ImplHandleBadInputUnicodeToTextConversion(sal_Bool bUndefined,
- sal_uInt32 nUtf32,
- sal_uInt32 nFlags,
- sal_Char ** pDestBufPtr,
- sal_Char * pDestBufEnd,
- sal_uInt32 * pInfo,
- sal_Char const * pPrefix,
- sal_Size nPrefixLen,
- sal_Bool * pPrefixWritten)
- SAL_THROW_EXTERN_C();
-
-#if defined __cplusplus
-}
-#endif /* __cpluscplus */
-
-#endif /* INCLUDED_RTL_TEXTENC_CONVERTER_H */
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/textenc/converter.hxx b/sal/textenc/converter.hxx
new file mode 100644
index 0000000..50338c2
--- /dev/null
+++ b/sal/textenc/converter.hxx
@@ -0,0 +1,61 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_SAL_TEXTENC_CONVERTER_HXX
+#define INCLUDED_SAL_TEXTENC_CONVERTER_HXX
+
+#include "sal/config.h"
+
+#include "sal/types.h"
+
+enum ImplBadInputConversionAction
+{
+ IMPL_BAD_INPUT_STOP,
+ IMPL_BAD_INPUT_CONTINUE,
+ IMPL_BAD_INPUT_NO_OUTPUT
+};
+
+ImplBadInputConversionAction
+ImplHandleBadInputTextToUnicodeConversion(
+ bool bUndefined, bool bMultiByte, char cByte, sal_uInt32 nFlags,
+ sal_Unicode ** pDestBufPtr, sal_Unicode * pDestBufEnd, sal_uInt32 * pInfo);
+
+ImplBadInputConversionAction
+ImplHandleBadInputUnicodeToTextConversion(bool bUndefined,
+ sal_uInt32 nUtf32,
+ sal_uInt32 nFlags,
+ char ** pDestBufPtr,
+ char * pDestBufEnd,
+ sal_uInt32 * pInfo,
+ char const * pPrefix,
+ sal_Size nPrefixLen,
+ bool * pPrefixWritten);
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/textenc/converteuctw.c b/sal/textenc/converteuctw.c
deleted file mode 100644
index 062862a..0000000
--- a/sal/textenc/converteuctw.c
+++ /dev/null
@@ -1,455 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-#include "converteuctw.h"
-#include "context.h"
-#include "converter.h"
-#include "tenchelp.h"
-#include "unichars.h"
-#include "rtl/alloc.h"
-#include "rtl/textcvt.h"
-#include "sal/types.h"
-
-typedef enum
-{
- IMPL_EUC_TW_TO_UNICODE_STATE_0,
- IMPL_EUC_TW_TO_UNICODE_STATE_1,
- IMPL_EUC_TW_TO_UNICODE_STATE_2_1,
- IMPL_EUC_TW_TO_UNICODE_STATE_2_2,
- IMPL_EUC_TW_TO_UNICODE_STATE_2_3
-} ImplEucTwToUnicodeState;
-
-typedef struct
-{
- ImplEucTwToUnicodeState m_eState;
- sal_Int32 m_nPlane; /* 0--15 */
- sal_Int32 m_nRow; /* 0--93 */
-} ImplEucTwToUnicodeContext;
-
-void * ImplCreateEucTwToUnicodeContext(void)
-{
- void * pContext = rtl_allocateMemory(sizeof (ImplEucTwToUnicodeContext));
- ((ImplEucTwToUnicodeContext *) pContext)->m_eState
- = IMPL_EUC_TW_TO_UNICODE_STATE_0;
- return pContext;
-}
-
-void ImplResetEucTwToUnicodeContext(void * pContext)
-{
- if (pContext)
- ((ImplEucTwToUnicodeContext *) pContext)->m_eState
- = IMPL_EUC_TW_TO_UNICODE_STATE_0;
-}
-
-sal_Size ImplConvertEucTwToUnicode(ImplTextConverterData const * pData,
- void * pContext,
- sal_Char const * pSrcBuf,
- sal_Size nSrcBytes,
- sal_Unicode * pDestBuf,
- sal_Size nDestChars,
- sal_uInt32 nFlags,
- sal_uInt32 * pInfo,
- sal_Size * pSrcCvtBytes)
-{
- sal_uInt16 const * pCns116431992Data
- = ((ImplEucTwConverterData const *) pData)->
- m_pCns116431992ToUnicodeData;
- sal_Int32 const * pCns116431992RowOffsets
- = ((ImplEucTwConverterData const *) pData)->
- m_pCns116431992ToUnicodeRowOffsets;
- sal_Int32 const * pCns116431992PlaneOffsets
- = ((ImplEucTwConverterData const *) pData)->
- m_pCns116431992ToUnicodePlaneOffsets;
- ImplEucTwToUnicodeState eState = IMPL_EUC_TW_TO_UNICODE_STATE_0;
- sal_Int32 nPlane = 0;
- sal_Int32 nRow = 0;
- sal_uInt32 nInfo = 0;
- sal_Size nConverted = 0;
- sal_Unicode * pDestBufPtr = pDestBuf;
- sal_Unicode * pDestBufEnd = pDestBuf + nDestChars;
-
- if (pContext)
- {
- eState = ((ImplEucTwToUnicodeContext *) pContext)->m_eState;
- nPlane = ((ImplEucTwToUnicodeContext *) pContext)->m_nPlane;
- nRow = ((ImplEucTwToUnicodeContext *) pContext)->m_nRow;
- }
-
- for (; nConverted < nSrcBytes; ++nConverted)
- {
- sal_Bool bUndefined = sal_True;
- sal_uInt32 nChar = *(sal_uChar const *) pSrcBuf++;
- switch (eState)
- {
- case IMPL_EUC_TW_TO_UNICODE_STATE_0:
- if (nChar < 0x80)
- if (pDestBufPtr != pDestBufEnd)
- *pDestBufPtr++ = (sal_Unicode) nChar;
- else
- goto no_output;
- else if (nChar >= 0xA1 && nChar <= 0xFE)
- {
- nRow = nChar - 0xA1;
- eState = IMPL_EUC_TW_TO_UNICODE_STATE_1;
- }
- else if (nChar == 0x8E)
- eState = IMPL_EUC_TW_TO_UNICODE_STATE_2_1;
- else
- {
- bUndefined = sal_False;
- goto bad_input;
- }
- break;
-
- case IMPL_EUC_TW_TO_UNICODE_STATE_1:
- if (nChar >= 0xA1 && nChar <= 0xFE)
- {
- nPlane = 0;
- goto transform;
- }
- else
- {
- bUndefined = sal_False;
- goto bad_input;
- }
- break;
-
- case IMPL_EUC_TW_TO_UNICODE_STATE_2_1:
- if (nChar >= 0xA1 && nChar <= 0xB0)
- {
- nPlane = nChar - 0xA1;
- ++eState;
- }
- else
- {
- bUndefined = sal_False;
- goto bad_input;
- }
- break;
-
- case IMPL_EUC_TW_TO_UNICODE_STATE_2_2:
- if (nChar >= 0xA1 && nChar <= 0xFE)
- {
- nRow = nChar - 0xA1;
- ++eState;
- }
- else
- {
- bUndefined = sal_False;
- goto bad_input;
- }
- break;
-
- case IMPL_EUC_TW_TO_UNICODE_STATE_2_3:
- if (nChar >= 0xA1 && nChar <= 0xFE)
- goto transform;
- else
- {
- bUndefined = sal_False;
- goto bad_input;
- }
- break;
- }
- continue;
-
- transform:
- {
- sal_Int32 nPlaneOffset = pCns116431992PlaneOffsets[nPlane];
- if (nPlaneOffset == -1)
- goto bad_input;
- else
- {
- sal_Int32 nOffset
- = pCns116431992RowOffsets[nPlaneOffset + nRow];
- if (nOffset == -1)
- goto bad_input;
- else
- {
- sal_uInt32 nFirstLast = pCns116431992Data[nOffset++];
- sal_uInt32 nFirst = nFirstLast & 0xFF;
- sal_uInt32 nLast = nFirstLast >> 8;
- nChar -= 0xA0;
- if (nChar >= nFirst && nChar <= nLast)
- {
- sal_uInt32 nUnicode
- = pCns116431992Data[nOffset + (nChar - nFirst)];
- if (nUnicode == 0xFFFF)
- goto bad_input;
- else if (ImplIsHighSurrogate(nUnicode))
- if (pDestBufEnd - pDestBufPtr >= 2)
- {
- nOffset += nLast - nFirst + 1;
- nFirst = pCns116431992Data[nOffset++];
- *pDestBufPtr++ = (sal_Unicode) nUnicode;
- *pDestBufPtr++
- = (sal_Unicode)
- pCns116431992Data[
- nOffset + (nChar - nFirst)];
- }
- else
- goto no_output;
- else
- if (pDestBufPtr != pDestBufEnd)
- *pDestBufPtr++ = (sal_Unicode) nUnicode;
- else
- goto no_output;
- }
- else
- goto bad_input;
- eState = IMPL_EUC_TW_TO_UNICODE_STATE_0;
- }
- }
- continue;
- }
-
- bad_input:
- switch (ImplHandleBadInputTextToUnicodeConversion(
- bUndefined, sal_True, 0, nFlags, &pDestBufPtr, pDestBufEnd,
- &nInfo))
- {
- case IMPL_BAD_INPUT_STOP:
- eState = IMPL_EUC_TW_TO_UNICODE_STATE_0;
- break;
-
- case IMPL_BAD_INPUT_CONTINUE:
- eState = IMPL_EUC_TW_TO_UNICODE_STATE_0;
- continue;
-
- case IMPL_BAD_INPUT_NO_OUTPUT:
- goto no_output;
- }
- break;
-
- no_output:
- --pSrcBuf;
- nInfo |= RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
- break;
- }
-
- if (eState != IMPL_EUC_TW_TO_UNICODE_STATE_0
- && (nInfo & (RTL_TEXTTOUNICODE_INFO_ERROR
- | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL))
- == 0)
- {
- if ((nFlags & RTL_TEXTTOUNICODE_FLAGS_FLUSH) == 0)
- nInfo |= RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL;
- else
- switch (ImplHandleBadInputTextToUnicodeConversion(
- sal_False, sal_True, 0, nFlags, &pDestBufPtr,
- pDestBufEnd, &nInfo))
- {
- case IMPL_BAD_INPUT_STOP:
- case IMPL_BAD_INPUT_CONTINUE:
- eState = IMPL_EUC_TW_TO_UNICODE_STATE_0;
- break;
-
- case IMPL_BAD_INPUT_NO_OUTPUT:
- nInfo |= RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
- break;
- }
- }
-
- if (pContext)
- {
- ((ImplEucTwToUnicodeContext *) pContext)->m_eState = eState;
- ((ImplEucTwToUnicodeContext *) pContext)->m_nPlane = nPlane;
- ((ImplEucTwToUnicodeContext *) pContext)->m_nRow = nRow;
- }
- if (pInfo)
- *pInfo = nInfo;
- if (pSrcCvtBytes)
- *pSrcCvtBytes = nConverted;
-
- return pDestBufPtr - pDestBuf;
-}
-
-sal_Size ImplConvertUnicodeToEucTw(ImplTextConverterData const * pData,
- void * pContext,
- sal_Unicode const * pSrcBuf,
- sal_Size nSrcChars,
- sal_Char * pDestBuf,
- sal_Size nDestBytes,
- sal_uInt32 nFlags,
- sal_uInt32 * pInfo,
- sal_Size * pSrcCvtChars)
-{
- sal_uInt8 const * pCns116431992Data
- = ((ImplEucTwConverterData const *) pData)->
- m_pUnicodeToCns116431992Data;
- sal_Int32 const * pCns116431992PageOffsets
- = ((ImplEucTwConverterData const *) pData)->
- m_pUnicodeToCns116431992PageOffsets;
- sal_Int32 const * pCns116431992PlaneOffsets
- = ((ImplEucTwConverterData const *) pData)->
- m_pUnicodeToCns116431992PlaneOffsets;
- sal_Unicode nHighSurrogate = 0;
- sal_uInt32 nInfo = 0;
- sal_Size nConverted = 0;
- sal_Char * pDestBufPtr = pDestBuf;
- sal_Char * pDestBufEnd = pDestBuf + nDestBytes;
-
- if (pContext)
- nHighSurrogate
- = ((ImplUnicodeToTextContext *) pContext)->m_nHighSurrogate;
-
- for (; nConverted < nSrcChars; ++nConverted)
- {
- sal_Bool bUndefined = sal_True;
- sal_uInt32 nChar = *pSrcBuf++;
- if (nHighSurrogate == 0)
- {
- if (ImplIsHighSurrogate(nChar))
- {
- nHighSurrogate = (sal_Unicode) nChar;
- continue;
- }
- }
- else if (ImplIsLowSurrogate(nChar))
- nChar = ImplCombineSurrogates(nHighSurrogate, nChar);
- else
- {
- bUndefined = sal_False;
- goto bad_input;
- }
-
- if (ImplIsLowSurrogate(nChar) || ImplIsNoncharacter(nChar))
- {
- bUndefined = sal_False;
- goto bad_input;
- }
-
- if (nChar < 0x80)
- if (pDestBufPtr != pDestBufEnd)
- *pDestBufPtr++ = (sal_Char) nChar;
- else
- goto no_output;
- else
- {
- sal_Int32 nOffset = pCns116431992PlaneOffsets[nChar >> 16];
- sal_uInt32 nFirst;
- sal_uInt32 nLast;
- sal_uInt32 nPlane;
- if (nOffset == -1)
- goto bad_input;
- nOffset
- = pCns116431992PageOffsets[nOffset + ((nChar & 0xFF00) >> 8)];
- if (nOffset == -1)
- goto bad_input;
- nFirst = pCns116431992Data[nOffset++];
- nLast = pCns116431992Data[nOffset++];
- nChar &= 0xFF;
- if (nChar < nFirst || nChar > nLast)
- goto bad_input;
- nOffset += 3 * (nChar - nFirst);
- nPlane = pCns116431992Data[nOffset++];
- if (nPlane == 0)
- goto bad_input;
- if (pDestBufEnd - pDestBufPtr < (nPlane == 1 ? 2 : 4))
- goto no_output;
- if (nPlane != 1)
- {
- *pDestBufPtr++ = (sal_Char) (unsigned char) 0x8E;
- *pDestBufPtr++ = (sal_Char) (0xA0 + nPlane);
- }
- *pDestBufPtr++ = (sal_Char) (0xA0 + pCns116431992Data[nOffset++]);
- *pDestBufPtr++ = (sal_Char) (0xA0 + pCns116431992Data[nOffset]);
- }
- nHighSurrogate = 0;
- continue;
-
- bad_input:
- switch (ImplHandleBadInputUnicodeToTextConversion(bUndefined,
- nChar,
- nFlags,
- &pDestBufPtr,
- pDestBufEnd,
- &nInfo,
- NULL,
- 0,
- NULL))
- {
- case IMPL_BAD_INPUT_STOP:
- nHighSurrogate = 0;
- break;
-
- case IMPL_BAD_INPUT_CONTINUE:
- nHighSurrogate = 0;
- continue;
-
- case IMPL_BAD_INPUT_NO_OUTPUT:
- goto no_output;
- }
- break;
-
- no_output:
- --pSrcBuf;
- nInfo |= RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
- break;
- }
-
- if (nHighSurrogate != 0
- && (nInfo & (RTL_UNICODETOTEXT_INFO_ERROR
- | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL))
- == 0)
- {
- if ((nFlags & RTL_UNICODETOTEXT_FLAGS_FLUSH) != 0)
- nInfo |= RTL_UNICODETOTEXT_INFO_SRCBUFFERTOSMALL;
- else
- switch (ImplHandleBadInputUnicodeToTextConversion(sal_False,
- 0,
- nFlags,
- &pDestBufPtr,
- pDestBufEnd,
- &nInfo,
- NULL,
- 0,
- NULL))
- {
- case IMPL_BAD_INPUT_STOP:
- case IMPL_BAD_INPUT_CONTINUE:
- nHighSurrogate = 0;
- break;
-
- case IMPL_BAD_INPUT_NO_OUTPUT:
- nInfo |= RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
- break;
- }
- }
-
- if (pContext)
- ((ImplUnicodeToTextContext *) pContext)->m_nHighSurrogate
- = nHighSurrogate;
- if (pInfo)
- *pInfo = nInfo;
- if (pSrcCvtChars)
- *pSrcCvtChars = nConverted;
-
- return pDestBufPtr - pDestBuf;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/textenc/converteuctw.cxx b/sal/textenc/converteuctw.cxx
new file mode 100644
index 0000000..0b6b41b
--- /dev/null
+++ b/sal/textenc/converteuctw.cxx
@@ -0,0 +1,460 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "sal/config.h"
+
+#include "rtl/textcvt.h"
+#include "sal/types.h"
+
+#include "context.hxx"
+#include "converter.hxx"
+#include "converteuctw.hxx"
+#include "tenchelp.hxx"
+#include "unichars.hxx"
+
+namespace {
+
+enum ImplEucTwToUnicodeState
+{
+ IMPL_EUC_TW_TO_UNICODE_STATE_0,
+ IMPL_EUC_TW_TO_UNICODE_STATE_1,
+ IMPL_EUC_TW_TO_UNICODE_STATE_2_1,
+ IMPL_EUC_TW_TO_UNICODE_STATE_2_2,
+ IMPL_EUC_TW_TO_UNICODE_STATE_2_3
+};
+
+struct ImplEucTwToUnicodeContext
+{
+ ImplEucTwToUnicodeState m_eState;
+ sal_Int32 m_nPlane; // 0--15
+ sal_Int32 m_nRow; // 0--93
+};
+
+}
+
+void * ImplCreateEucTwToUnicodeContext()
+{
+ ImplEucTwToUnicodeContext * pContext = new ImplEucTwToUnicodeContext;
+ pContext->m_eState = IMPL_EUC_TW_TO_UNICODE_STATE_0;
+ return pContext;
+}
+
+void ImplResetEucTwToUnicodeContext(void * pContext)
+{
+ if (pContext)
+ static_cast< ImplEucTwToUnicodeContext * >(pContext)->m_eState
+ = IMPL_EUC_TW_TO_UNICODE_STATE_0;
+}
+
+sal_Size ImplConvertEucTwToUnicode(ImplTextConverterData const * pData,
+ void * pContext,
+ char const * pSrcBuf,
+ sal_Size nSrcBytes,
+ sal_Unicode * pDestBuf,
+ sal_Size nDestChars,
+ sal_uInt32 nFlags,
+ sal_uInt32 * pInfo,
+ sal_Size * pSrcCvtBytes)
+{
+ sal_uInt16 const * pCns116431992Data
+ = static_cast< ImplEucTwConverterData const * >(pData)->
+ m_pCns116431992ToUnicodeData;
+ sal_Int32 const * pCns116431992RowOffsets
+ = static_cast< ImplEucTwConverterData const * >(pData)->
+ m_pCns116431992ToUnicodeRowOffsets;
+ sal_Int32 const * pCns116431992PlaneOffsets
+ = static_cast< ImplEucTwConverterData const * >(pData)->
+ m_pCns116431992ToUnicodePlaneOffsets;
+ ImplEucTwToUnicodeState eState = IMPL_EUC_TW_TO_UNICODE_STATE_0;
+ sal_Int32 nPlane = 0;
+ sal_Int32 nRow = 0;
+ sal_uInt32 nInfo = 0;
+ sal_Size nConverted = 0;
+ sal_Unicode * pDestBufPtr = pDestBuf;
+ sal_Unicode * pDestBufEnd = pDestBuf + nDestChars;
+
+ if (pContext)
+ {
+ eState = static_cast< ImplEucTwToUnicodeContext * >(pContext)->m_eState;
+ nPlane = static_cast< ImplEucTwToUnicodeContext * >(pContext)->m_nPlane;
+ nRow = static_cast< ImplEucTwToUnicodeContext * >(pContext)->m_nRow;
+ }
+
+ for (; nConverted < nSrcBytes; ++nConverted)
+ {
+ bool bUndefined = true;
+ sal_uInt32 nChar = *(sal_uChar const *) pSrcBuf++;
+ switch (eState)
+ {
+ case IMPL_EUC_TW_TO_UNICODE_STATE_0:
+ if (nChar < 0x80)
+ if (pDestBufPtr != pDestBufEnd)
+ *pDestBufPtr++ = (sal_Unicode) nChar;
+ else
+ goto no_output;
+ else if (nChar >= 0xA1 && nChar <= 0xFE)
+ {
+ nRow = nChar - 0xA1;
+ eState = IMPL_EUC_TW_TO_UNICODE_STATE_1;
+ }
+ else if (nChar == 0x8E)
+ eState = IMPL_EUC_TW_TO_UNICODE_STATE_2_1;
+ else
+ {
+ bUndefined = false;
+ goto bad_input;
+ }
+ break;
+
+ case IMPL_EUC_TW_TO_UNICODE_STATE_1:
+ if (nChar >= 0xA1 && nChar <= 0xFE)
+ {
+ nPlane = 0;
+ goto transform;
+ }
+ else
+ {
+ bUndefined = false;
+ goto bad_input;
+ }
+ break;
+
+ case IMPL_EUC_TW_TO_UNICODE_STATE_2_1:
+ if (nChar >= 0xA1 && nChar <= 0xB0)
+ {
+ nPlane = nChar - 0xA1;
+ eState = IMPL_EUC_TW_TO_UNICODE_STATE_2_2;
+ }
+ else
+ {
+ bUndefined = false;
+ goto bad_input;
+ }
+ break;
+
+ case IMPL_EUC_TW_TO_UNICODE_STATE_2_2:
+ if (nChar >= 0xA1 && nChar <= 0xFE)
+ {
+ nRow = nChar - 0xA1;
+ eState = IMPL_EUC_TW_TO_UNICODE_STATE_2_3;
+ }
+ else
+ {
+ bUndefined = false;
+ goto bad_input;
+ }
+ break;
+
+ case IMPL_EUC_TW_TO_UNICODE_STATE_2_3:
+ if (nChar >= 0xA1 && nChar <= 0xFE)
+ goto transform;
+ else
+ {
+ bUndefined = false;
+ goto bad_input;
+ }
+ break;
+ }
+ continue;
+
+ transform:
+ {
+ sal_Int32 nPlaneOffset = pCns116431992PlaneOffsets[nPlane];
+ if (nPlaneOffset == -1)
+ goto bad_input;
+ else
+ {
+ sal_Int32 nOffset
+ = pCns116431992RowOffsets[nPlaneOffset + nRow];
+ if (nOffset == -1)
+ goto bad_input;
+ else
+ {
+ sal_uInt32 nFirstLast = pCns116431992Data[nOffset++];
+ sal_uInt32 nFirst = nFirstLast & 0xFF;
+ sal_uInt32 nLast = nFirstLast >> 8;
+ nChar -= 0xA0;
+ if (nChar >= nFirst && nChar <= nLast)
+ {
+ sal_uInt32 nUnicode
+ = pCns116431992Data[nOffset + (nChar - nFirst)];
+ if (nUnicode == 0xFFFF)
+ goto bad_input;
+ else if (ImplIsHighSurrogate(nUnicode))
+ if (pDestBufEnd - pDestBufPtr >= 2)
+ {
+ nOffset += nLast - nFirst + 1;
+ nFirst = pCns116431992Data[nOffset++];
+ *pDestBufPtr++ = (sal_Unicode) nUnicode;
+ *pDestBufPtr++
+ = (sal_Unicode)
... etc. - the rest is truncated
More information about the Libreoffice-commits
mailing list