Blame toonz/sources/toonzlib/namebuilder.cpp
|
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 |
|
|
Shinya Kitaoka |
120a6e |
NameBuilder *NameBuilder::getBuilder(std::wstring levelName) {
|
|
Shinya Kitaoka |
120a6e |
if (levelName == L"")
|
|
Shinya Kitaoka |
120a6e |
return new NameCreator();
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return new NameModifier(levelName);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::wstring NameCreator::getNext() {
|
|
Shinya Kitaoka |
120a6e |
if (m_s.empty()) {
|
|
Shinya Kitaoka |
120a6e |
m_s.push_back(0);
|
|
Shinya Kitaoka |
120a6e |
return L"A";
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
int i = 0;
|
|
Shinya Kitaoka |
120a6e |
int n = m_s.size();
|
|
Shinya Kitaoka |
120a6e |
while (i < n) {
|
|
Shinya Kitaoka |
120a6e |
m_s[i]++;
|
|
Shinya Kitaoka |
120a6e |
if (m_s[i] <= 'Z' - 'A') break;
|
|
Shinya Kitaoka |
120a6e |
m_s[i] = 0;
|
|
Shinya Kitaoka |
120a6e |
i++;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (i >= n) {
|
|
Shinya Kitaoka |
120a6e |
n++;
|
|
Shinya Kitaoka |
120a6e |
m_s.push_back(0);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
std::wstring s;
|
|
Shinya Kitaoka |
120a6e |
for (i = n - 1; i >= 0; i--) s.append(1, (wchar_t)(L'A' + m_s[i]));
|
|
manongjohn |
e0b43c |
|
|
manongjohn |
e0b43c |
#ifdef _WIN32
|
|
manongjohn |
e0b43c |
std::vector<std::wstring> invalidNames{L"AUX", L"COM", L"CON",</std::wstring>
|
|
manongjohn |
e0b43c |
L"LPT", L"NUL", L"PRN"};
|
|
manongjohn |
e0b43c |
// If we're an invalid combination, let's check the next one
|
|
manongjohn |
e0b43c |
if (std::find(invalidNames.begin(), invalidNames.end(), s) !=
|
|
manongjohn |
e0b43c |
invalidNames.end())
|
|
manongjohn |
e0b43c |
return getNext();
|
|
manongjohn |
e0b43c |
#endif
|
|
manongjohn |
e0b43c |
|
|
Shinya Kitaoka |
120a6e |
return s;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
NameModifier::NameModifier(std::wstring name) : m_nameBase(name), m_index(0) {
|
|
Shinya Kitaoka |
120a6e |
int j = name.find_last_not_of(L"0123456789");
|
|
Shinya Kitaoka |
120a6e |
if (j != (int)std::wstring::npos && j + 1 < (int)name.length() &&
|
|
Shinya Kitaoka |
120a6e |
name[j] == '_') {
|
|
Shinya Kitaoka |
120a6e |
m_index = std::stoi(name.substr(j + 1));
|
|
Shinya Kitaoka |
120a6e |
m_nameBase = name.substr(0, j);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::wstring NameModifier::getNext() {
|
|
Shinya Kitaoka |
120a6e |
int index = m_index++;
|
|
Shinya Kitaoka |
120a6e |
if (index < 1)
|
|
Shinya Kitaoka |
120a6e |
return m_nameBase;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return m_nameBase + L"_" + std::to_wstring(index);
|
|
Toshihiro Shimizu |
890ddd |
}
|