Logo Search packages:      
Sourcecode: djvulibre version File versions

GPList< DjVmDir::File > DjVmDir::resolve_duplicates ( const bool  save_as_bundled  ) 

Check for duplicate names, and resolve them.

Definition at line 788 of file DjVmDir.cpp.

References GMapTemplate< KTYPE, VTYPE, VTYPE >::contains(), GPEnabled::count, GUTF8String::downcase(), GMapTemplate< KTYPE, VTYPE, VTYPE >::key(), GBaseString::rsearch(), and GUTF8String::substr().

Referenced by DjVmDoc::expand(), DjVuDocEditor::save_as(), and DjVmDoc::write().

{
  GCriticalSectionLock lock((GCriticalSection *) &class_lock);
  // Make sure all the filenames are unique.
  GPosition pos;
  GMap<GUTF8String,void *> save_map;
  GMap<GUTF8String,GPList<DjVmDir::File> > conflicts;
  for(pos=files_list;pos;++pos)
  {
    const GUTF8String save_name=files_list[pos]->check_save_name(save_as_bundled).downcase();
    if(save_map.contains(save_name))
    {
      conflicts[save_name].append(files_list[pos]);
    }else
    {
      save_map[save_name]=0;
    }
  }
  for(pos=conflicts;pos;++pos)
  {
    const GUTF8String &save_name=conflicts.key(pos);
    const int dot=save_name.rsearch('.',0);
    GPList<DjVmDir::File> &cfiles=conflicts[pos];
    int count=1;
    for(GPosition qpos=cfiles;qpos;++qpos)
    {
      GUTF8String new_name=cfiles[qpos]->get_load_name();
      if((new_name != GUTF8String(GNativeString(new_name)))
        ||conflicts.contains(new_name))
      {
        do
        {
          new_name=(dot<0)
            ?(save_name+"-"+GUTF8String(count++))
            :(save_name.substr(0,dot)+"-"+GUTF8String(count++)+
              save_name.substr(dot,(unsigned int)(-1)));
        } while(save_map.contains(new_name.downcase()));
      }
      cfiles[qpos]->set_save_name(new_name);
      save_map[new_name]=0;
    }
  }
  return files_list;
}


Generated by  Doxygen 1.6.0   Back to index