Home » U++ Library support » U++ Core » Some 'missing' string functions
Re: Some 'missing' string functions [message #16304 is a reply to message #13740] |
Fri, 06 June 2008 23:21   |
phirox
Messages: 49 Registered: December 2007
|
Member |
|
|
I really needed a similar thing as find_first_of, and found this topic. It seems there still isn't an implementation or the suggested Filter method, so I wrote my own:
It is modelled after Find and should be added to String.h and AString.hpp. I tested it with String and WString, and couldn't find any bugs. A FindFirstNotOf, FindLastOf, etc. shouldn't be so hard to copy from this model.
int FindFirstOf(int len, const tchar *s, int from) const;
int FindFirstOf(const tchar *s, int from = 0) const;
int FindFirstOf(const String& s, int from = 0) const { return FindFirstOf(s.GetCount(), ~s, from); }
template <class B>
int AString<B>::FindFirstOf(int len, const tchar *s, int from) const
{
ASSERT(from >= 0 && from <= GetLength());
const tchar *ptr = B::Begin();
const tchar *e = End();
const tchar *se = s + (len * sizeof(tchar));
for(const tchar *bs = ptr + from; bs < e; bs++)
for(const tchar *ss = s; ss < se; ss++)
if(*bs == *ss)
return (int)(bs - ptr);
return -1;
}
template <class B>
int AString<B>::FindFirstOf(const tchar *s, int from) const
{
return FindFirstOf(strlen__(s), s, from);
}
|
|
|
 |
|
Some 'missing' string functions
By: mdelfede on Fri, 25 January 2008 12:37
|
 |
|
Re: Some 'missing' string functions
By: mirek on Fri, 25 January 2008 23:05
|
 |
|
Re: Some 'missing' string functions
By: mirek on Fri, 25 January 2008 23:09
|
 |
|
Re: Some 'missing' string functions
By: mdelfede on Sat, 26 January 2008 14:06
|
 |
|
Re: Some 'missing' string functions
By: mirek on Sat, 26 January 2008 14:24
|
 |
|
Re: Some 'missing' string functions
By: mdelfede on Sat, 26 January 2008 14:49
|
 |
|
Re: Some 'missing' string functions
By: phirox on Fri, 06 June 2008 23:21
|
 |
|
Re: Some 'missing' string functions
By: mirek on Sat, 07 June 2008 16:12
|
 |
|
Re: Some 'missing' string functions
By: mr_ped on Mon, 09 June 2008 08:32
|
 |
|
Re: Some 'missing' string functions
By: hans on Mon, 09 June 2008 10:51
|
 |
|
Re: Some 'missing' string functions
By: mirek on Mon, 09 June 2008 14:27
|
 |
|
Re: Some 'missing' string functions
By: mirek on Mon, 09 June 2008 14:28
|
 |
|
Re: Some 'missing' string functions
By: captainc on Thu, 28 August 2008 10:13
|
 |
|
Re: Some 'missing' string functions
By: mirek on Thu, 28 August 2008 15:19
|
Goto Forum:
Current Time: Mon Aug 25 06:13:24 CEST 2025
Total time taken to generate the page: 0.04741 seconds
|