Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
shun-iwasawa 22b8d4
// #define UNICODE  // per le funzioni di conversione da/a UNC
Toshihiro Shimizu 890ddd
#include <windows.h></windows.h>
Toshihiro Shimizu 890ddd
#include <lm.h></lm.h>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const char slash     = '\\';
Shinya Kitaoka 120a6e
const char auxslash  = '/';
Shinya Kitaoka 120a6e
const char wslash    = L'\\';
Toshihiro Shimizu 890ddd
const char wauxslash = L'/';
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
const char slash     = '/';
Shinya Kitaoka 120a6e
const char auxslash  = '\\';
Shinya Kitaoka 120a6e
const char wslash    = '/';
Toshihiro Shimizu 890ddd
const char wauxslash = '\\';
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tfilepath.h"
Toshihiro Shimizu 890ddd
#include "tconvert.h"
shun-iwasawa b5e76b
#include "tfiletype.h"
Shinya Kitaoka 9eb50d
#include <cmath></cmath>
Shinya Kitaoka 9eb50d
#include <cctype></cctype>
tomosu eea0ac
#include <sstream></sstream>
Toshihiro Shimizu 890ddd
jabarrera 96d45c
// QT
jabarrera 96d45c
#include <qobject></qobject>
shun-iwasawa ef0f8b
#include <qregexp></qregexp>
jabarrera 96d45c
Toshihiro Shimizu 890ddd
bool TFilePath::m_underscoreFormatAllowed = true;
Toshihiro Shimizu 890ddd
shun-iwasawa ef0f8b
// specifies file path condition for sequential image for each project.
shun-iwasawa ef0f8b
// See filepathproperties.h
shun-iwasawa ef0f8b
bool TFilePath::m_useStandard             = true;
shun-iwasawa ef0f8b
bool TFilePath::m_acceptNonAlphabetSuffix = false;
shun-iwasawa ef0f8b
int TFilePath::m_letterCountForSuffix     = 1;
shun-iwasawa ef0f8b
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
shun-iwasawa 443318
// Returns true if the string between the fromSeg position and the toSeg
shun-iwasawa 443318
// position is "4 digits".
Shinya Kitaoka 120a6e
bool isNumbers(std::wstring str, int fromSeg, int toSeg) {
manongjohn 4ee91c
  /*
manongjohn 4ee91c
    if (toSeg - fromSeg != 5) return false;
manongjohn 4ee91c
    for (int pos = fromSeg + 1; pos < toSeg; pos++) {
manongjohn 4ee91c
      if (str[pos] < '0' || str[pos] > '9') return false;
manongjohn 4ee91c
    }
manongjohn 4ee91c
  */
manongjohn 4ee91c
  // Let's check if it follows the format ####A (i.e 00001 or 00001a)
manongjohn 4ee91c
  int numDigits = 0, numLetters = 0;
Shinya Kitaoka 120a6e
  for (int pos = fromSeg + 1; pos < toSeg; pos++) {
manongjohn 4ee91c
    if ((str[pos] >= 'A' && str[pos] <= 'Z') ||
manongjohn 4ee91c
        (str[pos] >= 'a' && str[pos] <= 'z')) {
manongjohn 4ee91c
      // Not the right format if we ran into a letter without first finding a
manongjohn 4ee91c
      // number
manongjohn 4ee91c
      if (!numDigits) return false;
manongjohn 4ee91c
manongjohn 4ee91c
      // We'll keep track of the number of letters we find.
manongjohn 4ee91c
      // NOTE: From here on out we should only see letters
manongjohn 4ee91c
      numLetters++;
manongjohn 4ee91c
    } else if (str[pos] >= '0' && str[pos] <= '9') {
manongjohn 4ee91c
      // Not the right format if we ran into a number that followed a letter.
manongjohn 4ee91c
      // This format is not something we expect currently
manongjohn 4ee91c
      if (numLetters) return false;  // not right format
manongjohn 4ee91c
manongjohn 4ee91c
      // We'll keep track of the number of digits we find.
manongjohn 4ee91c
      numDigits++;
manongjohn 4ee91c
    } else  // Not the right format if we found something we didn't expect
manongjohn 4ee91c
      return false;
Shinya Kitaoka 120a6e
  }
manongjohn 4ee91c
manongjohn 4ee91c
  // Not the right format if we see too many letters.
manongjohn 4ee91c
  // At the time of this logic, we only expect 1 letter.  Can expand to 2 or
manongjohn 4ee91c
  // more later, if we want.
manongjohn 4ee91c
  if (numLetters > 1) return false;
manongjohn 4ee91c
manongjohn 4ee91c
  return true;  // We're good!
manongjohn 4ee91c
}
manongjohn 4ee91c
manongjohn 4ee91c
bool checkForSeqNum(QString type) {
shun-iwasawa b5e76b
  TFileType::Type typeInfo = TFileType::getInfoFromExtension(type);
shun-iwasawa b5e76b
  if ((typeInfo & TFileType::IMAGE) && !(typeInfo & TFileType::LEVEL))
shun-iwasawa b5e76b
    return true;
shun-iwasawa b5e76b
  else
manongjohn 4ee91c
    return false;
Toshihiro Shimizu 890ddd
}
shun-iwasawa b5e76b
};  // namespace
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// TFrameId::operator string() const
Shinya Kitaoka 120a6e
std::string TFrameId::expand(FrameFormat format) const {
Shinya Kitaoka 120a6e
  if (m_frame == EMPTY_FRAME)
Shinya Kitaoka 120a6e
    return "";
Shinya Kitaoka 120a6e
  else if (m_frame == NO_FRAME)
Shinya Kitaoka 120a6e
    return "-";
Shinya Kitaoka 120a6e
  std::ostringstream o_buff;
Shinya Kitaoka 120a6e
  if (format == FOUR_ZEROS || format == UNDERSCORE_FOUR_ZEROS) {
Shinya Kitaoka 120a6e
    o_buff.fill('0');
Shinya Kitaoka 120a6e
    o_buff.width(4);
Shinya Kitaoka 120a6e
    o_buff << m_frame;
Shinya Kitaoka 120a6e
    o_buff.width(0);
manongjohn 4ee91c
  } else if (format == CUSTOM_PAD || format == UNDERSCORE_CUSTOM_PAD) {
manongjohn 4ee91c
    o_buff.fill('0');
manongjohn 4ee91c
    o_buff.width(m_zeroPadding);
manongjohn 4ee91c
    o_buff << m_frame;
manongjohn 4ee91c
    o_buff.width(0);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    o_buff << m_frame;
Shinya Kitaoka 120a6e
  }
shun-iwasawa ef0f8b
  if (m_letter.isEmpty())
shun-iwasawa ef0f8b
    return o_buff.str();
shun-iwasawa ef0f8b
  else
shun-iwasawa ef0f8b
    return o_buff.str() + m_letter.toStdString();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const TFrameId &TFrameId::operator++() {
Shinya Kitaoka 120a6e
  ++m_frame;
shun-iwasawa ef0f8b
  m_letter = "";
shun-iwasawa ef0f8b
  // m_letter = 0;
Shinya Kitaoka 120a6e
  return *this;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const TFrameId &TFrameId::operator--() {
shun-iwasawa ef0f8b
  if (!m_letter.isEmpty()) m_letter = "";
shun-iwasawa ef0f8b
  // if (m_letter > 0)
shun-iwasawa ef0f8b
  //  m_letter = 0;
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    --m_frame;
Shinya Kitaoka 120a6e
  return *this;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline bool isSlash(char c) { return c == slash || c == auxslash; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline bool isSlash(wchar_t c) { return c == wslash || c == wauxslash; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// cerca l'ultimo '/' o '\'. Se non c'e' ritorna -1
Shinya Kitaoka 120a6e
// di modo che la sottostringa che parte da getLastSlash() + 1 e'
Shinya Kitaoka 120a6e
// nome.frame.tipo
Shinya Kitaoka 120a6e
inline int getLastSlash(const std::wstring &path) {
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = path.length() - 1; i >= 0 && !isSlash(path[i]); i--) {
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return i;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
void TFilePath::setPath(string path)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
bool isUncName = false;
tomosu eea0ac
  // elimino i '//', './' e '/' finali; raddrizzo gli slash 'storti'.
Toshihiro Shimizu 890ddd
  // se il path comincia con  "<alpha>:" aggiungo uno slash</alpha>
tomosu eea0ac
  int length =path.length();
Toshihiro Shimizu 890ddd
  int pos = 0;
Toshihiro Shimizu 890ddd
  if(path.length()>=2 && isalpha(path[0]) && path[1] == ':')
Toshihiro Shimizu 890ddd
    {
Toshihiro Shimizu 890ddd
     m_path.append(path,0,2);
Toshihiro Shimizu 890ddd
     pos=2;
Toshihiro Shimizu 890ddd
     if(path.length()==2 || !isSlash(path[pos])) m_path.append(1,slash);
Toshihiro Shimizu 890ddd
    }
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
  else  //se si tratta di un path in formato UNC e' del tipo "\\\\MachineName"
Shinya Kitaoka 120a6e
        //RICONTROLLARE! SE SI HA IP ADDRESS FALLIVA!
Shinya Kitaoka 120a6e
    if (path.length() >= 3 && path[0] == '\\' &&  path[1] == '\\' &&
Shinya Kitaoka 120a6e
(isalpha(path[2]) || isdigit(path[2])) )
Toshihiro Shimizu 890ddd
      {
Toshihiro Shimizu 890ddd
      isUncName = true;
Toshihiro Shimizu 890ddd
      m_path.append(path,0,3);
Toshihiro Shimizu 890ddd
      pos = 3;
Toshihiro Shimizu 890ddd
      }
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
  for(;pos
Toshihiro Shimizu 890ddd
    if(path[pos] == '.')
Toshihiro Shimizu 890ddd
    {
Toshihiro Shimizu 890ddd
      pos++;
tomosu eea0ac
      if(pos>=length)
Toshihiro Shimizu 890ddd
      {
Toshihiro Shimizu 890ddd
        if(pos>1) m_path.append(1,'.');
Toshihiro Shimizu 890ddd
      }
Toshihiro Shimizu 890ddd
      else if(!isSlash(path[pos])) m_path.append(path,pos-1,2);
Toshihiro Shimizu 890ddd
      else {
tomosu eea0ac
         while(pos+1
Toshihiro Shimizu 890ddd
           pos++;
Toshihiro Shimizu 890ddd
      }
Toshihiro Shimizu 890ddd
    }
Toshihiro Shimizu 890ddd
    else if(isSlash(path[pos]))
Toshihiro Shimizu 890ddd
    {
Toshihiro Shimizu 890ddd
      do pos++;
Toshihiro Shimizu 890ddd
      while(pos
Toshihiro Shimizu 890ddd
      pos--;
Toshihiro Shimizu 890ddd
      m_path.append(1,slash);
Toshihiro Shimizu 890ddd
    }
Toshihiro Shimizu 890ddd
    else
Toshihiro Shimizu 890ddd
    {
Toshihiro Shimizu 890ddd
      m_path.append(1,path[pos]);
Toshihiro Shimizu 890ddd
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    // rimuovo l'eventuale '/' finale (a meno che m_path == "/" o m_path ==
Shinya Kitaoka 120a6e
"<letter>:\"</letter>
Toshihiro Shimizu 890ddd
    // oppure sia UNC (Windows only) )
Toshihiro Shimizu 890ddd
    if(!(m_path.length()==1 && m_path[0] == slash ||
Shinya Kitaoka 120a6e
         m_path.length()==3 && isalpha(m_path[0]) && m_path[1] == ':' &&
Shinya Kitaoka 120a6e
m_path[2] == slash)
Toshihiro Shimizu 890ddd
      && m_path.length()>1 && m_path[m_path.length()-1] == slash)
Toshihiro Shimizu 890ddd
      m_path.erase(m_path.length()-1, 1);
tomosu eea0ac
Shinya Kitaoka 120a6e
  if (isUncName && m_path.find_last_of('\\') == 1) // e' indicato solo il nome
Shinya Kitaoka 120a6e
della macchina...
Toshihiro Shimizu 890ddd
    m_path.append(1, slash);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
void append(string &out, wchar_t c)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
  if(32 <= c && c<=127 && c!='&') out.append(1, (char)c);
Toshihiro Shimizu 890ddd
  else if(c=='&') out.append("&");
tomosu eea0ac
  else
Toshihiro Shimizu 890ddd
    {
tomosu eea0ac
     ostringstream ss;
Toshihiro Shimizu 890ddd
     ss << "&#" <<  c << ";" << '\0';
Toshihiro Shimizu 890ddd
     out += ss.str();
Toshihiro Shimizu 890ddd
     ss.freeze(0);
Toshihiro Shimizu 890ddd
    }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFilePath::setPath(std::wstring path) {
Shinya Kitaoka 120a6e
  bool isUncName = false;
Shinya Kitaoka 120a6e
  // elimino i '//', './' e '/' finali; raddrizzo gli slash 'storti'.
Shinya Kitaoka 120a6e
  // se il path comincia con  "<alpha>:" aggiungo uno slash</alpha>
Shinya Kitaoka 120a6e
  int length = path.length();
Shinya Kitaoka 120a6e
  int pos    = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (path.length() >= 2 && iswalpha(path[0]) && path[1] == L':') {
Shinya Kitaoka 120a6e
    m_path.append(1, (wchar_t)path[0]);
Shinya Kitaoka 120a6e
    m_path.append(1, L':');
Shinya Kitaoka 120a6e
    // m_path.append(path,0,2);
Shinya Kitaoka 120a6e
    pos = 2;
Shinya Kitaoka 120a6e
    if (path.length() == 2 || !isSlash(path[pos])) m_path.append(1, wslash);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  // se si tratta di un path in formato UNC e' del tipo "\\\\MachineName"
Rozhuk Ivan 823a31
  else if ((path.length() >= 3 && path[0] == L'\\' && path[1] == L'\\' &&
shun-iwasawa ef0f8b
            iswalnum(path[2])) ||
Rozhuk Ivan 823a31
           (path.length() >= 3 && path[0] == L'/' && path[1] == L'/' &&
shun-iwasawa ef0f8b
            iswalnum(path[2]))) {
Shinya Kitaoka 120a6e
    isUncName = true;
Shinya Kitaoka 120a6e
    m_path.append(2, L'\\');
Shinya Kitaoka 120a6e
    m_path.append(1, path[2]);
Shinya Kitaoka 120a6e
    pos = 3;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  for (; pos < length; pos++)
Shinya Kitaoka 120a6e
    if (path[pos] == L'.') {
Shinya Kitaoka 120a6e
      pos++;
Shinya Kitaoka 120a6e
      if (pos >= length) {
Shinya Kitaoka 120a6e
        if (pos > 1) m_path.append(1, L'.');
Shinya Kitaoka 120a6e
      } else if (!isSlash(path[pos])) {
Shinya Kitaoka 120a6e
        m_path.append(1, L'.');
Shinya Kitaoka 120a6e
        m_path.append(1, path[pos]);
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        while (pos + 1 < length && isSlash(path[pos + 1])) pos++;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else if (isSlash(path[pos])) {
Shinya Kitaoka 120a6e
      int firstSlashPos = pos;
shun-iwasawa 22b8d4
      do pos++;
Shinya Kitaoka 120a6e
      while (pos < length && isSlash(path[pos]));
Shinya Kitaoka 120a6e
      if (firstSlashPos == 0 && pos == 4)  // Caso "\\\\MachineName"
Shinya Kitaoka 120a6e
        m_path.append(2, wslash);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        m_path.append(1, wslash);
Shinya Kitaoka 120a6e
      pos--;
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      m_path.append(1, path[pos]);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // rimuovo l'eventuale '/' finale (a meno che m_path == "/" o m_path ==
Shinya Kitaoka 120a6e
  // "<letter>:\"</letter>
Shinya Kitaoka 120a6e
  // oppure sia UNC (Windows only) )
Rozhuk Ivan 823a31
  if (!((m_path.length() == 1 && m_path[0] == wslash) ||
Rozhuk Ivan 823a31
        (m_path.length() == 3 && iswalpha(m_path[0]) && m_path[1] == L':' &&
shun-iwasawa ef0f8b
         m_path[2] == wslash)) &&
Rozhuk Ivan 823a31
      (m_path.length() > 1 && m_path[m_path.length() - 1] == wslash))
Shinya Kitaoka 120a6e
    m_path.erase(m_path.length() - 1, 1);
Shinya Kitaoka 120a6e
shun-iwasawa ef0f8b
  if (isUncName && !(m_path.find_last_of(L'\\') > 1 ||
shun-iwasawa ef0f8b
                     m_path.find_last_of(L'/') >
shun-iwasawa ef0f8b
                         1))  // e' indicato solo il nome della macchina...
Shinya Kitaoka 120a6e
    m_path.append(1, wslash);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath::TFilePath(const char *path) { setPath(::to_wstring(path)); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath::TFilePath(const std::string &path) { setPath(::to_wstring(path)); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath::TFilePath(const std::wstring &path) { setPath(path); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath::TFilePath(const QString &path) { setPath(path.toStdWString()); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
bool TFilePath::operator==(const TFilePath &fp) const {
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Shinya Kitaoka 120a6e
  return _wcsicmp(m_path.c_str(), fp.m_path.c_str()) == 0;
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  return m_path == fp.m_path;
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TFilePath::operator<(const TFilePath &fp) const {
Shinya Kitaoka 120a6e
  std::wstring iName = m_path;
Shinya Kitaoka 120a6e
  std::wstring jName = fp.m_path;
Shinya Kitaoka 120a6e
  int i1 = 0, j1 = 0;
Shinya Kitaoka 120a6e
  int i2 = m_path.find(L"\\");
Shinya Kitaoka 120a6e
  int j2 = fp.m_path.find(L"\\");
Shinya Kitaoka 120a6e
  if (i2 == j2 && j2 == -1)
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Shinya Kitaoka 120a6e
    return _wcsicmp(m_path.c_str(), fp.m_path.c_str()) < 0;
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
    return m_path < fp.m_path;
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
  if (!i2) {
Shinya Kitaoka 120a6e
    ++i1;
Shinya Kitaoka 120a6e
    i2 = m_path.find(L"\\", i1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (!j2) {
Shinya Kitaoka 120a6e
    ++j1;
Shinya Kitaoka 120a6e
    j2 = fp.m_path.find(L"\\", j1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  while (i2 != -1 || j2 != -1) {
Shinya Kitaoka 120a6e
    iName = (i2 != -1) ? m_path.substr(i1, i2 - i1) : m_path;
Shinya Kitaoka 120a6e
    jName = (j2 != -1) ? fp.m_path.substr(j1, j2 - j1) : fp.m_path;
Shinya Kitaoka 120a6e
// se le due parti di path, conpresi tra slash sono uguali
Shinya Kitaoka 120a6e
// itero il processo di confronto altrimenti ritorno
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Shinya Kitaoka 120a6e
    char differ;
Shinya Kitaoka 120a6e
    differ = _wcsicmp(iName.c_str(), jName.c_str());
Shinya Kitaoka 120a6e
    if (differ != 0) return differ < 0 ? true : false;
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
    if (TFilePath(iName) != TFilePath(jName))
Shinya Kitaoka 120a6e
      return TFilePath(iName) < TFilePath(jName);
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    i1 = (i2 != -1) ? i2 + 1 : m_path.size();
Shinya Kitaoka 120a6e
    j1 = (j2 != -1) ? j2 + 1 : fp.m_path.size();
Shinya Kitaoka 120a6e
    i2 = m_path.find(L"\\", i1);
Shinya Kitaoka 120a6e
    j2 = fp.m_path.find(L"\\", j1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  iName = m_path.substr(i1, m_path.size() - i1);
Shinya Kitaoka 120a6e
  jName = fp.m_path.substr(j1, fp.m_path.size() - j1);
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Shinya Kitaoka 120a6e
  return _wcsicmp(iName.c_str(), jName.c_str()) < 0;
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  return TFilePath(iName) < TFilePath(jName);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef LEVO
Shinya Kitaoka 120a6e
bool TFilePath::operator<(const TFilePath &fp) const {
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
wstring a = m_path, b = fp.m_path;
Shinya Kitaoka 120a6e
for(;;)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
wstring ka,kb;
Shinya Kitaoka 120a6e
int i;
Shinya Kitaoka 120a6e
i = a.find_first_of("/\\");
Shinya Kitaoka 120a6e
if(i==wstring::npos) {ka = a; a = L"";}
Shinya Kitaoka 120a6e
i = b.find_first_of("/\\");
Shinya Kitaoka 120a6e
if(i==wstring::npos) {ka = a; a = L"";}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
  wstring a = toLower(m_path), b = toLower(fp.m_path);
Shinya Kitaoka 120a6e
  return a < b;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath &TFilePath::operator+=(const TFilePath &fp) {
Shinya Kitaoka 120a6e
  assert(!fp.isAbsolute());
Shinya Kitaoka 120a6e
  if (fp.isEmpty())
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  else if (isEmpty()) {
Shinya Kitaoka 120a6e
    *this = fp;
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  } else if (m_path.length() != 1 || m_path[0] != slash) {
Shinya Kitaoka 120a6e
    assert(!m_path.empty());
Shinya Kitaoka 120a6e
    if (!isSlash(m_path[m_path.length() - 1])) m_path.append(1, wslash);
Shinya Kitaoka 120a6e
    m_path += fp.m_path;
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    *this = TFilePath(m_path + fp.m_path);
Shinya Kitaoka 120a6e
    return *this;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
TFilePath TFilePath::operator+(const TFilePath &fp) const {
Shinya Kitaoka 120a6e
  TFilePath ret(*this);
Shinya Kitaoka 120a6e
  ret += fp;
Shinya Kitaoka 120a6e
  return ret;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath &TFilePath::operator+=(const std::wstring &s) {
Shinya Kitaoka 120a6e
  if (s.empty()) return *this;
Shinya Kitaoka 120a6e
  // if(m_path.length()!=1 || m_path[0] != slash)
Shinya Kitaoka 120a6e
  //  m_path += slash;
Shinya Kitaoka 120a6e
  if (m_path.length() > 0 && !isSlash(m_path[m_path.length() - 1]))
Shinya Kitaoka 120a6e
    m_path.append(1, wslash);
Shinya Kitaoka 120a6e
  m_path += s;
Shinya Kitaoka 120a6e
  return *this;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
const std::wstring TFilePath::getWideString() const {
Shinya Kitaoka 120a6e
  return m_path;
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
std::wstring s;
Shinya Kitaoka 120a6e
int n = m_path.size();
Shinya Kitaoka 120a6e
for(int i=0;i
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
char c = m_path[i];
Shinya Kitaoka 120a6e
if(c!='&') s.append(1, (unsigned short)c);
Shinya Kitaoka 120a6e
else
Shinya Kitaoka 120a6e
 {
Shinya Kitaoka 120a6e
  i++;
Shinya Kitaoka 120a6e
  if(m_path[i] == '#')
Toshihiro Shimizu 890ddd
    {
Shinya Kitaoka 120a6e
     unsigned short w = 0;
Shinya Kitaoka 120a6e
     i++;
Shinya Kitaoka 120a6e
     while(i
Toshihiro Shimizu 890ddd
       {
Shinya Kitaoka 120a6e
        c = m_path[i];
Shinya Kitaoka 120a6e
        if('0'<=c && c<='9')
Shinya Kitaoka 120a6e
          w = w*10 + c - '0';
Shinya Kitaoka 120a6e
        else if('a' <=c && c<='f')
Shinya Kitaoka 120a6e
          w = w*10 + c - 'a' + 10;
Shinya Kitaoka 120a6e
        else if('A' <=c && c<='F')
Shinya Kitaoka 120a6e
          w = w*10 + c - 'A' + 10;
Shinya Kitaoka 120a6e
        else
Shinya Kitaoka 120a6e
          break;
Toshihiro Shimizu 890ddd
        i++;
Toshihiro Shimizu 890ddd
       }
Shinya Kitaoka 120a6e
     s.append(1, w);
Toshihiro Shimizu 890ddd
    }
Shinya Kitaoka 120a6e
 }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
return s;
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
const wstring TFilePath::getWideString() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
   wstring a(L"dummy string");
Toshihiro Shimizu 890ddd
   return a;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString TFilePath::getQString() const {
Shinya Kitaoka 120a6e
  return QString::fromStdWString(getWideString());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
std::ostream &operator<<(std::ostream &out, const TFilePath &path) {
Shinya Kitaoka 120a6e
  std::wstring w = path.getWideString();
Shinya Kitaoka 120a6e
  return out << ::to_string(w) << " ";
Shinya Kitaoka 120a6e
  //  string w = path.getString();
Shinya Kitaoka 120a6e
  //  return out << w << " ";
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
TFilePath TFilePath::operator+ (const TFilePath &fp) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
assert(!fp.isAbsolute());
Toshihiro Shimizu 890ddd
if(fp.isEmpty()) return *this;
Toshihiro Shimizu 890ddd
else if(isEmpty()) return fp;
tomosu eea0ac
else if(m_path.length()!=1 || m_path[0] != slash)
Toshihiro Shimizu 890ddd
  return TFilePath(m_path + slash + fp.m_path);
tomosu eea0ac
else
Toshihiro Shimizu 890ddd
  return TFilePath(m_path + fp.m_path);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TFilePath::isAbsolute() const {
Rozhuk Ivan 823a31
  return ((m_path.length() >= 1 && m_path[0] == slash) ||
Rozhuk Ivan 823a31
          (m_path.length() >= 2 && iswalpha(m_path[0]) && m_path[1] == ':'));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TFilePath::isRoot() const {
Rozhuk Ivan 823a31
  return ((m_path.length() == 1 && m_path[0] == slash) ||
Rozhuk Ivan 823a31
          (m_path.length() == 3 && iswalpha(m_path[0]) && m_path[1] == ':' &&
shun-iwasawa ef0f8b
           m_path[2] == slash) ||
Rozhuk Ivan 823a31
          ((m_path.length() > 2 && m_path[0] == slash && m_path[1] == slash) &&
shun-iwasawa ef0f8b
           (std::string::npos == m_path.find(slash, 2) ||
shun-iwasawa ef0f8b
            m_path.find(slash, 2) == (m_path.size() - 1))));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// ritorna ""(niente tipo, niente punto), "." (file con tipo) o ".." (file con
Shinya Kitaoka 120a6e
// tipo e frame)
Shinya Kitaoka 120a6e
std::string TFilePath::getDots() const {
shun-iwasawa ef0f8b
  if (!TFilePath::m_useStandard) {
shun-iwasawa ef0f8b
    TFilePathInfo info = analyzePath();
shun-iwasawa ef0f8b
    if (info.extension.isEmpty()) return "";
shun-iwasawa ef0f8b
    if (info.sepChar.isNull()) return ".";
shun-iwasawa ef0f8b
    // return ".." regardless of sepChar type (either "_" or ".")
shun-iwasawa ef0f8b
    return "..";
shun-iwasawa ef0f8b
  }
shun-iwasawa ef0f8b
  //-----
shun-iwasawa ef0f8b
manongjohn 4ee91c
  QString type = QString::fromStdString(getType()).toLower();
Jeremy Bullock d8339e
  if (isFfmpegType()) return ".";
Shinya Kitaoka 120a6e
  int i            = getLastSlash(m_path);
Shinya Kitaoka 120a6e
  std::wstring str = m_path.substr(i + 1);
Shinya Kitaoka 120a6e
  // potrei anche avere a.b.c.d dove d e' l'estensione
Shinya Kitaoka 120a6e
  i = str.rfind(L".");
Shinya Kitaoka 120a6e
  if (i == (int)std::wstring::npos || str == L"..") return "";
Toshihiro Shimizu 890ddd
manongjohn 4ee91c
  int j = str.substr(0, i).rfind(L".");
manongjohn 4ee91c
  if (j == (int)std::wstring::npos && m_underscoreFormatAllowed)
manongjohn 4ee91c
    j = str.substr(0, i).rfind(L"_");
manongjohn 4ee91c
manongjohn 4ee91c
  if (j != (int)std::wstring::npos)
manongjohn 4ee91c
    return (j == i - 1 || (checkForSeqNum(type) && isNumbers(str, j, i))) ? ".."
manongjohn 4ee91c
                                                                          : ".";
manongjohn 4ee91c
  else
Shinya Kitaoka 120a6e
    return ".";
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa fc0d80
QChar TFilePath::getSepChar() const {
shun-iwasawa fc0d80
  if (!TFilePath::m_useStandard) return analyzePath().sepChar;
shun-iwasawa fc0d80
  //-----
shun-iwasawa fc0d80
  QString type = QString::fromStdString(getType()).toLower();
shun-iwasawa fc0d80
  if (isFfmpegType()) return QChar();
shun-iwasawa fc0d80
  int i            = getLastSlash(m_path);
shun-iwasawa fc0d80
  std::wstring str = m_path.substr(i + 1);
shun-iwasawa fc0d80
  // potrei anche avere a.b.c.d dove d e' l'estensione
shun-iwasawa fc0d80
  i = str.rfind(L".");
shun-iwasawa fc0d80
  if (i == (int)std::wstring::npos || str == L"..") return QChar();
shun-iwasawa fc0d80
shun-iwasawa fc0d80
  int j = str.substr(0, i).rfind(L".");
shun-iwasawa fc0d80
shun-iwasawa fc0d80
  if (j != (int)std::wstring::npos)
shun-iwasawa fc0d80
    return (j == i - 1 || (checkForSeqNum(type) && isNumbers(str, j, i)))
shun-iwasawa fc0d80
               ? QChar('.')
shun-iwasawa fc0d80
               : QChar();
shun-iwasawa fc0d80
  if (!m_underscoreFormatAllowed) return QChar();
shun-iwasawa fc0d80
shun-iwasawa fc0d80
  j = str.substr(0, i).rfind(L"_");
shun-iwasawa fc0d80
  if (j != (int)std::wstring::npos)
shun-iwasawa fc0d80
    return (j == i - 1 || (checkForSeqNum(type) && isNumbers(str, j, i)))
shun-iwasawa fc0d80
               ? QChar('_')
shun-iwasawa fc0d80
               : QChar();
shun-iwasawa fc0d80
  else
shun-iwasawa fc0d80
    return QChar();
shun-iwasawa fc0d80
}
shun-iwasawa fc0d80
shun-iwasawa fc0d80
//-----------------------------------------------------------------------------
shun-iwasawa fc0d80
Shinya Kitaoka 120a6e
std::string TFilePath::getDottedType()
Shinya Kitaoka 120a6e
    const  // ritorna l'estensione con PUNTO (se c'e')
Toshihiro Shimizu 890ddd
{
shun-iwasawa ef0f8b
  if (!TFilePath::m_useStandard) {
shun-iwasawa ef0f8b
    QString ext = analyzePath().extension;
shun-iwasawa ef0f8b
    if (ext.isEmpty()) return "";
shun-iwasawa ef0f8b
    return "." + ext.toLower().toStdString();
shun-iwasawa ef0f8b
  }
shun-iwasawa ef0f8b
Shinya Kitaoka 120a6e
  int i            = getLastSlash(m_path);
Shinya Kitaoka 120a6e
  std::wstring str = m_path.substr(i + 1);
Shinya Kitaoka 120a6e
  i                = str.rfind(L".");
Shinya Kitaoka 120a6e
  if (i == (int)std::wstring::npos) return "";
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return toLower(::to_string(str.substr(i)));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
std::string TFilePath::getUndottedType()
Shinya Kitaoka 120a6e
    const  // ritorna l'estensione senza PUNTO
Toshihiro Shimizu 890ddd
{
shun-iwasawa ef0f8b
  if (!TFilePath::m_useStandard) {
shun-iwasawa ef0f8b
    QString ext = analyzePath().extension;
shun-iwasawa ef0f8b
    if (ext.isEmpty())
shun-iwasawa ef0f8b
      return "";
shun-iwasawa ef0f8b
    else
shun-iwasawa ef0f8b
      return ext.toLower().toStdString();
shun-iwasawa ef0f8b
  }
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
  //-----
Shinya Kitaoka 120a6e
  size_t i         = getLastSlash(m_path);
Shinya Kitaoka 120a6e
  std::wstring str = m_path.substr(i + 1);
Shinya Kitaoka 120a6e
  i                = str.rfind(L".");
Shinya Kitaoka 120a6e
  if (i == std::wstring::npos || i == str.length() - 1) return "";
Shinya Kitaoka 120a6e
  return toLower(::to_string(str.substr(i + 1)));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
std::wstring TFilePath::getWideName() const  // noDot! noSlash!
Toshihiro Shimizu 890ddd
{
shun-iwasawa ef0f8b
  if (!TFilePath::m_useStandard) {
shun-iwasawa ef0f8b
    return analyzePath().levelName.toStdWString();
shun-iwasawa ef0f8b
  }
shun-iwasawa ef0f8b
  //-----
shun-iwasawa ef0f8b
manongjohn 4ee91c
  QString type     = QString::fromStdString(getType()).toLower();
Shinya Kitaoka 38fd86
  int i            = getLastSlash(m_path);  // cerco l'ultimo slash
Shinya Kitaoka 120a6e
  std::wstring str = m_path.substr(i + 1);
Shinya Kitaoka 120a6e
  i                = str.rfind(L".");
Shinya Kitaoka 120a6e
  if (i == (int)std::wstring::npos) return str;
Shinya Kitaoka 120a6e
  int j = str.substr(0, i).rfind(L".");
manongjohn 4ee91c
  if (j != (int)std::wstring::npos) {
manongjohn 4ee91c
    if (checkForSeqNum(type) && isNumbers(str, j, i)) i = j;
manongjohn 4ee91c
  } else if (m_underscoreFormatAllowed) {
Shinya Kitaoka 120a6e
    j = str.substr(0, i).rfind(L"_");
manongjohn 4ee91c
    if (j != (int)std::wstring::npos && checkForSeqNum(type) &&
manongjohn 4ee91c
        isNumbers(str, j, i))
manongjohn 4ee91c
      i = j;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return str.substr(0, i);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
std::string TFilePath::getName() const  // noDot! noSlash!
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
  return ::to_string(getWideName());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
// es. TFilePath("/pippo/pluto.0001.gif").getLevelName() == "pluto..gif"
Shinya Kitaoka 120a6e
std::string TFilePath::getLevelName() const {
Shinya Kitaoka 120a6e
  return ::to_string(getLevelNameW());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Martin van Zijl 4e3671
// es. TFilePath("/pippo/pluto.0001.gif").getLevelName() == "pluto..gif"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
std::wstring TFilePath::getLevelNameW() const {
shun-iwasawa ef0f8b
  if (!TFilePath::m_useStandard) {
shun-iwasawa ef0f8b
    TFilePathInfo info = analyzePath();
shun-iwasawa ef0f8b
    if (info.extension.isEmpty()) return info.levelName.toStdWString();
shun-iwasawa ef0f8b
    QString name = info.levelName;
shun-iwasawa ef0f8b
    if (!info.sepChar.isNull()) name += info.sepChar;
shun-iwasawa ef0f8b
    name += "." + info.extension;
shun-iwasawa ef0f8b
    return name.toStdWString();
shun-iwasawa ef0f8b
  }
shun-iwasawa ef0f8b
  //-----
shun-iwasawa ef0f8b
Shinya Kitaoka 38fd86
  int i            = getLastSlash(m_path);  // cerco l'ultimo slash
Shinya Kitaoka 120a6e
  std::wstring str = m_path.substr(i + 1);  // str e' m_path senza directory
manongjohn 4ee91c
  QString type     = QString::fromStdString(getType()).toLower();
Jeremy Bullock d8339e
  if (isFfmpegType()) return str;
Shinya Kitaoka 120a6e
  int j = str.rfind(L".");                       // str[j..] = ".type"
Shinya Kitaoka 120a6e
  if (j == (int)std::wstring::npos) return str;  // no frame; no type
Shinya Kitaoka 120a6e
  i = str.substr(0, j).rfind(L'.');
Shinya Kitaoka 120a6e
  if (i == (int)std::wstring::npos && m_underscoreFormatAllowed)
Shinya Kitaoka 120a6e
    i = str.substr(0, j).rfind(L'_');
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (j == i || j - i == 1)  // prova.tif o prova..tif
Shinya Kitaoka 120a6e
    return str;
Toshihiro Shimizu 890ddd
Martin van Zijl 4e3671
  if (!checkForSeqNum(type) || !isNumbers(str, i, j) ||
shun-iwasawa ef0f8b
      i == (int)std::wstring::npos)
shun-iwasawa ef0f8b
    return str;
Shinya Kitaoka 120a6e
  // prova.0001.tif
Shinya Kitaoka 120a6e
  return str.erase(i + 1, j - i - 1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath TFilePath::getParentDir() const  // noSlash!
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
  int i = getLastSlash(m_path);  // cerco l'ultimo slash
Shinya Kitaoka 120a6e
  if (i < 0) {
shun-iwasawa ef0f8b
    if (m_path.length() >= 2 &&
shun-iwasawa ef0f8b
        (('a' <= m_path[0] && m_path[0] <= 'z') ||
shun-iwasawa ef0f8b
         ('A' <= m_path[0] && m_path[0] <= 'Z')) &&
Shinya Kitaoka 120a6e
        m_path[1] == ':')
Shinya Kitaoka 120a6e
      return TFilePath(m_path.substr(0, 2));
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      return TFilePath("");
Shinya Kitaoka 120a6e
  } else if (i == 0)
Shinya Kitaoka 120a6e
    return TFilePath("/");
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return TFilePath(m_path.substr(0, i));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
shun-iwasawa ef0f8b
// return true if the fID is EMPTY_FRAME
Shinya Kitaoka 120a6e
bool TFilePath::isLevelName() const {
shun-iwasawa ef0f8b
  if (!TFilePath::m_useStandard) {
shun-iwasawa ef0f8b
    return analyzePath().fId.getNumber() == TFrameId::EMPTY_FRAME;
shun-iwasawa ef0f8b
  }
shun-iwasawa ef0f8b
  //-----
shun-iwasawa ef0f8b
manongjohn 4ee91c
  QString type = QString::fromStdString(getType()).toLower();
manongjohn 4ee91c
  if (isFfmpegType() || !checkForSeqNum(type)) return false;
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    return getFrame() == TFrameId(TFrameId::EMPTY_FRAME);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  catch (...) {
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFrameId TFilePath::getFrame() const {
shun-iwasawa ef0f8b
  if (!TFilePath::m_useStandard) {
shun-iwasawa ef0f8b
    return analyzePath().fId;
shun-iwasawa ef0f8b
  }
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
  //-----
Shinya Kitaoka 38fd86
  int i            = getLastSlash(m_path);  // cerco l'ultimo slash
Shinya Kitaoka 120a6e
  std::wstring str = m_path.substr(i + 1);  // str e' il path senza parentdir
manongjohn 4ee91c
  QString type     = QString::fromStdString(getType()).toLower();
Shinya Kitaoka 120a6e
  i                = str.rfind(L'.');
Shinya Kitaoka 120a6e
  if (i == (int)std::wstring::npos || str == L"." || str == L"..")
Shinya Kitaoka 120a6e
    return TFrameId(TFrameId::NO_FRAME);
Shinya Kitaoka 120a6e
  int j;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  j = str.substr(0, i).rfind(L'.');
Shinya Kitaoka 120a6e
  if (j == (int)std::wstring::npos && m_underscoreFormatAllowed)
Shinya Kitaoka 120a6e
    j = str.substr(0, i).rfind(L'_');
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (j == (int)std::wstring::npos) return TFrameId(TFrameId::NO_FRAME);
Shinya Kitaoka 120a6e
  if (i == j + 1) return TFrameId(TFrameId::EMPTY_FRAME);
Toshihiro Shimizu 890ddd
shun-iwasawa 443318
  // Exclude cases with non-numeric characters inbetween. (In case the file name
shun-iwasawa 443318
  // contains "_" or ".")
manongjohn 4ee91c
  if (!checkForSeqNum(type) || !isNumbers(str, j, i))
manongjohn 4ee91c
    return TFrameId(TFrameId::NO_FRAME);
Toshihiro Shimizu 890ddd
manongjohn 4ee91c
  int k, number = 0, digits = 0;
manongjohn 4ee91c
  for (k = j + 1; k < i && iswdigit(str[k]); k++) {
manongjohn 4ee91c
    digits++;
manongjohn 4ee91c
    number = number * 10 + str[k] - L'0';
manongjohn 4ee91c
  }
shun-iwasawa ef0f8b
  char letter = '\0';
Shinya Kitaoka 120a6e
  if (iswalpha(str[k])) letter = str[k++] + ('a' - L'a');
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
  //  if (number == 0 || k < i)  // || letter!='\0')
shun-iwasawa ef0f8b
  //    throw TMalformedFrameException(
shun-iwasawa ef0f8b
  //        *this,
shun-iwasawa ef0f8b
  //        str + L": " + QObject::tr("Malformed frame name").toStdWString());
manongjohn 4ee91c
  int padding = 0;
manongjohn 4ee91c
manongjohn 4ee91c
  if (str[j + 1] == '0') padding = digits;
manongjohn 4ee91c
manongjohn 4ee91c
  return TFrameId(number, letter, padding, str[j]);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Jeremy Bullock d8339e
bool TFilePath::isFfmpegType() const {
Jeremy Bullock d8339e
  QString type = QString::fromStdString(getType()).toLower();
justburner b375f4
  return (type == "gif" || type == "mp4" || type == "webm");
justburner b375f4
}
justburner b375f4
justburner b375f4
//-----------------------------------------------------------------------------
justburner b375f4
justburner b375f4
bool TFilePath::isUneditable() const {
justburner b375f4
  QString type = QString::fromStdString(getType()).toLower();
justburner b375f4
  return (type == "psd" || type == "gif" || type == "mp4" || type == "webm");
Jeremy Bullock d8339e
}
Jeremy Bullock d8339e
Jeremy Bullock d8339e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
TFilePath TFilePath::withType(const std::string &type) const {
Shinya Kitaoka 120a6e
  assert(type.length() < 2 || type.substr(0, 2) != "..");
Shinya Kitaoka 38fd86
  int i            = getLastSlash(m_path);  // cerco l'ultimo slash
Shinya Kitaoka 120a6e
  std::wstring str = m_path.substr(i + 1);  // str e' il path senza parentdir
Shinya Kitaoka 120a6e
  int j            = str.rfind(L'.');
Shinya Kitaoka 120a6e
  if (j == (int)std::wstring::npos || str == L"..")
Shinya Kitaoka 120a6e
  // il path originale non ha tipo
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    if (type == "")
Shinya Kitaoka 120a6e
      return *this;
Shinya Kitaoka 120a6e
    else if (type[0] == '.')
Shinya Kitaoka 120a6e
      return TFilePath(m_path + ::to_wstring(type));
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      return TFilePath(m_path + ::to_wstring("." + type));
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
  // il path originale ha gia' il tipo
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    if (type == "")
Shinya Kitaoka 120a6e
      return TFilePath(m_path.substr(0, i + j + 1));
Shinya Kitaoka 120a6e
    else if (type[0] == '.')
Shinya Kitaoka 120a6e
      return TFilePath(m_path.substr(0, i + j + 1) + ::to_wstring(type));
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      return TFilePath(m_path.substr(0, i + j + 2) + ::to_wstring(type));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath TFilePath::withName(const std::string &name) const {
Shinya Kitaoka 120a6e
  return withName(::to_wstring(name));
Shinya Kitaoka 120a6e
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TFilePath TFilePath::withName(const std::wstring &name) const {
shun-iwasawa ef0f8b
  if (!TFilePath::m_useStandard) {
shun-iwasawa ef0f8b
    TFilePathInfo info = analyzePath();
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
    QString ret = info.parentDir + QString::fromStdWString(name);
shun-iwasawa ef0f8b
    if (info.fId.getNumber() != TFrameId::NO_FRAME) {
shun-iwasawa ef0f8b
      QString sepChar = (info.sepChar.isNull()) ? "." : QString(info.sepChar);
shun-iwasawa ef0f8b
      ret += sepChar + QString::fromStdString(
shun-iwasawa ef0f8b
                           info.fId.expand(info.fId.getCurrentFormat()));
shun-iwasawa ef0f8b
    }
shun-iwasawa ef0f8b
    if (!info.extension.isEmpty()) ret += "." + info.extension;
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
    return TFilePath(ret);
shun-iwasawa ef0f8b
  }
shun-iwasawa ef0f8b
Shinya Kitaoka 38fd86
  int i            = getLastSlash(m_path);  // cerco l'ultimo slash
Shinya Kitaoka 120a6e
  std::wstring str = m_path.substr(i + 1);  // str e' il path senza parentdir
manongjohn 4ee91c
  QString type     = QString::fromStdString(getType()).toLower();
Shinya Kitaoka 120a6e
  int j;
Shinya Kitaoka 120a6e
  j = str.rfind(L'.');
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (j == (int)std::wstring::npos) {
Shinya Kitaoka 120a6e
    if (m_underscoreFormatAllowed) {
Shinya Kitaoka 120a6e
      j = str.rfind(L'_');
Shinya Kitaoka 120a6e
      if (j != (int)std::wstring::npos)
Shinya Kitaoka 120a6e
        return TFilePath(m_path.substr(0, i + 1) + name + str.substr(j));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    return TFilePath(m_path.substr(0, i + 1) + name);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  int k;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  k = str.substr(0, j).rfind(L".");
Shinya Kitaoka 120a6e
  if (k == (int)std::wstring::npos && m_underscoreFormatAllowed)
Shinya Kitaoka 120a6e
    k = str.substr(0, j).rfind(L"_");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (k == (int)(std::wstring::npos))
Shinya Kitaoka 120a6e
    k = j;
manongjohn 4ee91c
  else if (k != j - 1 && (!checkForSeqNum(type) || !isNumbers(str, k, j)))
Shinya Kitaoka 120a6e
    k = j;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return TFilePath(m_path.substr(0, i + 1) + name + str.substr(k));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath TFilePath::withParentDir(const TFilePath &dir) const {
Shinya Kitaoka 120a6e
  int i = getLastSlash(m_path);  // cerco l'ultimo slash
Shinya Kitaoka 120a6e
  return dir + TFilePath(m_path.substr(i + 1));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath TFilePath::withFrame(const TFrameId &frame,
Shinya Kitaoka 120a6e
                               TFrameId::FrameFormat format) const {
shun-iwasawa ef0f8b
  if (!TFilePath::m_useStandard) {
shun-iwasawa ef0f8b
    TFilePathInfo info = analyzePath();
shun-iwasawa ef0f8b
    // Override format input because it may be wrong.
shun-iwasawa ef0f8b
    if (checkForSeqNum(info.extension)) format = frame.getCurrentFormat();
shun-iwasawa ef0f8b
    // override format if the original fid is available
shun-iwasawa ef0f8b
    else if (info.fId.getNumber() != TFrameId::NO_FRAME)
shun-iwasawa ef0f8b
      format = info.fId.getCurrentFormat();
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
    if (info.extension.isEmpty()) {
shun-iwasawa ef0f8b
      if (frame.isEmptyFrame() || frame.isNoFrame()) return *this;
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
      return TFilePath(m_path + L"." + ::to_wstring(frame.expand(format)));
shun-iwasawa ef0f8b
    }
shun-iwasawa ef0f8b
    if (frame.isNoFrame()) {
shun-iwasawa ef0f8b
      return TFilePath(info.parentDir + info.levelName + "." + info.extension);
shun-iwasawa ef0f8b
    }
shun-iwasawa fc0d80
    QString sepChar = (info.sepChar.isNull()) ? QString(frame.getStartSeqInd())
shun-iwasawa fc0d80
                                              : QString(info.sepChar);
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
    return TFilePath(info.parentDir + info.levelName + sepChar +
shun-iwasawa ef0f8b
                     QString::fromStdString(frame.expand(format)) + "." +
shun-iwasawa ef0f8b
                     info.extension);
shun-iwasawa ef0f8b
  }
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
  //-----------------
shun-iwasawa ef0f8b
Shinya Kitaoka 120a6e
  const std::wstring dot = L".", dotDot = L"..";
Shinya Kitaoka 38fd86
  int i            = getLastSlash(m_path);  // cerco l'ultimo slash
Shinya Kitaoka 120a6e
  std::wstring str = m_path.substr(i + 1);  // str e' il path senza parentdir
manongjohn 4ee91c
  QString type     = QString::fromStdString(getType()).toLower();
Shinya Kitaoka 120a6e
  assert(str != dot && str != dotDot);
Shinya Kitaoka 120a6e
  int j          = str.rfind(L'.');
Shinya Kitaoka 120a6e
  const char *ch = ".";
manongjohn 4ee91c
  // Override format input because it may be wrong.
manongjohn 4ee91c
  if (!isFfmpegType() && checkForSeqNum(type))
manongjohn 4ee91c
    format = frame.getCurrentFormat();
Shinya Kitaoka 120a6e
  if (m_underscoreFormatAllowed && (format == TFrameId::UNDERSCORE_FOUR_ZEROS ||
manongjohn 4ee91c
                                    format == TFrameId::UNDERSCORE_NO_PAD ||
manongjohn 4ee91c
                                    format == TFrameId::UNDERSCORE_CUSTOM_PAD))
Shinya Kitaoka 120a6e
    ch = "_";
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
  // no extension case
Shinya Kitaoka 120a6e
  if (j == (int)std::wstring::npos) {
Shinya Kitaoka 120a6e
    if (frame.isEmptyFrame() || frame.isNoFrame())
Shinya Kitaoka 120a6e
      return *this;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      return TFilePath(m_path + ::to_wstring(ch + frame.expand(format)));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
manongjohn 4ee91c
  int k = str.substr(0, j).rfind(L'.');
manongjohn 4ee91c
manongjohn 4ee91c
  bool hasValidFrameNum = false;
manongjohn 4ee91c
  if (!isFfmpegType() && checkForSeqNum(type) && isNumbers(str, k, j))
manongjohn 4ee91c
    hasValidFrameNum = true;
Shinya Kitaoka 120a6e
  std::string frameString;
shun-iwasawa 85c995
  if (frame.isNoFrame())
shun-iwasawa 85c995
    frameString = "";
shun-iwasawa 85c995
  else if (!frame.isEmptyFrame() && getDots() != "." && !hasValidFrameNum) {
manongjohn 4ee91c
    if (k != (int)std::wstring::npos) {
manongjohn 4ee91c
      std::wstring wstr = str.substr(k, j - k);
manongjohn 4ee91c
      std::string str2(wstr.begin(), wstr.end());
manongjohn 4ee91c
      frameString = str2;
manongjohn 4ee91c
    } else
manongjohn 4ee91c
      frameString = "";
manongjohn 4ee91c
  } else
Shinya Kitaoka 120a6e
    frameString = ch + frame.expand(format);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (k != (int)std::wstring::npos)
Shinya Kitaoka 120a6e
    return TFilePath(m_path.substr(0, k + i + 1) + ::to_wstring(frameString) +
Shinya Kitaoka 120a6e
                     str.substr(j));
Shinya Kitaoka 120a6e
  else if (m_underscoreFormatAllowed) {
Shinya Kitaoka 120a6e
    k = str.substr(0, j).rfind(L'_');
Shinya Kitaoka 120a6e
    if (k != (int)std::wstring::npos &&
Shinya Kitaoka 120a6e
        (k == j - 1 ||
manongjohn 4ee91c
         (checkForSeqNum(type) &&
manongjohn 4ee91c
          isNumbers(str, k,
shun-iwasawa 443318
                    j))))  // -- In case of "_." or "_[numbers]." --
Shinya Kitaoka 120a6e
      return TFilePath(m_path.substr(0, k + i + 1) +
Shinya Kitaoka 120a6e
                       ((frame.isNoFrame())
Shinya Kitaoka 120a6e
                            ? L""
Shinya Kitaoka 120a6e
                            : ::to_wstring("_" + frame.expand(format))) +
Shinya Kitaoka 120a6e
                       str.substr(j));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return TFilePath(m_path.substr(0, j + i + 1) + ::to_wstring(frameString) +
Shinya Kitaoka 120a6e
                   str.substr(j));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TFilePath::isAncestorOf(const TFilePath &possibleDescendent) const {
Shinya Kitaoka 120a6e
  size_t len = m_path.length();
Shinya Kitaoka 120a6e
  if (len == 0) {
Shinya Kitaoka 120a6e
    // il punto e' antenato di tutti i path non assoluti
Shinya Kitaoka 120a6e
    return !possibleDescendent.isAbsolute();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // un path e' antenato di se stesso
Shinya Kitaoka 120a6e
  if (m_path == possibleDescendent.m_path) return true;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int possibleDescendentLen = possibleDescendent.m_path.length();
Shinya Kitaoka 120a6e
  // altrimenti l'antenato deve essere piu' corto
Shinya Kitaoka 120a6e
  if ((int)len >= possibleDescendentLen) return false;
Shinya Kitaoka 120a6e
  // e deve coincidere con la prima parte del discendente
Shinya Kitaoka 120a6e
  if (toLower(m_path) != toLower(possibleDescendent.m_path.substr(0, len)))
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
  // se l'antenato non finisce con slash ci deve essere uno slash nel
Shinya Kitaoka 120a6e
  // discendente, subito dopo
Shinya Kitaoka 120a6e
  if (m_path[len - 1] != wslash && possibleDescendent.m_path[len] != wslash)
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath TFilePath::operator-(const TFilePath &fp) const {
Shinya Kitaoka 120a6e
  if (toLower(m_path) == toLower(fp.m_path)) return TFilePath("");
Shinya Kitaoka 120a6e
  if (!fp.isAncestorOf(*this)) return *this;
Shinya Kitaoka 120a6e
  int len = fp.m_path.length();
Shinya Kitaoka 120a6e
  if (len == 0 || fp.m_path[len - 1] != wslash) len++;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return TFilePath(m_path.substr(len));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TFilePath::match(const TFilePath &fp) const {
shun-iwasawa ef0f8b
  if (!TFilePath::m_useStandard) {
shun-iwasawa ef0f8b
    if (getParentDir() != fp.getParentDir()) return false;
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
    TFilePathInfo info     = analyzePath();
shun-iwasawa ef0f8b
    TFilePathInfo info_ext = fp.analyzePath();
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
    return (info.levelName == info_ext.levelName && info.fId == info_ext.fId &&
shun-iwasawa ef0f8b
            info.extension == info_ext.extension);
shun-iwasawa ef0f8b
  }
shun-iwasawa ef0f8b
Shinya Kitaoka 120a6e
  return getParentDir() == fp.getParentDir() && getName() == fp.getName() &&
Shinya Kitaoka 120a6e
         getFrame() == fp.getFrame() && getType() == fp.getType();
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//-----------------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void TFilePath::split(std::wstring &head, TFilePath &tail) const {
Shinya Kitaoka 120a6e
  TFilePath ancestor = getParentDir();
Shinya Kitaoka 120a6e
  if (ancestor == TFilePath()) {
Shinya Kitaoka 120a6e
    head = getWideString();
Shinya Kitaoka 120a6e
    tail = TFilePath();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  for (;;) {
Shinya Kitaoka 120a6e
    if (ancestor.isRoot()) break;
Shinya Kitaoka 120a6e
    TFilePath p = ancestor.getParentDir();
Shinya Kitaoka 120a6e
    if (p == TFilePath()) break;
Shinya Kitaoka 120a6e
    ancestor = p;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  head = ancestor.getWideString();
Shinya Kitaoka 120a6e
  tail = *this - ancestor;
Toshihiro Shimizu 890ddd
}
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
//-----------------------------------------------------------------------------
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
QString TFilePath::fidRegExpStr() {
shun-iwasawa ef0f8b
  if (m_useStandard) return QString("(\\d+)([a-zA-Z]?)");
shun-iwasawa ef0f8b
  QString suffixLetter = (m_acceptNonAlphabetSuffix)
shun-iwasawa ef0f8b
                             ? "[^\\._ \\\\/:,;*?\"<>|0123456789]"
shun-iwasawa ef0f8b
                             : "[a-zA-Z]";
shun-iwasawa 22b8d4
  QString countLetter  = (m_letterCountForSuffix == 0)
shun-iwasawa 22b8d4
                             ? "{0,}"
shun-iwasawa 22b8d4
                             : (QString("{0,%1}").arg(m_letterCountForSuffix));
shun-iwasawa ef0f8b
  return QString("(\\d+)(%1%2)").arg(suffixLetter).arg(countLetter);
shun-iwasawa ef0f8b
  // const QString fIdRegExp("(\\d+)([a-zA-Z]?)");
shun-iwasawa ef0f8b
}
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
//-----------------------------------------------------------------------------
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
TFilePath::TFilePathInfo TFilePath::analyzePath() const {
shun-iwasawa ef0f8b
  assert(!TFilePath::m_useStandard);
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
  TFilePath::TFilePathInfo info;
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
  int i            = getLastSlash(m_path);
shun-iwasawa ef0f8b
  std::wstring str = m_path.substr(i + 1);
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
  if (i >= 0) info.parentDir = QString::fromStdWString(m_path.substr(0, i + 1));
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
  QString fileName = QString::fromStdWString(str);
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
  // Level Name : letters other than  \/:,;*?"<>|
shun-iwasawa ef0f8b
  const QString levelNameRegExp("([^\\\\/:,;*?\"<>|]+)");
shun-iwasawa ef0f8b
  // Sep Char : period or underscore
shun-iwasawa ef0f8b
  const QString sepCharRegExp("([\\._])");
shun-iwasawa ef0f8b
  // Frame Number and Suffix
shun-iwasawa ef0f8b
  QString fIdRegExp = TFilePath::fidRegExpStr();
shun-iwasawa ef0f8b
shun-iwasawa 443318
  // Extension: letters other than "._" or  \/:,;*?"<>|  or " "(space)
shun-iwasawa ef0f8b
  const QString extensionRegExp("([^\\._ \\\\/:,;*?\"<>|]+)");
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
  // ignore frame numbers on non-sequential (i.e. movie) extension case :
shun-iwasawa ef0f8b
  // hoge_0001.mp4
shun-iwasawa ef0f8b
  // QRegExp rx_mf("^" + levelNameRegExp + "\\." + extensionRegExp + "$");
shun-iwasawa ef0f8b
  // if (rx_mf.indexIn(levelName) != -1) {
shun-iwasawa ef0f8b
  //  QString ext = rx_mf.cap(2);
shun-iwasawa ef0f8b
  //  if (!checkForSeqNum(ext)) {
shun-iwasawa ef0f8b
  //    info.levelName = rx_mf.cap(1);
shun-iwasawa ef0f8b
  //    info.sepChar = QChar();
shun-iwasawa 443318
  //    info.fId = TFrameId(TFrameId::NO_FRAME, 0, 0); // initialize with NO_PAD
shun-iwasawa ef0f8b
  //    info.extension = ext;
shun-iwasawa ef0f8b
  //    return info;
shun-iwasawa ef0f8b
  //  }
shun-iwasawa ef0f8b
  //}
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
  // hogehoge.0001a.jpg
shun-iwasawa ef0f8b
  // empty frame case : hogehoge..jpg
shun-iwasawa 22b8d4
  // empty level name case : ..jpg   .0001a.jpg
shun-iwasawa 22b8d4
  QRegExp rx("^(?:" + levelNameRegExp + ")?" + sepCharRegExp +
shun-iwasawa 22b8d4
             "(?:" + fIdRegExp + ")?" + "\\." + extensionRegExp + "$");
shun-iwasawa ef0f8b
  if (rx.indexIn(fileName) != -1) {
shun-iwasawa ef0f8b
    assert(rx.captureCount() == 5);
shun-iwasawa ef0f8b
    info.levelName = rx.cap(1);
shun-iwasawa ef0f8b
    info.sepChar   = rx.cap(2)[0];
shun-iwasawa ef0f8b
    info.extension = rx.cap(5);
shun-iwasawa ef0f8b
    // ignore frame numbers on non-sequential (i.e. movie) extension case :
shun-iwasawa ef0f8b
    // hoge_0001.mp4
shun-iwasawa ef0f8b
    if (!checkForSeqNum(info.extension)) {
shun-iwasawa ef0f8b
      info.levelName = rx.cap(1) + rx.cap(2);
shun-iwasawa ef0f8b
      if (!rx.cap(3).isEmpty()) info.levelName += rx.cap(3);
shun-iwasawa ef0f8b
      if (!rx.cap(4).isEmpty()) info.levelName += rx.cap(4);
shun-iwasawa ef0f8b
      info.sepChar = QChar();
shun-iwasawa ef0f8b
      info.fId = TFrameId(TFrameId::NO_FRAME, 0, 0);  // initialize with NO_PAD
shun-iwasawa ef0f8b
    } else {
shun-iwasawa ef0f8b
      QString numberStr = rx.cap(3);
shun-iwasawa ef0f8b
      if (numberStr.isEmpty())  // empty frame case : hogehoge..jpg
shun-iwasawa ef0f8b
        info.fId =
shun-iwasawa ef0f8b
            TFrameId(TFrameId::EMPTY_FRAME, 0, 4, info.sepChar.toLatin1());
shun-iwasawa ef0f8b
      else {
shun-iwasawa ef0f8b
        int number  = numberStr.toInt();
shun-iwasawa ef0f8b
        int padding = 0;
shun-iwasawa ef0f8b
        if (numberStr[0] == "0")  // with padding
shun-iwasawa ef0f8b
          padding = numberStr.count();
shun-iwasawa ef0f8b
        QString suffix;
shun-iwasawa ef0f8b
        if (!rx.cap(4).isEmpty()) suffix = rx.cap(4);
shun-iwasawa ef0f8b
        info.fId = TFrameId(number, suffix, padding, info.sepChar.toLatin1());
shun-iwasawa ef0f8b
      }
shun-iwasawa ef0f8b
    }
shun-iwasawa ef0f8b
    return info;
shun-iwasawa ef0f8b
  }
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
  // QRegExp rx_ef("^" + levelNameRegExp + sepCharRegExp + "\\." +
shun-iwasawa ef0f8b
  // extensionRegExp + "$"); if (rx_ef.indexIn(levelName) != -1) {
shun-iwasawa ef0f8b
  //  info.levelName = rx_ef.cap(1);
shun-iwasawa ef0f8b
  //  info.sepChar = rx_ef.cap(2)[0];
shun-iwasawa ef0f8b
  //  info.fId = TFrameId(TFrameId::EMPTY_FRAME, 0, 4, info.sepChar.toLatin1());
shun-iwasawa ef0f8b
  //  info.extension = rx_ef.cap(3);
shun-iwasawa ef0f8b
  //  return info;
shun-iwasawa ef0f8b
  //}
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
  // no frame case : hogehoge.jpg
shun-iwasawa ef0f8b
  // no level name case : .jpg
shun-iwasawa ef0f8b
  QRegExp rx_nf("^(?:" + levelNameRegExp + ")?\\." + extensionRegExp + "$");
shun-iwasawa ef0f8b
  if (rx_nf.indexIn(fileName) != -1) {
shun-iwasawa ef0f8b
    if (!rx_nf.cap(1).isEmpty()) info.levelName = rx_nf.cap(1);
shun-iwasawa ef0f8b
    info.sepChar = QChar();
shun-iwasawa ef0f8b
    info.fId = TFrameId(TFrameId::NO_FRAME, 0, 0);  // initialize with NO_PAD
shun-iwasawa ef0f8b
    info.extension = rx_nf.cap(2);
shun-iwasawa ef0f8b
    return info;
shun-iwasawa ef0f8b
  }
shun-iwasawa ef0f8b
shun-iwasawa ef0f8b
  // no periods
shun-iwasawa ef0f8b
  info.levelName = fileName;
shun-iwasawa ef0f8b
  info.sepChar   = QChar();
shun-iwasawa ef0f8b
  info.fId = TFrameId(TFrameId::NO_FRAME, 0, 0);  // initialize with NO_PAD
shun-iwasawa ef0f8b
  info.extension = QString();
shun-iwasawa ef0f8b
  return info;
shun-iwasawa ef0f8b
}