summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorAndreas Heinisch <andreas.heinisch@yahoo.de>2020-05-20 15:49:08 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-05-21 08:50:23 +0200
commit3ff159d35770ac3454ee909b348cb4f4ca8b0b9b (patch)
treeedd985ad08757e7b3ebb5f0a147d7ed5b07c4e84 /basic
parent89340fcb6509afd1bffea7b6060d5ff5a444b3f1 (diff)
tdf#132389 - case-insensitive operation for non-ASCII characters
Support case-insensitive operation for non-ASCII characters in the Replace function in Basic. Change-Id: I48069ad7be1ae0f012c52f595cc44e6b50580b94 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94580 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'basic')
-rw-r--r--basic/qa/basic_coverage/test_string_replace.vb37
-rw-r--r--basic/qa/vba_tests/replace.vb7
-rw-r--r--basic/source/runtime/methods.cxx11
3 files changed, 52 insertions, 3 deletions
diff --git a/basic/qa/basic_coverage/test_string_replace.vb b/basic/qa/basic_coverage/test_string_replace.vb
new file mode 100644
index 000000000000..99eafdba6b14
--- /dev/null
+++ b/basic/qa/basic_coverage/test_string_replace.vb
@@ -0,0 +1,37 @@
+Dim passCount As Integer
+Dim failCount As Integer
+Dim result As String
+
+Function doUnitTest() As String
+ result = verify_stringReplace()
+ If failCount <> 0 Or passCount = 0 Then
+ doUnitTest = 0
+ Else
+ doUnitTest = 1
+ End If
+End Function
+
+Function verify_stringReplace() As String
+ passCount = 0
+ failCount = 0
+
+ result = "Test Results" & Chr$(10) & "============" & Chr$(10)
+
+ ' tdf#132389 - case-insensitive operation for non-ASCII characters
+ retStr = Replace("ABCabc", "b", "*")
+ TestLog_ASSERT retStr, "A*Ca*c", "case-insensitive ASCII: " & retStr
+ retStr = Replace("АБВабв", "б", "*")
+ TestLog_ASSERT retStr, "А*Ва*в", "case-insensitive non-ASCII: " & retStr
+
+ result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
+ verify_stringReplace = result
+End Function
+
+Sub TestLog_ASSERT(actual As Variant, expected As Variant, testName As String)
+ If expected = actual Then
+ passCount = passCount + 1
+ Else
+ result = result & Chr$(10) & "Failed: " & testName & " returned " & actual & ", expected " & expected
+ failCount = failCount + 1
+ End If
+End Sub
diff --git a/basic/qa/vba_tests/replace.vb b/basic/qa/vba_tests/replace.vb
index 64a3f99421f1..1349c10fae20 100644
--- a/basic/qa/vba_tests/replace.vb
+++ b/basic/qa/vba_tests/replace.vb
@@ -42,6 +42,13 @@ Function verify_testReplace() as String
TestLog_ASSERT retStr = "aefefdBc", "count = 2: " & retStr
retStr = Replace(srcStr, destStr, repStr, 1, 0, vbBinaryCompare)
TestLog_ASSERT retStr = "abcbcdBc", "start = 1, count = 0, not support in Unix: " & retStr
+
+ ' tdf#132389 - case-insensitive operation for non-ASCII characters
+ retStr = Replace("ABCabc", "b", "*", 1, 2, vbTextCompare)
+ TestLog_ASSERT retStr = "A*Ca*c", "case-insensitive ASCII: " & retStr
+ retStr = Replace("АБВабв", "б", "*", 1, 2, vbTextCompare)
+ TestLog_ASSERT retStr = "А*Ва*в", "case-insensitive non-ASCII: " & retStr
+
result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
verify_testReplace = result
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index 75b7b9177b42..106bfe806d0b 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -98,6 +98,9 @@ using namespace com::sun::star::uno;
#include <unistd.h>
#endif
+#include <com/sun/star/i18n/XCharacterClassification.hpp>
+#include <vcl/unohelp.hxx>
+
#if HAVE_FEATURE_SCRIPTING
static void FilterWhiteSpace( OUString& rStr )
@@ -1278,9 +1281,11 @@ void SbRtl_Replace(StarBASIC *, SbxArray & rPar, bool)
OUString aSrcStr(aExpStr);
if (bCaseInsensitive)
{
- // FIXME: case insensitivity should not be ASCII-only
- aSrcStr = aSrcStr.toAsciiUpperCase();
- aFindStr = aFindStr.toAsciiUpperCase();
+ // tdf#132389 - case-insensitive operation for non-ASCII characters
+ const css::lang::Locale& rLocale = Application::GetSettings().GetUILanguageTag().getLocale();
+ css::uno::Reference < i18n::XCharacterClassification > xCharClass = vcl::unohelper::CreateCharacterClassification();
+ aSrcStr = xCharClass->toUpper(aSrcStr, 0, aSrcStr.getLength(), rLocale);
+ aFindStr = xCharClass->toUpper(aFindStr, 0, aSrcStr.getLength(), rLocale);
}
// Note: the result starts from lStartPos, removing everything to the left. See i#94895.