summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2011-06-30 09:12:40 +0100
committerCaolán McNamara <caolanm@redhat.com>2011-06-30 11:35:56 +0100
commit1a2912eed9980d7ded481bc60a81597b0c699481 (patch)
tree6528508c2e04c31345ad1a4392638b118b561b40
parent4312ed8c4f85575ab125da84ba09f02430ee9a89 (diff)
add StringBuffers ::remove
-rw-r--r--sal/inc/rtl/strbuf.h19
-rw-r--r--sal/inc/rtl/strbuf.hxx29
-rw-r--r--sal/inc/rtl/ustrbuf.h18
-rw-r--r--sal/inc/rtl/ustrbuf.hxx31
-rw-r--r--sal/qa/OStringBuffer/rtl_OStringBuffer.cxx48
-rw-r--r--sal/rtl/source/strbuf.c33
-rw-r--r--sal/rtl/source/ustrbuf.c32
-rwxr-xr-xsal/util/sal.map9
8 files changed, 212 insertions, 7 deletions
diff --git a/sal/inc/rtl/strbuf.h b/sal/inc/rtl/strbuf.h
index 584137f6d38c..78f604009c11 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 918f2e6e6fa7..48a55683bd46 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 a7295f5e5324..36e5652000db 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 3f3498aa2ecf..bde72fc0cde2 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 b01862f1bb86..257a31b93e4a 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 47fd5c8b51ed..a620a3c0419d 100644
--- a/sal/rtl/source/strbuf.c
+++ b/sal/rtl/source/strbuf.c
@@ -146,4 +146,37 @@ void SAL_CALL rtl_stringbuffer_insert( rtl_String ** This,
}
}
+/*************************************************************************
+ * 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 3b05eb258c90..f5dbefdb75b8 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 020e11fbcb57..152b02349d9c 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;