svl/inc/svl/lngmisc.hxx      |   42 +++++++++++++++++-------------------------
 svl/qa/unit/test_lngmisc.cxx |   40 +++++++++++++++++++++++++++++++++++-----
 svl/source/misc/lngmisc.cxx  |   33 ++++++++++++++++++---------------
 3 files changed, 70 insertions(+), 45 deletions(-)

New commits:
commit 69ee7654fa662a577890d594214cba1b0cbfea6f
Author: August Sodora <aug...@gmail.com>
Date:   Sat Nov 26 22:56:51 2011 -0500

    Remove unnecessary includes

diff --git a/svl/inc/svl/lngmisc.hxx b/svl/inc/svl/lngmisc.hxx
index c24ed4d..d3521bc 100644
--- a/svl/inc/svl/lngmisc.hxx
+++ b/svl/inc/svl/lngmisc.hxx
@@ -33,10 +33,6 @@
 
 #include <rtl/ustring.hxx>
 
-class String;
-
-///////////////////////////////////////////////////////////////////////////
-
 #define SVT_SOFT_HYPHEN (static_cast<sal_Unicode>(0x00AD))
 #define SVT_HARD_HYPHEN (static_cast<sal_Unicode>(0x2011))
 
diff --git a/svl/source/misc/lngmisc.cxx b/svl/source/misc/lngmisc.cxx
index 1c42160..2e6a0a4 100644
--- a/svl/source/misc/lngmisc.cxx
+++ b/svl/source/misc/lngmisc.cxx
@@ -34,7 +34,6 @@
 #include <comphelper/string.hxx>
 #include <rtl/ustrbuf.hxx>
 #include <tools/debug.hxx>
-#include <tools/string.hxx>
 
 namespace linguistic
 {
commit a627ec05ce7ea85acaeab68aee925c4c295e9c4a
Author: August Sodora <aug...@gmail.com>
Date:   Sat Nov 26 22:56:17 2011 -0500

    Cosmetic

diff --git a/svl/inc/svl/lngmisc.hxx b/svl/inc/svl/lngmisc.hxx
index 72d829c..c24ed4d 100644
--- a/svl/inc/svl/lngmisc.hxx
+++ b/svl/inc/svl/lngmisc.hxx
@@ -45,27 +45,23 @@ class String;
 
 namespace linguistic
 {
-
-inline bool IsHyphen( sal_Unicode cChar )
-{
-    return cChar == SVT_SOFT_HYPHEN  ||  cChar == SVT_HARD_HYPHEN;
-}
-
-
-inline bool IsControlChar( sal_Unicode cChar )
-{
-    // TODO: why doesn't this include 0x0F DEL?
-    return cChar < static_cast<sal_Unicode>(' ');
-}
-
-SVL_DLLPRIVATE sal_Int32 GetNumControlChars( const rtl::OUString &rTxt );
-SVL_DLLPUBLIC bool  RemoveHyphens( rtl::OUString &rTxt );
-SVL_DLLPUBLIC bool  RemoveControlChars( rtl::OUString &rTxt );
-
-SVL_DLLPUBLIC bool ReplaceControlChars(rtl::OUString &rTxt);
-
-SVL_DLLPUBLIC ::rtl::OUString GetThesaurusReplaceText( const ::rtl::OUString 
&rText );
-
+    inline bool IsHyphen(sal_Unicode cChar)
+    {
+        return cChar == SVT_SOFT_HYPHEN  ||  cChar == SVT_HARD_HYPHEN;
+    }
+
+    inline bool IsControlChar(sal_Unicode cChar)
+    {
+        // TODO: why doesn't this include 0x0F DEL?
+        return cChar < static_cast<sal_Unicode>(' ');
+    }
+
+    SVL_DLLPRIVATE sal_Int32 GetNumControlChars( const rtl::OUString &rTxt );
+
+    SVL_DLLPUBLIC bool RemoveHyphens(rtl::OUString &rTxt);
+    SVL_DLLPUBLIC bool RemoveControlChars(rtl::OUString &rTxt);
+    SVL_DLLPUBLIC bool ReplaceControlChars(rtl::OUString &rTxt);
+    SVL_DLLPUBLIC ::rtl::OUString GetThesaurusReplaceText(const 
::rtl::OUString &rText);
 } // namespace linguistic
 
 #endif
commit d5737d5b4c5b350b7b08e848b9d30f4ea9c8063b
Author: August Sodora <aug...@gmail.com>
Date:   Sat Nov 26 22:55:20 2011 -0500

    Remove unnecessary casts

diff --git a/svl/source/misc/lngmisc.cxx b/svl/source/misc/lngmisc.cxx
index 2372e81..1c42160 100644
--- a/svl/source/misc/lngmisc.cxx
+++ b/svl/source/misc/lngmisc.cxx
@@ -114,10 +114,10 @@ namespace linguistic
 
         ::rtl::OUString aText(rText);
 
-        sal_Int32 nPos = aText.indexOf(sal_Unicode('('));
+        sal_Int32 nPos = aText.indexOf('(');
         while (nPos >= 0)
         {
-            sal_Int32 nEnd = aText.indexOf(sal_Unicode(')'), nPos);
+            sal_Int32 nEnd = aText.indexOf(')', nPos);
             if (nEnd >= 0)
             {
                 ::rtl::OUStringBuffer aTextBuf(aText);
@@ -126,12 +126,12 @@ namespace linguistic
             }
             else
                 break;
-            nPos = aText.indexOf(sal_Unicode('('));
+            nPos = aText.indexOf('(');
         }
 
-        nPos = aText.indexOf(sal_Unicode('*'));
+        nPos = aText.indexOf('*');
         if(nPos == 0)
-            aText = ::rtl::OUString();
+            return ::rtl::OUString();
         else if(nPos > 0)
             aText = aText.copy(0, nPos);
 
commit 38ba2f002b6fe76273b3abc1092a93e10551057a
Author: August Sodora <aug...@gmail.com>
Date:   Sat Nov 26 22:53:32 2011 -0500

    String->OUString

diff --git a/svl/inc/svl/lngmisc.hxx b/svl/inc/svl/lngmisc.hxx
index 4a94bc7..72d829c 100644
--- a/svl/inc/svl/lngmisc.hxx
+++ b/svl/inc/svl/lngmisc.hxx
@@ -64,7 +64,7 @@ SVL_DLLPUBLIC bool  RemoveControlChars( rtl::OUString &rTxt );
 
 SVL_DLLPUBLIC bool ReplaceControlChars(rtl::OUString &rTxt);
 
-SVL_DLLPUBLIC String GetThesaurusReplaceText( const String &rText );
+SVL_DLLPUBLIC ::rtl::OUString GetThesaurusReplaceText( const ::rtl::OUString 
&rText );
 
 } // namespace linguistic
 
