You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by da...@apache.org on 2025/05/04 17:32:25 UTC
(openoffice) 07/14: Use only the C API for ICU in forms, so it can use newer ICU versions.
This is an automated email from the ASF dual-hosted git repository.
damjan pushed a commit to branch icu-c-api
in repository https://gitbox.apache.org/repos/asf/openoffice.git
commit dd866940559eeefe0eedaee0ab9840604e5eacc3
Author: Damjan Jovanovic <da...@apache.org>
AuthorDate: Thu May 1 10:59:17 2025 +0200
Use only the C API for ICU in forms, so it can use newer ICU versions.
Patch by: me
---
main/forms/source/xforms/datatypes.cxx | 31 +++++++++++++---------
main/forms/source/xforms/datatypes.hxx | 4 +--
.../source/xforms/warnings_guard_unicode_regex.h | 5 +++-
3 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/main/forms/source/xforms/datatypes.cxx b/main/forms/source/xforms/datatypes.cxx
index 29d828c6d0..6b30ad2a9e 100644
--- a/main/forms/source/xforms/datatypes.cxx
+++ b/main/forms/source/xforms/datatypes.cxx
@@ -84,6 +84,8 @@ namespace xforms
//--------------------------------------------------------------------
OXSDDataType::~OXSDDataType()
{
+ if ( m_pPatternMatcher )
+ uregex_close( m_pPatternMatcher );
}
//--------------------------------------------------------------------
@@ -207,24 +209,26 @@ namespace xforms
//--------------------------------------------------------------------
namespace
{
- static void lcl_initializePatternMatcher( ::std::auto_ptr< RegexMatcher >& _rpMatcher, const ::rtl::OUString& _rPattern )
+ static void lcl_initializePatternMatcher( URegularExpression **_ppMatcher, const ::rtl::OUString& _rPattern )
{
UErrorCode nMatchStatus = U_ZERO_ERROR;
- UnicodeString aIcuPattern( reinterpret_cast<const UChar *>(_rPattern.getStr()), _rPattern.getLength() ); // UChar != sal_Unicode in MinGW
- _rpMatcher.reset( new RegexMatcher( aIcuPattern, 0, nMatchStatus ) );
+ if ( *_ppMatcher ) {
+ uregex_close( *_ppMatcher );
+ *_ppMatcher = NULL;
+ }
+ *_ppMatcher = uregex_open( reinterpret_cast<const UChar *>(_rPattern.getStr()), _rPattern.getLength(), 0, NULL, &nMatchStatus );
OSL_ENSURE( U_SUCCESS( nMatchStatus ), "lcl_initializePatternMatcher: invalid pattern property!" );
// if asserts, then something changed our pattern without going to convertFastPropertyValue/checkPropertySanity
}
- static bool lcl_matchString( RegexMatcher& _rMatcher, const ::rtl::OUString& _rText )
+ static bool lcl_matchString( URegularExpression *_pMatcher, const ::rtl::OUString& _rText )
{
UErrorCode nMatchStatus = U_ZERO_ERROR;
- UnicodeString aInput( reinterpret_cast<const UChar *>(_rText.getStr()), _rText.getLength() ); // UChar != sal_Unicode in MinGW
- _rMatcher.reset( aInput );
- if ( _rMatcher.matches( nMatchStatus ) )
+ uregex_setText( _pMatcher, reinterpret_cast<const UChar *>(_rText.getStr()), _rText.getLength(), &nMatchStatus ); // UChar != sal_Unicode in MinGW
+ if ( uregex_matches( _pMatcher, 0, &nMatchStatus ) )
{
- int32_t nStart = _rMatcher.start( nMatchStatus );
- int32_t nEnd = _rMatcher.end ( nMatchStatus );
+ int32_t nStart = uregex_start( _pMatcher, 0, &nMatchStatus );
+ int32_t nEnd = uregex_end ( _pMatcher, 0, &nMatchStatus );
if ( ( nStart == 0 ) && ( nEnd == _rText.getLength() ) )
return true;
}
@@ -245,12 +249,12 @@ namespace xforms
// ensure our pattern matcher is up to date
if ( m_bPatternMatcherDirty )
{
- lcl_initializePatternMatcher( m_pPatternMatcher, m_sPattern );
+ lcl_initializePatternMatcher( &m_pPatternMatcher, m_sPattern );
m_bPatternMatcherDirty = false;
}
// let it match the string
- if ( !lcl_matchString( *m_pPatternMatcher.get(), _rValue ) )
+ if ( !lcl_matchString( m_pPatternMatcher, _rValue ) )
return RID_STR_XFORMS_PATTERN_DOESNT_MATCH;
}
@@ -293,14 +297,15 @@ namespace xforms
::rtl::OUString sPattern;
OSL_VERIFY( _rNewValue >>= sPattern );
- UnicodeString aIcuPattern( reinterpret_cast<const UChar *>(sPattern.getStr()), sPattern.getLength() ); // UChar != sal_Unicode in MinGW
UErrorCode nMatchStatus = U_ZERO_ERROR;
- RegexMatcher aMatcher( aIcuPattern, 0, nMatchStatus );
+ // UChar != sal_Unicode in MinGW
+ URegularExpression *aMatcher = uregex_open( reinterpret_cast<const UChar *>(sPattern.getStr()), sPattern.getLength(), 0, NULL, &nMatchStatus );
if ( U_FAILURE( nMatchStatus ) )
{
_rErrorMessage = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "This is no valid pattern." ) );
return false;
}
+ uregex_close( aMatcher );
}
return true;
}
diff --git a/main/forms/source/xforms/datatypes.hxx b/main/forms/source/xforms/datatypes.hxx
index db68d6a7de..58c6d0c180 100644
--- a/main/forms/source/xforms/datatypes.hxx
+++ b/main/forms/source/xforms/datatypes.hxx
@@ -67,8 +67,8 @@ namespace xforms
sal_uInt16 m_nWST;
// </properties>
- ::std::auto_ptr< U_NAMESPACE_QUALIFIER RegexMatcher >
- m_pPatternMatcher;
+ URegularExpression
+ *m_pPatternMatcher;
bool m_bPatternMatcherDirty;
protected:
diff --git a/main/forms/source/xforms/warnings_guard_unicode_regex.h b/main/forms/source/xforms/warnings_guard_unicode_regex.h
index 10566e84ea..326fa498b4 100644
--- a/main/forms/source/xforms/warnings_guard_unicode_regex.h
+++ b/main/forms/source/xforms/warnings_guard_unicode_regex.h
@@ -24,6 +24,9 @@
#ifndef INCLUDED_WARNINGS_GUARD_UNICODE_REGEX_H
#define INCLUDED_WARNINGS_GUARD_UNICODE_REGEX_H
+#define U_SHOW_CPLUSPLUS_API 0
+#define U_SHOW_CPLUSPLUS_HEADER_API 0
+
// Because the GCC system_header mechanism doesn't work in .c/.cxx compilation
// units and more important affects the rest of the current include file, the
// warnings guard is separated into this header file on its own.
@@ -36,7 +39,7 @@
#elif defined __GNUC__
#pragma GCC system_header
#endif
-#include <unicode/regex.h>
+#include <unicode/uregex.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif