head	1.1;
access;
symbols;
locks; strict;
comment	@# @;


1.1
date	2005.09.09.01.18.12;	author myevan;	state Exp;
branches;
next	;


desc
@@


1.1
log
@ó 
@
text
@#ifndef ETER_STRING_UTILS
#define ETER_STRING_UTILS

#include <string>

namespace eter
{

template<typename C>
void string_join(const std::string& sep, const C& container, std::string* ret)
{
	unsigned int capacity = sep.length() * container.size() - 1;
	
	// calculate string sequence
	{
		for (C::const_iterator i = container.begin(); i != container.end(); ++i)
			capacity += (*i).length();
	}

	string buf;
	buf.reserve(capacity);

	// join strings
	{
		C::const_iterator cur = container.begin();
		C::const_iterator end = container.end();
		--end;

		while (cur != end)
		{
			buf.append(*cur++);
			buf.append(sep);
		}
		buf.append(*cur);
	}

	swap(*ret, buf);
}

inline unsigned long string_hash(const char* name)
{
	unsigned char* iter = (unsigned char*)name;	
	unsigned long cur;

	unsigned long ret;
	unsigned long xor;
	
	ret	= 0;
	xor = 0;
	
	while ((cur = *iter++))
	{			
		ret = ( ( ret << 8 ) | cur ) % 16777213UL;
		xor ^= cur;
	}
	
	return ret | (xor<<24);
}

}

#endif@
