[Libreoffice-commits] core.git: basic/qa basic/source

tushar (via logerrit) logerrit at kemper.freedesktop.org
Sat May 1 11:13:19 UTC 2021


 basic/qa/vba_tests/strconv.vb    |   28 +++++++++++++++++++---------
 basic/source/runtime/methods.cxx |   14 +++++++++++---
 2 files changed, 30 insertions(+), 12 deletions(-)

New commits:
commit 6fecdeac5d81a60a479195a62cdc174b919f763b
Author:     tushar <tusharrai282 at gmail.com>
AuthorDate: Mon Mar 15 22:17:46 2021 +0530
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sat May 1 13:12:22 2021 +0200

    tdf#124184 Fixing StrConv VBA Function
    
    * vbUnicode/vbFromUnicode considers optional third LCID argument.
    * LCID is also used for other conversions.
    * The encoding is decided based on the language defined in LCID,
      or on program locale when LCID is omitted, using MS default
      ACP mapping for languages.
    * Unit testis for vbWide / vbNarrow are changed and enabled.
    * Unit tests for vbKatakana / vbHiragana are changed and enabled.
    * Unit test for vbFromUnicode / vbUnicode is changed to rely on
      en-US locale used in testing, and is enabled.
    
    Change-Id: Iabd4153db311cd02c3f3e7247f9fc71ad9f5f682
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112539
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/basic/qa/vba_tests/strconv.vb b/basic/qa/vba_tests/strconv.vb
index 9bb6f9649a1d..b0295df428b2 100644
--- a/basic/qa/vba_tests/strconv.vb
+++ b/basic/qa/vba_tests/strconv.vb
@@ -23,21 +23,31 @@ Sub verify_testStrConv()
     TestUtil.AssertEqual(StrConv("abc EFG hij", vbProperCase), "Abc Efg Hij", "StrConv(""abc EFG hij"", vbProperCase)")
 
     ' Converts narrow (single-byte) characters in string to wide
-    'TestUtil.AssertEqual(StrConv("ABCDEVB¥ì¥¹¥­¥å©`", vbWide), "£Á£Â£Ã£Ä£ÅVB¥ì¥¹¥­¥å©`", "StrConv(""ABCDEVB¥ì¥¹¥­¥å©`"", vbWide)")
+    TestUtil.AssertEqual(StrConv("ABCDEVB¥ì¥¹¥­¥å©", vbWide), "ABCDEVB¥ì¥¹¥­¥å©", "StrConv(""ABCDEVB¥ì¥¹¥­¥å©"", vbWide)")
 
     ' Converts wide (double-byte) characters in string to narrow (single-byte) characters
-    'TestUtil.AssertEqual(StrConv("£Á£Â£Ã£Ä£ÅVB¥ì¥¹¥­¥å©`", vbNarrow), "ABCDEVB¥ì¥¹¥­¥å©`", "StrConv(""£Á£Â£Ã£Ä£ÅVB¥ì¥¹¥­¥å©`"", vbNarrow)")
+    TestUtil.AssertEqual(StrConv("ABCD@$%23'?EG", vbNarrow), "ABCD@$%23'?EG", "StrConv(""ABCD@$%23'?EG"", vbNarrow)")
 
     ' Converts Hiragana characters in string to Katakana characters
-    'TestUtil.AssertEqual(StrConv("¤Ï¤Ê¤Á¤ã¤ó", vbKatakana), "¥Ï¥Ê¥Á¥ã¥ó", "StrConv(""¤Ï¤Ê¤Á¤ã¤ó"", vbKatakana)")
+    TestUtil.AssertEqual(StrConv("かたかな", vbKatakana), "カタカナ", "StrConv(""かたかな"", vbKatakana)")
 
     ' Converts Katakana characters in string to Hiragana characters
