Kaydet (Commit) 83345ff8 authored tarafından August Sodora's avatar August Sodora

Simplification and accompanying tests

üst e280ff03
...@@ -17,14 +17,14 @@ namespace ...@@ -17,14 +17,14 @@ namespace
private: private:
void testRemoveHyphens(); void testRemoveHyphens();
void testRemoveControlChars(); void testRemoveControlChars();
// void testReplaceControlChars(); void testReplaceControlChars();
// void testGetThesaurusReplaceText(); // void testGetThesaurusReplaceText();
CPPUNIT_TEST_SUITE(LngMiscTest); CPPUNIT_TEST_SUITE(LngMiscTest);
CPPUNIT_TEST(testRemoveHyphens); CPPUNIT_TEST(testRemoveHyphens);
CPPUNIT_TEST(testRemoveControlChars); CPPUNIT_TEST(testRemoveControlChars);
// CPPUNIT_TEST(testReplaceControlChars); CPPUNIT_TEST(testReplaceControlChars);
// CPPUNIT_TEST(testGetThesaurusReplaceText); // CPPUNIT_TEST(testGetThesaurusReplaceText);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
...@@ -92,12 +92,40 @@ namespace ...@@ -92,12 +92,40 @@ namespace
CPPUNIT_ASSERT(str4.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(" "))); CPPUNIT_ASSERT(str4.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(" ")));
} }
/*
void LngMiscTest::testReplaceControlChars() void LngMiscTest::testReplaceControlChars()
{ {
CPPUNIT_ASSERT(true); ::rtl::OUString str1(RTL_CONSTASCII_USTRINGPARAM(""));
::rtl::OUString str2(RTL_CONSTASCII_USTRINGPARAM("asdf"));
::rtl::OUString str3(RTL_CONSTASCII_USTRINGPARAM("asdf\nasdf"));
::rtl::OUStringBuffer str4Buf(33);
str4Buf.setLength(33);
for(int i = 0; i < 33; i++)
str4Buf[i] = static_cast<sal_Unicode>(i);
// TODO: is this a bug? shouldn't RemoveControlChars remove this?
// str4Buf[33] = static_cast<sal_Unicode>(0x7F);
::rtl::OUString str4(str4Buf.makeStringAndClear());
bool bModified = linguistic::ReplaceControlChars(str1);
CPPUNIT_ASSERT(!bModified);
CPPUNIT_ASSERT(str1.isEmpty());
bModified = linguistic::ReplaceControlChars(str2);
CPPUNIT_ASSERT(!bModified);
CPPUNIT_ASSERT(str2.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("asdf")));
bModified = linguistic::ReplaceControlChars(str3);
CPPUNIT_ASSERT(bModified);
CPPUNIT_ASSERT(str3.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("asdf asdf")));
bModified = linguistic::ReplaceControlChars(str4);
CPPUNIT_ASSERT(bModified);
CPPUNIT_ASSERT(str4.getLength() == 32);
for(int i = 0; i < 32; i++)
CPPUNIT_ASSERT(str4[i] == ' ');
} }
/*
void LngMiscTest::testGetThesaurusReplaceText() void LngMiscTest::testGetThesaurusReplaceText()
{ {
CPPUNIT_ASSERT(true); CPPUNIT_ASSERT(true);
......
...@@ -82,29 +82,27 @@ namespace linguistic ...@@ -82,29 +82,27 @@ namespace linguistic
// 1. non breaking field characters get removed // 1. non breaking field characters get removed
// 2. remaining control characters will be replaced by ' ' // 2. remaining control characters will be replaced by ' '
bool bModified = false; if (GetNumControlChars(rTxt) == 0)
sal_Int32 nCtrlChars = GetNumControlChars( rTxt ); return false;
if (nCtrlChars)
sal_Int32 n = rTxt.getLength();
rtl::OUStringBuffer aBuf(n);
aBuf.setLength(n);
sal_Int32 j = 0;
for (sal_Int32 i = 0; i < n && j < n; ++i)
{ {
sal_Int32 nLen = rTxt.getLength(); if (CH_TXTATR_INWORD == rTxt[i])
rtl::OUStringBuffer aBuf( nLen ); continue;
sal_Int32 nCnt = 0;
for (sal_Int32 i = 0; i < nLen; ++i) aBuf[j++] = IsControlChar(rTxt[i]) ? ' ' : rTxt[i];
{
sal_Unicode cChar = rTxt[i];
if (CH_TXTATR_INWORD != cChar)
{
if (IsControlChar( cChar ))
cChar = ' ';
DBG_ASSERT( nCnt < nLen, "index out of range" );
aBuf.setCharAt( nCnt++, cChar );
}
}
aBuf.setLength( nCnt );
rTxt = aBuf.makeStringAndClear();
bModified = true;
} }
return bModified;
aBuf.setLength(j);
rTxt = aBuf.makeStringAndClear();
return true;
} }
String GetThesaurusReplaceText(const String &rText) String GetThesaurusReplaceText(const String &rText)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment