Apache OpenOffice (AOO) Bugzilla – Issue 76106
RFE: ::rtl::OUString::indexOfAscii
Last modified: 2007-07-04 08:58:31 UTC
again being in need of some (efficient) possibility to replace a number of patterns in a string with other strings, I wonder whether it would make sense to have some sal_Int32 indexOfAscii( const sal_Char* pAsciiPattern, sal_Int32 fromIndex = 0 ) const method in the ::rtl::OUString class. This would safe repeated creations of temporary OUStrings from an ASCII literal string.
I'll add sal_Int32 indexOfAsciiL(char const* pattern, sal_Int32 len, sal_Int32 from=0); and similarly lastIndexOfAsciiL.
I know I'm immodest :), but why only the L versions? Those require sString.indexOfAsciiL( "foo", sizeof( "foo" ) - 1 ) or sString.indexOfAsciiL( RTL_CONSTASCII_USTRINGPARAM( "foo" ) ) or sString.indexOfAsciiL( pSomeAsciiString, strlen( pSomeAsciiString ) ) where the non-L version would allow the shorter sString.indexOfAscii( "foo" ) resp. sString.indexOfAscii( pSomeAsciiString ) Any chance you re-consider this?
Ha! Otherwise it's always you to throw in the word "optimization." ;) Now, I'm offering that neatly pre-optimized, len-included stuff all by myself, and you complain... :( I'll see how best to implement that stuff in the first place and then decide on a balanced interface.
LOL :) I don't complain about you adding the L versions, in fact I think that's a good idea, since there are other scenrios where they have their advantage. It's just that I'm really lazy :), and I don't like to type that much stuff as shown above all the time. I think both versions have some reasons for them to be added ...
obr->sb: as discussed via phone, I am also missing OUString::endsWithAsciiL (there already is OUString::endsWithIgnoreAsciiCaseAsciiL). Please add it with this issue as well.
Added: rtl/ustring.h: sal_Int32 SAL_CALL rtl_ustr_indexOfAscii_WithLength(sal_Unicode const * str, sal_Int32 len, char const * subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C() sal_Int32 SAL_CALL rtl_ustr_lastIndexOfAscii_WithLength(sal_Unicode const * str, sal_Int32 len, char const * subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C() rtl/ustring.hxx: bool rtl::OUString::endsWithAsciiL(char const * asciiStr, sal_Int32 asciiStrLength) const sal_Int32 rtl::OUString::indexOfAsciiL(char const * str, sal_Int32 len, sal_Int32 fromIndex = 0) const SAL_THROW(()) sal_Int32 rtl::OUString::lastIndexOfAsciiL(char const * str, sal_Int32 len) const SAL_THROW(()) See sal/qa/rtl/oustring/rtl_OUString2.cxx:1.9.4.1 for tests.
> I'll see how best to implement that stuff in the first place and then > decide on a balanced interface. Does this mean that decision was against an mere indexOfAscii? Sad, since this forces the usage of strlen in place where you do not have a constant ASCII literal, but only a |sal_Char const*| ... :(
@fs: "Does this mean that decision was against an mere indexOfAscii?" Yes. The implementation can make good use of the length, so it should be acceptable that the caller supply it (obtaining the length is a trivial operation for the caller).
sure - but an operation every caller has to do again and again, which is what I don't like.
.