Issue 76106 - RFE: ::rtl::OUString::indexOfAscii
Summary: RFE: ::rtl::OUString::indexOfAscii
Status: CLOSED FIXED
Alias: None
Product: udk
Classification: Code
Component: code (show other issues)
Version: current
Hardware: All All
: P3 Trivial (vote)
Target Milestone: OOo 2.3
Assignee: Stephan Bergmann
QA Contact: issues@udk
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-04 21:42 UTC by Frank Schönheit
Modified: 2007-07-04 08:58 UTC (History)
2 users (show)

See Also:
Issue Type: ENHANCEMENT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Frank Schönheit 2007-04-04 21:42:33 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.
Comment 1 Stephan Bergmann 2007-04-05 07:33:59 UTC
I'll add

sal_Int32 indexOfAsciiL(char const* pattern, sal_Int32 len, sal_Int32 from=0);

and similarly lastIndexOfAsciiL.
Comment 2 Frank Schönheit 2007-04-05 07:49:16 UTC
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?
Comment 3 Stephan Bergmann 2007-04-05 07:59:00 UTC
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.
Comment 4 Frank Schönheit 2007-04-05 08:23:40 UTC
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 ...
Comment 5 nospam4obr 2007-05-30 12:00:15 UTC
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.
Comment 6 Stephan Bergmann 2007-06-05 15:08:13 UTC
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.
Comment 7 Frank Schönheit 2007-06-06 19:51:44 UTC
> 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*| ... :(
Comment 8 Stephan Bergmann 2007-06-07 09:07:20 UTC
@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).
Comment 9 Frank Schönheit 2007-06-07 12:15:32 UTC
sure - but an operation every caller has to do again and again, which is what I
don't like.
Comment 10 Stephan Bergmann 2007-06-11 13:17:42 UTC
.
Comment 11 Stephan Bergmann 2007-07-04 08:58:31 UTC
.