diff options
author | Norbert Thiebaud <nthiebaud@gmail.com> | 2012-11-19 22:34:58 -0600 |
---|---|---|
committer | Norbert Thiebaud <nthiebaud@gmail.com> | 2012-11-21 14:57:58 +0000 |
commit | 95841e1393868f0fa7d015b31accea960d35a7b6 (patch) | |
tree | a8ab47fe6c7add113326e1085183944523671a8d /sal | |
parent | 19c54819a9d8f03788a97ecd4296093f72643069 (diff) |
add strip* Family of function to OUStringBuffer
Change-Id: I225f95601009704c93484b6a68a0efd2446d4b48
Reviewed-on: https://gerrit.libreoffice.org/1140
Reviewed-by: Luboš Luňák <l.lunak@suse.cz>
Tested-by: Norbert Thiebaud <nthiebaud@gmail.com>
Reviewed-by: Norbert Thiebaud <nthiebaud@gmail.com>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/inc/rtl/ustrbuf.hxx | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/sal/inc/rtl/ustrbuf.hxx b/sal/inc/rtl/ustrbuf.hxx index 201e79066943..a82a30b15995 100644 --- a/sal/inc/rtl/ustrbuf.hxx +++ b/sal/inc/rtl/ustrbuf.hxx @@ -1102,6 +1102,72 @@ public: pData->buffer, pData->length, literal, internal::ConstCharArrayDetector< T, void >::size - 1); } + /** + Strip the given character from the start of the buffer. + + @since LibreOffice 4.0 + + @param c the character to strip + @return The number of characters stripped + + */ + sal_Int32 stripStart(sal_Unicode c = (sal_Unicode)' ') + { + sal_Int32 index; + for(index = 0; index < getLength() ; index++) + { + if(pData->buffer[ index ] != c) + { + break; + } + } + if(index) + { + remove(0, index); + } + return index; + } + + /** + Strip the given character from the end of the buffer. + + @since LibreOffice 4.0 + + @param c the character to strip + @return The number of characters stripped + + */ + sal_Int32 stripEnd(sal_Unicode c = (sal_Unicode)' ') + { + sal_Int32 result = getLength(); + sal_Int32 index; + for(index = getLength(); index > 0 ; index--) + { + if(pData->buffer[ index - 1 ] != c) + { + break; + } + } + if(index < getLength()) + { + remove(index); + } + return result - getLength(); + } + /** + Strip the given character from the both end of the buffer. + + @since LibreOffice 4.0 + + @param c the character to strip + @return The number of characters stripped + + */ + sal_Int32 strip(sal_Unicode c = (sal_Unicode)' ') + { + return stripStart(c) + stripEnd(c); + } + private: /** A pointer to the data structur which contains the data. |