Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/namebuilder.h"
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
NameBuilder *NameBuilder::getBuilder(wstring levelName)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (levelName == L"")
Toshihiro Shimizu 890ddd
		return new NameCreator();
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		return new NameModifier(levelName);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
wstring NameCreator::getNext()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_s.empty()) {
Toshihiro Shimizu 890ddd
		m_s.push_back(0);
Toshihiro Shimizu 890ddd
		return L"A";
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int i = 0;
Toshihiro Shimizu 890ddd
	int n = m_s.size();
Toshihiro Shimizu 890ddd
	while (i < n) {
Toshihiro Shimizu 890ddd
		m_s[i]++;
Toshihiro Shimizu 890ddd
		if (m_s[i] <= 'Z' - 'A')
Toshihiro Shimizu 890ddd
			break;
Toshihiro Shimizu 890ddd
		m_s[i] = 0;
Toshihiro Shimizu 890ddd
		i++;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (i >= n) {
Toshihiro Shimizu 890ddd
		n++;
Toshihiro Shimizu 890ddd
		m_s.push_back(0);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	wstring s;
Toshihiro Shimizu 890ddd
	for (i = n - 1; i >= 0; i--)
Toshihiro Shimizu 890ddd
		s.append(1, (wchar_t)(L'A' + m_s[i]));
Toshihiro Shimizu 890ddd
	return s;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
NameModifier::NameModifier(wstring name)
Toshihiro Shimizu 890ddd
	: m_nameBase(name), m_index(0)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int j = name.find_last_not_of(L"0123456789");
Toshihiro Shimizu 890ddd
	if (j != (int)wstring::npos &&
Toshihiro Shimizu 890ddd
		j + 1 < (int)name.length() &&
Toshihiro Shimizu 890ddd
		name[j] == '_') {
Toshihiro Shimizu 890ddd
		m_index = toInt(name.substr(j + 1));
Toshihiro Shimizu 890ddd
		m_nameBase = name.substr(0, j);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
wstring NameModifier::getNext()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int index = m_index++;
Toshihiro Shimizu 890ddd
	if (index < 1)
Toshihiro Shimizu 890ddd
		return m_nameBase;
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		return m_nameBase + L"_" + toWideString(index);
Toshihiro Shimizu 890ddd
}