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]));
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
}