-    'TestUtil.AssertEqual(StrConv("¥Ï¥Ê¥Á¥ã¥ó", vbHiragana), "¤Ï¤Ê¤Á¤ã¤ó", "StrConv(""¥Ï¥Ê¥Á¥ã¥ó"", vbHiragana)")
-
-    'Dim x() As Byte
-    'x = StrConv("ÉϺ£ÊÐABC", vbFromUnicode)
-    'TestUtil.AssertEqual(UBound(x), 8, "UBound(x)")
-    'TestUtil.AssertEqual(StrConv(x, vbUnicode), "ÉϺ£ÊÐABC", "StrConv(x, vbUnicode)")
+    TestUtil.AssertEqual(StrConv("カタカナ", vbHiragana), "かたかな", "StrConv(""カタカナ"", vbHiragana)")
+
+    ' Assumes CP-1252 encoding associated with en-US locale used in unit tests.
+    Dim x() As Byte
+    x = StrConv("ÉϺ£ÊÐABC", vbFromUnicode)
+    TestUtil.AssertEqual(UBound(x), 8, "UBound(x)")
+    TestUtil.AssertEqual(x(0), 201, "x(0)")
+    TestUtil.AssertEqual(x(1), 207, "x(1)")
+    TestUtil.AssertEqual(x(2), 186, "x(2)")
+    TestUtil.AssertEqual(x(3), 163, "x(3)")
+    TestUtil.AssertEqual(x(4), 202, "x(4)")
+    TestUtil.AssertEqual(x(5), 208, "x(5)")
+    TestUtil.AssertEqual(x(6), 65, "x(6)")
+    TestUtil.AssertEqual(x(7), 66, "x(7)")
+    TestUtil.AssertEqual(x(8), 67, "x(8)")
+    TestUtil.AssertEqual(StrConv(x, vbUnicode), "ÉϺ£ÊÐABC", "StrConv(x, vbUnicode)")
 
     Exit Sub
 errorHandler:
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index 910b95f084fa..843c85b4860f 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -39,6 +39,7 @@
 #include <osl/time.h>
 #include <unotools/charclass.hxx>
 #include <unotools/ucbstreamhelper.hxx>
+#include <unotools/wincodepage.hxx>
 #include <tools/wldcrd.hxx>
 #include <i18nlangtag/lang.h>
 #include <rtl/string.hxx>
@@ -4106,6 +4107,14 @@ void SbRtl_StrConv(StarBASIC *, SbxArray & rPar, bool)
 
     OUString aOldStr = rPar.Get(1)->GetOUString();
     sal_Int32 nConversion = rPar.Get(2)->GetLong();
+    LanguageType nLanguage = LANGUAGE_SYSTEM;
+    if (nArgCount == 3)
+    {
+        sal_Int32 lcid = rPar.Get(3)->GetLong();
+        nLanguage = LanguageType(lcid);
+    }
+    OUString sLanguage = LanguageTag(nLanguage).getLanguage();
+    rtl_TextEncoding encodingVal = utl_getWinTextEncodingFromLangStr(sLanguage);
 
     sal_Int32 nOldLen = aOldStr.getLength();
     if( nOldLen == 0 )
@@ -4151,7 +4160,6 @@ void SbRtl_StrConv(StarBASIC *, SbxArray & rPar, bool)
         uno::Reference< uno::XComponentContext > xContext = getProcessComponentContext();
         ::utl::TransliterationWrapper aTransliterationWrapper( xContext, nType );
         uno::Sequence<sal_Int32> aOffsets;
-        LanguageType nLanguage = LANGUAGE_SYSTEM;
         aTransliterationWrapper.loadModuleIfNeeded( nLanguage );
         aNewStr = aTransliterationWrapper.transliterate( aOldStr, nLanguage, 0, nOldLen, &aOffsets );
     }
@@ -4174,14 +4182,14 @@ void SbRtl_StrConv(StarBASIC *, SbxArray & rPar, bool)
         OString aOStr(pChar.get());
 
         // there is no concept about default codepage in unix. so it is incorrectly in unix
-        OUString aOUStr = OStringToOUString(aOStr, osl_getThreadTextEncoding());
+        OUString aOUStr = OStringToOUString(aOStr, encodingVal);
         rPar.Get(0)->PutString(aOUStr);
         return;
     }
     else if ( (nConversion & 0x80) == 128 ) // vbFromUnicode
     {
         // there is no concept about default codepage in unix. so it is incorrectly in unix
-        OString aOStr = OUStringToOString(aNewStr,osl_getThreadTextEncoding());
+        OString aOStr = OUStringToOString(aNewStr, encodingVal);
         const char* pChar = aOStr.getStr();
         sal_Int32 nArraySize = aOStr.getLength();
         SbxDimArray* pArray = new SbxDimArray(SbxBYTE);


More information about the Libreoffice-commits mailing list