put local functions into unnamed namespaces

This commit is contained in:
unK
2008-09-27 20:54:32 +02:00
parent d61cb54653
commit 9b65b39126
7 changed files with 229 additions and 222 deletions

View File

@@ -23,62 +23,65 @@
extern ncmpcpp_keys Key;
string DisplayKeys(int *key, int size = 2)
namespace
{
bool backspace = 1;
string result = "\t";
for (int i = 0; i < size; i++)
string DisplayKeys(int *key, int size = 2)
{
if (key[i] == null_key);
else if (key[i] == 259)
result += "Up";
else if (key[i] == 258)
result += "Down";
else if (key[i] == 339)
result += "Page Up";
else if (key[i] == 338)
result += "Page Down";
else if (key[i] == 262)
result += "Home";
else if (key[i] == 360)
result += "End";
else if (key[i] == 32)
result += "Space";
else if (key[i] == 10)
result += "Enter";
else if (key[i] == 330)
result += "Delete";
else if (key[i] == 261)
result += "Right";
else if (key[i] == 260)
result += "Left";
else if (key[i] == 9)
result += "Tab";
else if (key[i] >= 1 && key[i] <= 26)
bool backspace = 1;
string result = "\t";
for (int i = 0; i < size; i++)
{
result += "Ctrl-";
result += key[i]+64;
if (key[i] == null_key);
else if (key[i] == 259)
result += "Up";
else if (key[i] == 258)
result += "Down";
else if (key[i] == 339)
result += "Page Up";
else if (key[i] == 338)
result += "Page Down";
else if (key[i] == 262)
result += "Home";
else if (key[i] == 360)
result += "End";
else if (key[i] == 32)
result += "Space";
else if (key[i] == 10)
result += "Enter";
else if (key[i] == 330)
result += "Delete";
else if (key[i] == 261)
result += "Right";
else if (key[i] == 260)
result += "Left";
else if (key[i] == 9)
result += "Tab";
else if (key[i] >= 1 && key[i] <= 26)
{
result += "Ctrl-";
result += key[i]+64;
}
else if (key[i] >= 265 && key[i] <= 276)
{
result += "F";
result += key[i]-216;
}
else if ((key[i] == 263 || key[i] == 127) && !backspace);
else if ((key[i] == 263 || key[i] == 127) && backspace)
{
result += "Backspace";
backspace = 0;
}
else
result += key[i];
result += " ";
}
else if (key[i] >= 265 && key[i] <= 276)
{
result += "F";
result += key[i]-216;
}
else if ((key[i] == 263 || key[i] == 127) && !backspace);
else if ((key[i] == 263 || key[i] == 127) && backspace)
{
result += "Backspace";
backspace = 0;
}
else
result += key[i];
result += " ";
if (result.length() > 12)
result = result.substr(0, 12);
for (int i = result.length(); i <= 12; result += " ", i++);
result += ": ";
return result;
}
if (result.length() > 12)
result = result.substr(0, 12);
for (int i = result.length(); i <= 12; result += " ", i++);
result += ": ";
return result;
}
string GetKeybindings()

View File

@@ -32,30 +32,33 @@ pthread_mutex_t curl = PTHREAD_MUTEX_INITIALIZER;
bool data_ready = 0;
#endif
size_t write_data(char *buffer, size_t size, size_t nmemb, string data)
namespace
{
int result = 0;
if (buffer)
size_t write_data(char *buffer, size_t size, size_t nmemb, string data)
{
data += buffer;
result = size*nmemb;
int result = 0;
if (buffer)
{
data += buffer;
result = size*nmemb;
}
return result;
}
return result;
}
void EscapeHtml(string &str)
{
for (int i = str.find("<"); i != string::npos; i = str.find("<"))
void EscapeHtml(string &str)
{
int j = str.find(">")+1;
str.replace(i, j-i, "");
for (int i = str.find("<"); i != string::npos; i = str.find("<"))
{
int j = str.find(">")+1;
str.replace(i, j-i, "");
}
for (int i = str.find("&#039;"); i != string::npos; i = str.find("&#039;"))
str.replace(i, 6, "'");
for (int i = str.find("&quot;"); i != string::npos; i = str.find("&quot;"))
str.replace(i, 6, "\"");
for (int i = str.find("&amp;"); i != string::npos; i = str.find("&amp;"))
str.replace(i, 5, "&");
}
for (int i = str.find("&#039;"); i != string::npos; i = str.find("&#039;"))
str.replace(i, 6, "'");
for (int i = str.find("&quot;"); i != string::npos; i = str.find("&quot;"))
str.replace(i, 6, "\"");
for (int i = str.find("&amp;"); i != string::npos; i = str.find("&amp;"))
str.replace(i, 5, "&");
}
#ifdef HAVE_CURL_CURL_H

