Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous messageGo to previous message
phirox is currently offline  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);
}
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Commandline-Args with Core-Console-App
Next Topic: Path including non-English character, buglog and usrlog file cannot be deleted
Goto Forum:
  


Current Time: Mon Aug 25 06:13:24 CEST 2025

Total time taken to generate the page: 0.04741 seconds