11/*
22 -------------------------------------------------------------------------------
33 This file is part of the Private Message Database.
4- Copyright (C) 2014, 2016 Dirk Stolle
4+ Copyright (C) 2014, 2016, 2025 Dirk Stolle
55
66 This program is free software: you can redistribute it and/or modify
77 it under the terms of the GNU General Public License as published by
@@ -36,40 +36,39 @@ void FolderMap::add(const SHA256::MessageDigest& pm_digest, const std::string& f
3636
3737bool FolderMap::hasEntry (const SHA256::MessageDigest& pm_digest) const
3838{
39- return ( m_FolderMap.find (pm_digest)!= m_FolderMap.end () );
39+ return m_FolderMap.find (pm_digest) != m_FolderMap.end ();
4040}
4141
4242const std::string& FolderMap::getFolderName (const SHA256::MessageDigest& pm_digest) const
4343{
4444 const std::map<SHA256::MessageDigest, std::string>::const_iterator iter = m_FolderMap.find (pm_digest);
45- if (iter!=m_FolderMap.end ()) return iter->second ;
46- throw std::runtime_error (" The message database's folder map has no message entry for the given hash " +pm_digest.toHexString ()+" !" );
45+ if (iter != m_FolderMap.end ())
46+ return iter->second ;
47+ throw std::runtime_error (" The message database's folder map has no message entry for the given hash " + pm_digest.toHexString () + " !" );
4748}
4849
4950bool FolderMap::save (const std::string& directory) const
5051{
5152 std::ofstream output;
52- output.open (( directory+ " foldermap" ). c_str () , std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
53+ output.open (directory + " foldermap" , std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
5354 if (!output)
5455 {
5556 return false ;
5657 }
5758 const char space = ' ' ;
5859 const char end = ' \n ' ;
59- std::map<SHA256::MessageDigest, std::string>::const_iterator iter = m_FolderMap.begin ();
60- while (iter!=m_FolderMap.end ())
60+ for (const auto & [digest, folder]: m_FolderMap)
6161 {
62- const std::string hexRepresentation = iter-> first .toHexString ();
63- // write hash
62+ const std::string hexRepresentation = digest .toHexString ();
63+ // write hash
6464 output.write (hexRepresentation.c_str (), hexRepresentation.length ());
65- // write space
65+ // write space
6666 output.write (&space, 1 );
67- // write folder name
68- output.write (iter-> second .c_str (), iter-> second .length ());
69- // write end of line character
67+ // write folder name
68+ output.write (folder .c_str (), folder .length ());
69+ // write end of line character
7070 output.write (&end, 1 );
71- ++iter;
72- }// while
71+ }
7372 const bool well = output.good ();
7473 output.close ();
7574 return well;
@@ -88,25 +87,25 @@ bool FolderMap::load(const std::string& directory)
8887 const unsigned int cMaxLine = 1024 ;
8988 char buffer[cMaxLine];
9089 std::string line = " " ;
91- while (inFile.getline (buffer, cMaxLine- 1 ))
90+ while (inFile.getline (buffer, cMaxLine - 1 ))
9291 {
9392 buffer[cMaxLine-1 ] = ' \0 ' ;
9493 line = std::string (buffer);
9594 if (!md.fromHexString (line.substr (0 , 64 )))
9695 {
9796 inFile.close ();
98- std::cout << " Error: string \" " << line.substr (0 ,64 )<< " \" is no valid hash!\n " ;
97+ std::cout << " Error: String \" " << line.substr (0 ,64 ) << " \" is no valid hash!\n " ;
9998 return false ;
10099 }
101- // remove hash
100+ // remove hash
102101 line.erase (0 , 64 );
103- // remove leading spaces
102+ // remove leading spaces
104103 trimLeft (line);
105104 if (!line.empty ())
106105 {
107106 m_FolderMap[md] = line;
108- }// if
109- }// while
107+ }
108+ }
110109 inFile.close ();
111110 return true ;
112111}
@@ -115,10 +114,10 @@ std::set<std::string> FolderMap::getPresentFolders() const
115114{
116115 std::set<std::string> allFolders;
117116 std::map<SHA256::MessageDigest, std::string>::const_iterator iter = m_FolderMap.begin ();
118- while (iter!= m_FolderMap.end ())
117+ while (iter != m_FolderMap.end ())
119118 {
120119 allFolders.insert (iter->second );
121120 ++iter;
122- }// while
121+ }
123122 return allFolders;
124123}
0 commit comments