View File

@@ -30,7 +30,6 @@
void * GetArtistInfo(void *);
#endif
void EscapeHtml(string &);
void * GetLyrics(void *);
#endif

View File

@@ -197,29 +197,6 @@ void DefaultConfiguration(ncmpcpp_config &conf)
conf.message_delay_time = 4;
}
void GetKeys(string line, int *key)
{
int i = line.find("=")+1;
line = line.substr(i, line.length()-i);
i = 0;
if (line[i] == ' ')
while (line[++i] == ' ');
line = line.substr(i, line.length()-i);
i = line.find(" ");
string one;
string two;
if (i != string::npos)
{
one = line.substr(0, i);
i++;
two = line.substr(i, line.length()-i);
}
else
one = line;
key[0] = !one.empty() && one[0] == '\'' ? one[1] : (atoi(one.c_str()) == 0 ? null_key : atoi(one.c_str()));
key[1] = !two.empty() && two[0] == '\'' ? two[1] : (atoi(two.c_str()) == 0 ? null_key : atoi(two.c_str()));
}
string GetLineValue(const string &line, char a, char b)
{
int i = 0;
@@ -240,54 +217,80 @@ string GetLineValue(const string &line, char a, char b)
return "";
}
string IntoStr(Color color)
namespace
{
string result;
void GetKeys(string line, int *key)
{
int i = line.find("=")+1;
line = line.substr(i, line.length()-i);
i = 0;
if (line[i] == ' ')
while (line[++i] == ' ');
line = line.substr(i, line.length()-i);
i = line.find(" ");
string one;
string two;
if (i != string::npos)
{
one = line.substr(0, i);
i++;
two = line.substr(i, line.length()-i);
}
else
one = line;
key[0] = !one.empty() && one[0] == '\'' ? one[1] : (atoi(one.c_str()) == 0 ? null_key : atoi(one.c_str()));
key[1] = !two.empty() && two[0] == '\'' ? two[1] : (atoi(two.c_str()) == 0 ? null_key : atoi(two.c_str()));
}
if (color == clDefault)
result = "default";
else if (color == clBlack)
result = "black";
else if (color == clRed)
result = "red";
else if (color == clGreen)
result = "green";
else if (color == clYellow)
result = "yellow";
else if (color == clBlue)
result = "blue";
else if (color == clMagenta)
result = "magenta";
else if (color == clCyan)
result = "cyan";
else if (color == clWhite)
result = "white";
string IntoStr(Color color)
{
string result;
return result;
}
if (color == clDefault)
result = "default";
else if (color == clBlack)
result = "black";
else if (color == clRed)
result = "red";
else if (color == clGreen)
result = "green";
else if (color == clYellow)
result = "yellow";
else if (color == clBlue)
result = "blue";
else if (color == clMagenta)
result = "magenta";
else if (color == clCyan)
result = "cyan";
else if (color == clWhite)
result = "white";
Color IntoColor(const string &color)
{
Color result = clDefault;
return result;
}
if (color == "black")
result = clBlack;
else if (color == "red")
result = clRed;
else if (color == "green")
result = clGreen;
else if (color == "yellow")
result = clYellow;
else if (color == "blue")
result = clBlue;
else if (color == "magenta")
result = clMagenta;
else if (color == "cyan")
result = clCyan;
else if (color == "white")
result = clWhite;
Color IntoColor(const string &color)
{
Color result = clDefault;
return result;
if (color == "black")
result = clBlack;
else if (color == "red")
result = clRed;
else if (color == "green")
result = clGreen;
else if (color == "yellow")
result = clYellow;
else if (color == "blue")
result = clBlue;
else if (color == "magenta")
result = clMagenta;
else if (color == "cyan")
result = clCyan;
else if (color == "white")
result = clWhite;
return result;
}
}
void ReadKeys(ncmpcpp_keys &keys)

View File

@@ -147,12 +147,10 @@ struct ncmpcpp_config
void DefaultKeys(ncmpcpp_keys &);
void DefaultConfiguration(ncmpcpp_config &);
void GetKeys(string, int *);
string GetLineValue(const string &, char = '"', char = '"');
string IntoStr(Color);
Color IntoColor(const string &);
void ReadKeys(ncmpcpp_keys &);
void ReadConfiguration(ncmpcpp_config &);
string GetLineValue(const string &, char = '"', char = '"');
#endif

View File

