diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-06-30 09:12:40 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-06-30 11:35:56 +0100 |
commit | 3533a051a623d3587db715d057fb9a3746c0bc19 (patch) | |
tree | 13278be2c9f2e08ab5e4eeabd750319d45b8026e | |
parent | a66e064d81dd6af52c9d56830eba1ca0cf66c51c (diff) |
add StringBuffers ::remove
-rw-r--r-- | sal/inc/rtl/strbuf.h | 19 | ||||
-rw-r--r-- | sal/inc/rtl/strbuf.hxx | 29 | ||||
-rw-r--r-- | sal/inc/rtl/ustrbuf.h | 18 | ||||
-rw-r--r-- | sal/inc/rtl/ustrbuf.hxx | 31 | ||||
-rw-r--r-- | sal/qa/OStringBuffer/rtl_OStringBuffer.cxx | 48 | ||||
-rw-r--r-- | sal/rtl/source/strbuf.c | 33 | ||||
-rw-r--r-- | sal/rtl/source/ustrbuf.c | 32 | ||||
-rwxr-xr-x | sal/util/sal.map | 9 |
8 files changed, 212 insertions, 7 deletions
diff --git a/sal/inc/rtl/strbuf.h b/sal/inc/rtl/strbuf.h index 0156e6ed7..1c076cf46 100644 --- a/sal/inc/rtl/strbuf.h +++ b/sal/inc/rtl/strbuf.h @@ -105,7 +105,6 @@ void SAL_CALL rtl_stringbuffer_ensureCapacity( /*inout*/rtl_String ** This, @param offset the offset. @param ch a character array. @param len the number of characters to append. - @return this string buffer. */ void SAL_CALL rtl_stringbuffer_insert( /*inout*/rtl_String ** This, /*inout*/sal_Int32 * capacity, @@ -113,6 +112,24 @@ void SAL_CALL rtl_stringbuffer_insert( /*inout*/rtl_String ** This, const sal_Char * str, sal_Int32 len); +/** + Removes the characters in a substring of this sequence. + + The substring begins at the specified <code>start</code> and + extends to the character at index <code>end - 1</code> or to + the end of the sequence if no such character exists. If + <code>start</code> is equal to <code>end</code>, no changes + are made. + + start must be >= 0 && <= This->length && <= end + + @param start The beginning index, inclusive + @param end The ending index, exclusive + */ +void SAL_CALL rtl_stringbuffer_remove( /*inout*/rtl_String ** This, + sal_Int32 start, + sal_Int32 end ); + #ifdef __cplusplus } #endif diff --git a/sal/inc/rtl/strbuf.hxx b/sal/inc/rtl/strbuf.hxx index 47f2c0b20..7e52b21ab 100644 --- a/sal/inc/rtl/strbuf.hxx +++ b/sal/inc/rtl/strbuf.hxx @@ -54,7 +54,7 @@ namespace rtl is compiled to the equivalent of: <p><blockquote><pre> x = new OStringBuffer().append("a").append(4).append("c") - .toString() + .makeStringAndClear() </pre></blockquote><p> The principal operations on a <code>OStringBuffer</code> are the <code>append</code> and <code>insert</code> methods, which are @@ -670,6 +670,33 @@ public: sal_Char sz[RTL_STR_MAX_VALUEOFDOUBLE]; return insert( offset, sz, rtl_str_valueOfDouble( sz, d ) ); } + + /** + Removes the characters in a substring of this sequence. + + The substring begins at the specified <code>start</code> and + extends to the character at index <code>end - 1</code> or to + the end of the sequence if no such character exists. If + <code>start</code> is equal to <code>end</code>, no changes + are made. + + start must be >= 0 && <= getLength() && <= end + + As is usual for the rtl string classes, this is based + on an analogous Java StringBuffer member. In this + case <code>delete</code>, but because that's a reserved + keyword in C++, this is named <code>remove</code>. + + @param start The beginning index, inclusive + @param end The ending index, exclusive + @return this string buffer. + */ + OStringBuffer & remove( sal_Int32 start, sal_Int32 end ) + { + rtl_stringbuffer_remove( &pData, start, end ); + return *this; + } + private: /** A pointer to the data structur which contains the data. diff --git a/sal/inc/rtl/ustrbuf.h b/sal/inc/rtl/ustrbuf.h index dfd8019ee..d2d2ed460 100644 --- a/sal/inc/rtl/ustrbuf.h +++ b/sal/inc/rtl/ustrbuf.h @@ -159,6 +159,24 @@ void SAL_CALL rtl_uStringbuffer_insert_ascii( /*inout*/rtl_uString ** This, const sal_Char * str, sal_Int32 len); +/** + Removes the characters in a substring of this sequence. + + The substring begins at the specified <code>start</code> and + extends to the character at index <code>end - 1</code> or to + the end of the sequence if no such character exists. If + <code>start</code> is equal to <code>end</code>, no changes + are made. + + start must be >= 0 && <= This->length && <= end + + @param start The beginning index, inclusive + @param end The ending index, exclusive + */ +void SAL_CALL rtl_uStringbuffer_remove( /*inout*/rtl_uString ** This, + sal_Int32 start, + sal_Int32 end ); + #ifdef __cplusplus } #endif diff --git a/sal/inc/rtl/ustrbuf.hxx b/sal/inc/rtl/ustrbuf.hxx index b6160ccc9..d48c5c762 100644 --- a/sal/inc/rtl/ustrbuf.hxx +++ b/sal/inc/rtl/ustrbuf.hxx @@ -53,7 +53,7 @@ namespace rtl is compiled to the equivalent of: <p><blockquote><pre> x = new OUStringBuffer().append("a").append(4).append("c") - .toString() + .makeStringAndClear() </pre></blockquote><p> The principal operations on a <code>OUStringBuffer</code> are the <code>append</code> and <code>insert</code> methods, which are @@ -95,7 +95,7 @@ public: Allocates a new string buffer that contains the same sequence of characters as the string buffer argument. - @param value a <code>OStringBuffer</code>. + @param value a <code>OUStringBuffer</code>. */ OUStringBuffer( const OUStringBuffer & value ) : pData(NULL) @@ -280,7 +280,6 @@ public: */ const OUString toString() const { return OUString(pData->buffer); } - /** The character at the specified index of this string buffer is set to <code>ch</code>. @@ -739,6 +738,32 @@ public: return *this; } + /** + Removes the characters in a substring of this sequence. + + The substring begins at the specified <code>start</code> and + extends to the character at index <code>end - 1</code> or to + the end of the sequence if no such character exists. If + <code>start</code> is equal to <code>end</code>, no changes + are made. + + start must be >= 0 && <= getLength() && <= end + + As is usual for the rtl string classes, this is based + on an analogous Java StringBuffer member. In this + case <code>delete</code>, but because that's a reserved + keyword in C++, this is named <code>remove</code>. + + @param start The beginning index, inclusive + @param end The ending index, exclusive + @return this string buffer. + */ + OUStringBuffer & remove( sal_Int32 start, sal_Int32 end ) + { + rtl_uStringbuffer_remove( &pData, start, end ); + return *this; + } + /** Allows access to the internal data of this OUStringBuffer, for effective manipulation. diff --git a/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx b/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx index 206287b74..2307dab8c 100644 --- a/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx +++ b/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx @@ -319,6 +319,53 @@ namespace rtl_OStringBuffer CPPUNIT_TEST_SUITE_END(); }; + + class remove : public CppUnit::TestFixture + { + public: + void setUp() + { + } + + void tearDown() + { + } + + void remove_001() + { + ::rtl::OStringBuffer sb( + RTL_CONSTASCII_STRINGPARAM("Red Hat, Inc.")); + + sb.remove(0, 4); + CPPUNIT_ASSERT(sb.toString().equalsL( + RTL_CONSTASCII_STRINGPARAM("Hat, Inc."))); + + sb.remove(3, 9); + CPPUNIT_ASSERT(sb.toString().equalsL( + RTL_CONSTASCII_STRINGPARAM("Hat"))); + + sb.remove(0, 100); + + CPPUNIT_ASSERT(sb.toString().isEmpty()); + + sb.append(RTL_CONSTASCII_STRINGPARAM("Red Hat, Inc.")); + + sb.remove(3, 100); + + CPPUNIT_ASSERT(sb.toString().equalsL( + RTL_CONSTASCII_STRINGPARAM("Red"))); + + sb.remove(0, sb.getLength()); + + CPPUNIT_ASSERT(sb.toString().isEmpty()); + } + + CPPUNIT_TEST_SUITE(remove); + CPPUNIT_TEST(remove_001); + CPPUNIT_TEST_SUITE_END(); + }; + + // ----------------------------------------------------------------------------- class getLength : public CppUnit::TestFixture @@ -16555,6 +16602,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_008_float); CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_008_Float_Negative); CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_009_double); CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::append_009_Double_Negative); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_OStringBuffer::remove); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sal/rtl/source/strbuf.c b/sal/rtl/source/strbuf.c index 446b1cee2..8d0f27625 100644 --- a/sal/rtl/source/strbuf.c +++ b/sal/rtl/source/strbuf.c @@ -144,6 +144,39 @@ void SAL_CALL rtl_stringbuffer_insert( rtl_String ** This, (*This)->length = nOldLen + len; pBuf[ nOldLen + len ] = 0; } +} + +/************************************************************************* + * rtl_stringbuffer_remove + */ +void SAL_CALL rtl_stringbuffer_remove( rtl_String ** This, + sal_Int32 start, + sal_Int32 end ) +{ + sal_Int32 nTailLen; + sal_Char * pBuf; + sal_Int32 n; + + if (end > (*This)->length) + end = (*This)->length; + + n = end - start; + + //remove nothing + if (!n) + return; + + pBuf = (*This)->buffer; + nTailLen = (*This)->length - end; + + if (nTailLen) + { + /* move the tail */ + rtl_moveMemory(pBuf + start, pBuf + end, nTailLen * sizeof(sal_Char)); + } + + (*This)->length-=n; + pBuf[ (*This)->length ] = 0; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/rtl/source/ustrbuf.c b/sal/rtl/source/ustrbuf.c index 33317b6f3..18ca27f22 100644 --- a/sal/rtl/source/ustrbuf.c +++ b/sal/rtl/source/ustrbuf.c @@ -206,5 +206,37 @@ void SAL_CALL rtl_uStringbuffer_insert_ascii( /*inout*/rtl_uString ** This, } } +/************************************************************************* + * rtl_uStringbuffer_remove + */ +void SAL_CALL rtl_uStringbuffer_remove( rtl_uString ** This, + sal_Int32 start, + sal_Int32 end ) +{ + sal_Int32 nTailLen; + sal_Unicode * pBuf; + sal_Int32 n; + + if (end > (*This)->length) + end = (*This)->length; + + n = end - start; + + //remove nothing + if (!n) + return; + + pBuf = (*This)->buffer; + nTailLen = (*This)->length - end; + + if (nTailLen) + { + /* move the tail */ + rtl_moveMemory(pBuf + start, pBuf + end, nTailLen * sizeof(sal_Unicode)); + } + + (*This)->length-=n; + pBuf[ (*This)->length ] = 0; +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/util/sal.map b/sal/util/sal.map index 020e11fbc..152b02349 100755 --- a/sal/util/sal.map +++ b/sal/util/sal.map @@ -598,14 +598,19 @@ UDK_3.10 { # OOo 3.2 rtl_math_acosh; } UDK_3.9; - -UDK_3.11 { # OOo 3.4 +UDK_3.11 { # symbols available in >= OOo/LibO 3.4 global: osl_setEnvironment; osl_clearEnvironment; osl_setThreadName; } UDK_3.10; +LIBO_UDK_3.5 { # symbols available in >= LibO 3.5 + global: + rtl_stringbuffer_remove; + rtl_uStringbuffer_remove; +} UDK_3.10; + PRIVATE_1.0 { global: osl_detail_ObjectRegistry_storeAddresses; |