summaryrefslogtreecommitdiff
path: root/sal/inc
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@suse.com>2012-10-02 18:39:30 +0100
committerMichael Meeks <michael.meeks@suse.com>2012-10-02 18:39:54 +0100
commit595ba03fd4769c069bbe0431ab878956ef1c37ad (patch)
treea0db9fe4e82e34b8606bc5be54d24df49a749e9a /sal/inc
parent2d25eea6949196d2275d8b2bd484e6dab0163a33 (diff)
update string copy semantics to be undefined in a non-crashing way.
Change-Id: I03bb4db5931932280e368012cbaee6bef2854dd6
Diffstat (limited to 'sal/inc')
-rw-r--r--sal/inc/rtl/string.h17
-rw-r--r--sal/inc/rtl/string.hxx36
-rw-r--r--sal/inc/rtl/ustring.h17
-rw-r--r--sal/inc/rtl/ustring.hxx36
4 files changed, 58 insertions, 48 deletions
diff --git a/sal/inc/rtl/string.h b/sal/inc/rtl/string.h
index c38e106e6fdb..6dd42363b98a 100644
--- a/sal/inc/rtl/string.h
+++ b/sal/inc/rtl/string.h
@@ -889,6 +889,23 @@ SAL_DLLPUBLIC void SAL_CALL rtl_string_newFromStr( rtl_String ** newStr, const s
*/
SAL_DLLPUBLIC void SAL_CALL rtl_string_newFromStr_WithLength( rtl_String ** newStr, const sal_Char * value, sal_Int32 len ) SAL_THROW_EXTERN_C();
+/** Allocate a new string that is a substring of this string.
+
+ The substring begins at the specified beginIndex and contains count
+ characters. Meaningless combinations such as negative beginIndex,
+ or beginIndex + count greater than the length of the string have
+ undefined behaviour.
+
+ @param beginIndex the beginning index, inclusive.
+ @param count the number of characters.
+ @return the specified substring.
+
+ @since LibreOffice 3.7
+ */
+SAL_DLLPUBLIC void SAL_CALL rtl_string_newFromSubString(
+ rtl_String ** newStr, const rtl_String * from,
+ sal_Int32 beginIndex, sal_Int32 count ) SAL_THROW_EXTERN_C();
+
/**
@internal
@since LibreOffice 3.6
diff --git a/sal/inc/rtl/string.hxx b/sal/inc/rtl/string.hxx
index 84ab48e05dc6..d58999b812f6 100644
--- a/sal/inc/rtl/string.hxx
+++ b/sal/inc/rtl/string.hxx
@@ -1024,31 +1024,27 @@ public:
/**
Returns a new string that is a substring of this string.
- The substring begins at the specified beginIndex. It is an error for
- beginIndex to be negative or to be greater than the length of this string.
+ The substring begins at the specified beginIndex. If
+ beginIndex is negative or be greater than the length of
+ this string, behaviour is undefined.
@param beginIndex the beginning index, inclusive.
@return the specified substring.
*/
OString copy( sal_Int32 beginIndex ) const SAL_THROW(())
{
- assert(beginIndex >= 0 && beginIndex <= getLength());
- if ( beginIndex == 0 )
- return *this;
- else
- {
- rtl_String* pNew = 0;
- rtl_string_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, getLength()-beginIndex );
- return OString( pNew, (DO_NOT_ACQUIRE*)0 );
- }
+ rtl_String *pNew = 0;
+ rtl_string_newFromSubString( &pNew, pData, beginIndex, getLength() - beginIndex );
+ return OString( pNew, (DO_NOT_ACQUIRE*)0 );
}
/**
Returns a new string that is a substring of this string.
The substring begins at the specified beginIndex and contains count
- characters. It is an error for either beginIndex or count to be negative,
- or for beginIndex + count to be greater than the length of this string.
+ characters. If either beginIndex or count are negative,
+ or beginIndex + count are greater than the length of this string
+ then behaviour is undefined.
@param beginIndex the beginning index, inclusive.
@param count the number of characters.
@@ -1056,17 +1052,9 @@ public:
*/
OString copy( sal_Int32 beginIndex, sal_Int32 count ) const SAL_THROW(())
{
- assert(beginIndex >= 0 && beginIndex <= getLength() && count >= 0
- && sal::static_int_cast<sal_uInt32>(count) <=
- sal::static_int_cast<sal_uInt32>(getLength() - beginIndex));
- if ( (beginIndex == 0) && (count == getLength()) )
- return *this;
- else
- {
- rtl_String* pNew = 0;
- rtl_string_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, count );
- return OString( pNew, (DO_NOT_ACQUIRE*)0 );
- }
+ rtl_String *pNew = 0;
+ rtl_string_newFromSubString( &pNew, pData, beginIndex, count );
+ return OString( pNew, (DO_NOT_ACQUIRE*)0 );
}
/**
diff --git a/sal/inc/rtl/ustring.h b/sal/inc/rtl/ustring.h
index 5b4982ec1461..231dcdce253a 100644
--- a/sal/inc/rtl/ustring.h
+++ b/sal/inc/rtl/ustring.h
@@ -1226,6 +1226,23 @@ SAL_DLLPUBLIC void SAL_CALL rtl_uString_newFromStr(
SAL_DLLPUBLIC void SAL_CALL rtl_uString_newFromStr_WithLength(
rtl_uString ** newStr, const sal_Unicode * value, sal_Int32 len ) SAL_THROW_EXTERN_C();
+/** Allocate a new string that is a substring of this string.
+
+ The substring begins at the specified beginIndex and contains count
+ characters. Meaningless combinations such as negative beginIndex,
+ or beginIndex + count greater than the length of the string have
+ undefined behaviour.
+
+ @param beginIndex the beginning index, inclusive.
+ @param count the number of characters.
+ @return the specified substring.
+
+ @since LibreOffice 3.7
+ */
+SAL_DLLPUBLIC void SAL_CALL rtl_uString_newFromSubString(
+ rtl_uString ** newStr, const rtl_uString * from,
+ sal_Int32 beginIndex, sal_Int32 count ) SAL_THROW_EXTERN_C();
+
/** Allocate a new string that contains a copy of a character array.
If the length of value is greater than zero, the reference count of the
diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx
index b008054e17e3..e12a4b0b6256 100644
--- a/sal/inc/rtl/ustring.hxx
+++ b/sal/inc/rtl/ustring.hxx
@@ -1340,31 +1340,27 @@ public:
/**
Returns a new string that is a substring of this string.
- The substring begins at the specified beginIndex. It is an error for
- beginIndex to be negative or to be greater than the length of this string.
+ The substring begins at the specified beginIndex. If
+ beginIndex is negative or be greater than the length of
+ this string, behaviour is undefined.
@param beginIndex the beginning index, inclusive.
@return the specified substring.
*/
OUString copy( sal_Int32 beginIndex ) const SAL_THROW(())
{
- assert(beginIndex >= 0 && beginIndex <= getLength());
- if ( beginIndex == 0 )
- return *this;
- else
- {
- rtl_uString* pNew = 0;
- rtl_uString_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, getLength()-beginIndex );
- return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
- }
+ rtl_uString *pNew = 0;
+ rtl_uString_newFromSubString( &pNew, pData, beginIndex, getLength() - beginIndex );
+ return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
}
/**
Returns a new string that is a substring of this string.
The substring begins at the specified beginIndex and contains count
- characters. It is an error for either beginIndex or count to be negative,
- or for beginIndex + count to be greater than the length of this string.
+ characters. If either beginIndex or count are negative,
+ or beginIndex + count are greater than the length of this string
+ then behaviour is undefined.
@param beginIndex the beginning index, inclusive.
@param count the number of characters.
@@ -1372,17 +1368,9 @@ public:
*/
OUString copy( sal_Int32 beginIndex, sal_Int32 count ) const SAL_THROW(())
{
- assert(beginIndex >= 0 && beginIndex <= getLength() && count >= 0
- && sal::static_int_cast< sal_uInt32 >(count) <=
- sal::static_int_cast< sal_uInt32 >(getLength() - beginIndex));
- if ( (beginIndex == 0) && (count == getLength()) )
- return *this;
- else
- {
- rtl_uString* pNew = 0;
- rtl_uString_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, count );
- return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
- }
+ rtl_uString *pNew = 0;
+ rtl_uString_newFromSubString( &pNew, pData, beginIndex, count );
+ return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
}
/**