diff --git a/svl/source/misc/lngmisc.cxx b/svl/source/misc/lngmisc.cxx
index 49a4433..2372e81 100644
--- a/svl/source/misc/lngmisc.cxx
+++ b/svl/source/misc/lngmisc.cxx
@@ -105,35 +105,39 @@ namespace linguistic
         return true;
     }
 
-    String GetThesaurusReplaceText(const String &rText)
+    ::rtl::OUString GetThesaurusReplaceText(const ::rtl::OUString &rText)
     {
         // The strings for synonyms returned by the thesaurus sometimes have 
some
         // explanation text put in between '(' and ')' or a trailing '*'.
         // These parts should not be put in the ReplaceEdit Text that may get
         // inserted into the document. Thus we strip them from the text.
 
-        String aText( rText );
+        ::rtl::OUString aText(rText);
 
-        xub_StrLen nPos = aText.Search( sal_Unicode('(') );
-        while (STRING_NOTFOUND != nPos)
+        sal_Int32 nPos = aText.indexOf(sal_Unicode('('));
+        while (nPos >= 0)
         {
-            xub_StrLen nEnd = aText.Search( sal_Unicode(')'), nPos );
-            if (STRING_NOTFOUND != nEnd)
-                aText.Erase( nPos, nEnd-nPos+1 );
+            sal_Int32 nEnd = aText.indexOf(sal_Unicode(')'), nPos);
+            if (nEnd >= 0)
+            {
+                ::rtl::OUStringBuffer aTextBuf(aText);
+                aTextBuf.remove(nPos, nEnd - nPos + 1);
+                aText = aTextBuf.makeStringAndClear();
+            }
             else
                 break;
-            nPos = aText.Search( sal_Unicode('(') );
+            nPos = aText.indexOf(sal_Unicode('('));
         }
 
-        nPos = aText.Search( sal_Unicode('*') );
-        if (STRING_NOTFOUND != nPos)
-            aText.Erase( nPos );
+        nPos = aText.indexOf(sal_Unicode('*'));
+        if(nPos == 0)
+            aText = ::rtl::OUString();
+        else if(nPos > 0)
+            aText = aText.copy(0, nPos);
 
         // remove any possible remaining ' ' that may confuse the thesaurus
         // when it gets called with the text
-        aText = comphelper::string::strip(aText, ' ');
-
-        return aText;
+        return comphelper::string::strip(aText, ' ');
     }
 } // namespace linguistic
 