@@ -189,98 +189,101 @@ bool WriteTags(Song &s)
return false;
}
SongSetFunction IntoSetFunction(char c)
namespace
{
switch (c)
SongSetFunction IntoSetFunction(char c)
{
case 'a':
return &Song::SetArtist;
case 't':
return &Song::SetTitle;
case 'b':
return &Song::SetAlbum;
case 'y':
return &Song::SetYear;
case 'n':
return &Song::SetTrack;
case 'g':
return &Song::SetGenre;
case 'c':
return &Song::SetComposer;
case 'p':
return &Song::SetPerformer;
case 'd':
return &Song::SetDisc;
case 'C':
return &Song::SetComment;
default:
return NULL;
}
}
string GenerateFilename(const Song &s, string &pattern)
{
const string unallowed_chars = "\"*/:<>?\\|";
string result = Window::OmitBBCodes(DisplaySong(s, &pattern));
for (string::const_iterator it = unallowed_chars.begin(); it != unallowed_chars.end(); it++)
{
for (int i = 0; i < result.length(); i++)
switch (c)
{
if (result[i] == *it)
result.erase(result.begin()+i);
case 'a':
return &Song::SetArtist;
case 't':
return &Song::SetTitle;
case 'b':
return &Song::SetAlbum;
case 'y':
return &Song::SetYear;
case 'n':
return &Song::SetTrack;
case 'g':
return &Song::SetGenre;
case 'c':
return &Song::SetComposer;
case 'p':
return &Song::SetPerformer;
case 'd':
return &Song::SetDisc;
case 'C':
return &Song::SetComment;
default:
return NULL;
}
}
return result;
}
string ParseFilename(Song &s, string mask, bool preview)
{
std::stringstream result;
vector<string> separators;
vector< std::pair<char, string> > tags;
string file = s.GetName().substr(0, s.GetName().find_last_of("."));
try
string GenerateFilename(const Song &s, string &pattern)
{
for (int i = mask.find("%"); i != string::npos; i = mask.find("%"))
const string unallowed_chars = "\"*/:<>?\\|";
string result = Window::OmitBBCodes(DisplaySong(s, &pattern));
for (string::const_iterator it = unallowed_chars.begin(); it != unallowed_chars.end(); it++)
{
tags.push_back(make_pair(mask.at(i+1), ""));
mask = mask.substr(i+2);
i = mask.find("%");
if (!mask.empty())
separators.push_back(mask.substr(0, i));
for (int i = 0; i < result.length(); i++)
{
if (result[i] == *it)
result.erase(result.begin()+i);
}
}
int i = 0;
for (vector<string>::const_iterator it = separators.begin(); it != separators.end(); it++, i++)
{
int j = file.find(*it);
tags.at(i).second = file.substr(0, j);
file = file.substr(j+it->length());
}
if (!file.empty())
tags.at(i).second = file;
}
catch (std::out_of_range)
{
return "Error while parsing filename!";
return result;
}
for (vector< std::pair<char, string> >::iterator it = tags.begin(); it != tags.end(); it++)
string ParseFilename(Song &s, string mask, bool preview)
{
for (string::iterator j = it->second.begin(); j != it->second.end(); j++)
if (*j == '_')
*j = ' ';
std::stringstream result;
vector<string> separators;
vector< std::pair<char, string> > tags;
string file = s.GetName().substr(0, s.GetName().find_last_of("."));
if (!preview)
try
{
SongSetFunction set = IntoSetFunction(it->first);
if (set)
(s.*set)(it->second);
for (int i = mask.find("%"); i != string::npos; i = mask.find("%"))
{
tags.push_back(make_pair(mask.at(i+1), ""));
mask = mask.substr(i+2);
i = mask.find("%");
if (!mask.empty())
separators.push_back(mask.substr(0, i));
}
int i = 0;
for (vector<string>::const_iterator it = separators.begin(); it != separators.end(); it++, i++)
{
int j = file.find(*it);
tags.at(i).second = file.substr(0, j);
file = file.substr(j+it->length());
}
if (!file.empty())
tags.at(i).second = file;
}
else
result << "%" << it->first << ": " << it->second << "\n";
catch (std::out_of_range)
{
return "Error while parsing filename!";
}
for (vector< std::pair<char, string> >::iterator it = tags.begin(); it != tags.end(); it++)
{
for (string::iterator j = it->second.begin(); j != it->second.end(); j++)
if (*j == '_')
*j = ' ';
if (!preview)
{
SongSetFunction set = IntoSetFunction(it->first);
if (set)
(s.*set)(it->second);
}
else
result << "%" << it->first << ": " << it->second << "\n";
}
return result.str();
}
return result.str();
}
void __deal_with_filenames(SongList &v)

View File

@@ -41,8 +41,6 @@ string DisplayTag(const Song &, void *, const Menu<Song> *);
bool GetSongTags(Song &);
bool WriteTags(Song &);
string GenerateFilename(const Song &, string &);
string ParseFilename(Song &, string, bool);
void __deal_with_filenames(SongList &);
#endif