commit 530fc2fef8ff53ad99ac43b3a8bb8a70a358b4b7
Author: August Sodora <aug...@gmail.com>
Date:   Sat Nov 26 22:43:23 2011 -0500

    Added test to lngmisc

diff --git a/svl/qa/unit/test_lngmisc.cxx b/svl/qa/unit/test_lngmisc.cxx
index d982f44..d9c6ef3 100644
--- a/svl/qa/unit/test_lngmisc.cxx
+++ b/svl/qa/unit/test_lngmisc.cxx
@@ -9,6 +9,7 @@
 #include "svl/lngmisc.hxx"
 
 #include <rtl/ustrbuf.hxx>
+#include <tools/string.hxx>
 
 namespace
 {
@@ -18,14 +19,14 @@ namespace
     void testRemoveHyphens();
     void testRemoveControlChars();
     void testReplaceControlChars();
-    //    void testGetThesaurusReplaceText();
+    void testGetThesaurusReplaceText();
 
     CPPUNIT_TEST_SUITE(LngMiscTest);
 
     CPPUNIT_TEST(testRemoveHyphens);
     CPPUNIT_TEST(testRemoveControlChars);
     CPPUNIT_TEST(testReplaceControlChars);
-    //    CPPUNIT_TEST(testGetThesaurusReplaceText);
+    CPPUNIT_TEST(testGetThesaurusReplaceText);
 
     CPPUNIT_TEST_SUITE_END();
   };
@@ -125,12 +126,41 @@ namespace
       CPPUNIT_ASSERT(str4[i] == ' ');
   }
 
-  /*
   void LngMiscTest::testGetThesaurusReplaceText()
   {
-    CPPUNIT_ASSERT(true);
+    const static String str1(RTL_CONSTASCII_USTRINGPARAM(""));
+    const static String str2(RTL_CONSTASCII_USTRINGPARAM("asdf"));
+    const static String str3(RTL_CONSTASCII_USTRINGPARAM("asdf (abc)"));
+    const static String str4(RTL_CONSTASCII_USTRINGPARAM("asdf*"));
+    const static String str5(RTL_CONSTASCII_USTRINGPARAM("asdf * "));
+    const static String str6(RTL_CONSTASCII_USTRINGPARAM("asdf (abc) *"));
+    const static String str7(RTL_CONSTASCII_USTRINGPARAM("asdf asdf * (abc)"));
+    const static String str8(RTL_CONSTASCII_USTRINGPARAM(" * (abc) asdf *"));
+
+    String r = linguistic::GetThesaurusReplaceText(str1);
+    CPPUNIT_ASSERT(!r.Len());
+
+    r = linguistic::GetThesaurusReplaceText(str2);
+    CPPUNIT_ASSERT(r == str2);
+
+    r = linguistic::GetThesaurusReplaceText(str3);
+    CPPUNIT_ASSERT(r == str2);
+
+    r = linguistic::GetThesaurusReplaceText(str4);
+    CPPUNIT_ASSERT(r == str2);
+
+    r = linguistic::GetThesaurusReplaceText(str5);
+    CPPUNIT_ASSERT(r == str2);
+
+    r = linguistic::GetThesaurusReplaceText(str6);
+    CPPUNIT_ASSERT(r == str2);
+
+    r = linguistic::GetThesaurusReplaceText(str7);
+    CPPUNIT_ASSERT(r == String::CreateFromAscii("asdf asdf"));
+
+    r = linguistic::GetThesaurusReplaceText(str8);
+    CPPUNIT_ASSERT(!r.Len());
   }
-  */
 
   CPPUNIT_TEST_SUITE_REGISTRATION(LngMiscTest);
 }
_______________________________________________
Libreoffice-commits mailing list
Libreoffice-commits@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to