make str_pool return const char * instead of char *
This commit is contained in:
@@ -55,7 +55,7 @@ namespace
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void charset_convert(const char *from, const char *to, char *&inbuf, size_t len = 0)
|
void charset_convert(const char *from, const char *to, const char *&inbuf, size_t len = 0)
|
||||||
{
|
{
|
||||||
if (!inbuf || !from || !to)
|
if (!inbuf || !from || !to)
|
||||||
return;
|
return;
|
||||||
@@ -70,7 +70,7 @@ namespace
|
|||||||
size_t buflen = len*6+1;
|
size_t buflen = len*6+1;
|
||||||
char *outbuf = new char[buflen];
|
char *outbuf = new char[buflen];
|
||||||
char *outstart = outbuf;
|
char *outstart = outbuf;
|
||||||
char *instart = inbuf;
|
const char *instart = inbuf;
|
||||||
|
|
||||||
if (iconv(cd, const_cast<ICONV_CONST char **>(&inbuf), &len, &outbuf, &buflen) == size_t(-1))
|
if (iconv(cd, const_cast<ICONV_CONST char **>(&inbuf), &len, &outbuf, &buflen) == size_t(-1))
|
||||||
{
|
{
|
||||||
@@ -90,7 +90,7 @@ void utf_to_locale(std::string &s)
|
|||||||
{
|
{
|
||||||
if (s.empty() || Config.system_encoding.empty() || !has_non_ascii_chars(s))
|
if (s.empty() || Config.system_encoding.empty() || !has_non_ascii_chars(s))
|
||||||
return;
|
return;
|
||||||
char *tmp = str_pool_get(s.c_str());
|
const char *tmp = str_pool_get(s.c_str());
|
||||||
charset_convert("utf-8", Config.system_encoding.c_str(), tmp, s.length());
|
charset_convert("utf-8", Config.system_encoding.c_str(), tmp, s.length());
|
||||||
s = tmp;
|
s = tmp;
|
||||||
str_pool_put(tmp);
|
str_pool_put(tmp);
|
||||||
@@ -107,7 +107,7 @@ void locale_to_utf(std::string &s)
|
|||||||
{
|
{
|
||||||
if (s.empty() || Config.system_encoding.empty() || !has_non_ascii_chars(s))
|
if (s.empty() || Config.system_encoding.empty() || !has_non_ascii_chars(s))
|
||||||
return;
|
return;
|
||||||
char *tmp = str_pool_get(s.c_str());
|
const char *tmp = str_pool_get(s.c_str());
|
||||||
charset_convert(Config.system_encoding.c_str(), "utf-8", tmp, s.length());
|
charset_convert(Config.system_encoding.c_str(), "utf-8", tmp, s.length());
|
||||||
s = tmp;
|
s = tmp;
|
||||||
str_pool_put(tmp);
|
str_pool_put(tmp);
|
||||||
@@ -120,14 +120,14 @@ std::string locale_to_utf_cpy(const std::string &s)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void str_pool_utf_to_locale(char *&s)
|
void str_pool_utf_to_locale(const char *&s)
|
||||||
{
|
{
|
||||||
if (!s || Config.system_encoding.empty() || !has_non_ascii_chars(s))
|
if (!s || Config.system_encoding.empty() || !has_non_ascii_chars(s))
|
||||||
return;
|
return;
|
||||||
charset_convert("utf-8", Config.system_encoding.c_str(), s);
|
charset_convert("utf-8", Config.system_encoding.c_str(), s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void str_pool_locale_to_utf(char *&s)
|
void str_pool_locale_to_utf(const char *&s)
|
||||||
{
|
{
|
||||||
if (!s || Config.system_encoding.empty() || !has_non_ascii_chars(s))
|
if (!s || Config.system_encoding.empty() || !has_non_ascii_chars(s))
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ void locale_to_utf(std::string &);
|
|||||||
std::string utf_to_locale_cpy(const std::string &s);
|
std::string utf_to_locale_cpy(const std::string &s);
|
||||||
std::string locale_to_utf_cpy(const std::string &s);
|
std::string locale_to_utf_cpy(const std::string &s);
|
||||||
|
|
||||||
void str_pool_utf_to_locale(char *&);
|
void str_pool_utf_to_locale(const char *&);
|
||||||
void str_pool_locale_to_utf(char *&);
|
void str_pool_locale_to_utf(const char *&);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
|||||||
@@ -98,8 +98,8 @@ extern char * mpdTagItemKeys[MPD_TAG_NUM_OF_ITEM_TYPES];
|
|||||||
|
|
||||||
/* internal stuff don't touch this struct */
|
/* internal stuff don't touch this struct */
|
||||||
typedef struct _mpd_ReturnElement {
|
typedef struct _mpd_ReturnElement {
|
||||||
char * name;
|
const char * name;
|
||||||
char * value;
|
const char * value;
|
||||||
} mpd_ReturnElement;
|
} mpd_ReturnElement;
|
||||||
|
|
||||||
/* mpd_Connection
|
/* mpd_Connection
|
||||||
@@ -261,32 +261,32 @@ void mpd_freeSearchStats(mpd_SearchStats * stats);
|
|||||||
*/
|
*/
|
||||||
typedef struct _mpd_Song {
|
typedef struct _mpd_Song {
|
||||||
/* filename of song */
|
/* filename of song */
|
||||||
char * file;
|
const char * file;
|
||||||
/* artist, maybe NULL if there is no tag */
|
/* artist, maybe NULL if there is no tag */
|
||||||
char * artist;
|
const char * artist;
|
||||||
/* title, maybe NULL if there is no tag */
|
/* title, maybe NULL if there is no tag */
|
||||||
char * title;
|
const char * title;
|
||||||
/* album, maybe NULL if there is no tag */
|
/* album, maybe NULL if there is no tag */
|
||||||
char * album;
|
const char * album;
|
||||||
/* track, maybe NULL if there is no tag */
|
/* track, maybe NULL if there is no tag */
|
||||||
char * track;
|
const char * track;
|
||||||
/* name, maybe NULL if there is no tag; it's the name of the current
|
/* name, maybe NULL if there is no tag; it's the name of the current
|
||||||
* song, f.e. the icyName of the stream */
|
* song, f.e. the icyName of the stream */
|
||||||
char * name;
|
const char * name;
|
||||||
/* date */
|
/* date */
|
||||||
char *date;
|
const char *date;
|
||||||
|
|
||||||
/* added by qball */
|
/* added by qball */
|
||||||
/* Genre */
|
/* Genre */
|
||||||
char *genre;
|
const char *genre;
|
||||||
/* Composer */
|
/* Composer */
|
||||||
char *composer;
|
const char *composer;
|
||||||
/* Performer */
|
/* Performer */
|
||||||
char *performer;
|
const char *performer;
|
||||||
/* Disc */
|
/* Disc */
|
||||||
char *disc;
|
const char *disc;
|
||||||
/* Comment */
|
/* Comment */
|
||||||
char *comment;
|
const char *comment;
|
||||||
|
|
||||||
/* length of song in seconds, check that it is not MPD_SONG_NO_TIME */
|
/* length of song in seconds, check that it is not MPD_SONG_NO_TIME */
|
||||||
int time;
|
int time;
|
||||||
@@ -324,7 +324,7 @@ mpd_Song * mpd_songDup(mpd_Song * song);
|
|||||||
* used to store info fro directory (right now that just the path)
|
* used to store info fro directory (right now that just the path)
|
||||||
*/
|
*/
|
||||||
typedef struct _mpd_Directory {
|
typedef struct _mpd_Directory {
|
||||||
char * path;
|
const char * path;
|
||||||
} mpd_Directory;
|
} mpd_Directory;
|
||||||
|
|
||||||
/* mpd_newDirectory
|
/* mpd_newDirectory
|
||||||
@@ -350,7 +350,7 @@ mpd_Directory * mpd_directoryDup(mpd_Directory * directory);
|
|||||||
* stores info about playlist file returned by lsinfo
|
* stores info about playlist file returned by lsinfo
|
||||||
*/
|
*/
|
||||||
typedef struct _mpd_PlaylistFile {
|
typedef struct _mpd_PlaylistFile {
|
||||||
char * path;
|
const char * path;
|
||||||
} mpd_PlaylistFile;
|
} mpd_PlaylistFile;
|
||||||
|
|
||||||
/* mpd_newPlaylistFile
|
/* mpd_newPlaylistFile
|
||||||
|
|||||||
@@ -494,7 +494,7 @@ void MPD::Song::SetHashAndSlash()
|
|||||||
{
|
{
|
||||||
if (!itsSong->file)
|
if (!itsSong->file)
|
||||||
return;
|
return;
|
||||||
char *tmp = strrchr(itsSong->file, '/');
|
const char *tmp = strrchr(itsSong->file, '/');
|
||||||
itsSlash = tmp && *(tmp-1) != '/' /* no http:// */ ? tmp-itsSong->file : std::string::npos;
|
itsSlash = tmp && *(tmp-1) != '/' /* no http:// */ ? tmp-itsSong->file : std::string::npos;
|
||||||
itsHash = calc_hash(itsSong->file);
|
itsHash = calc_hash(itsSong->file);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ static struct slot *slot_alloc(struct slot *next, const char *value)
|
|||||||
return slot;
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *str_pool_get(const char *value)
|
const char *str_pool_get(const char *value)
|
||||||
{
|
{
|
||||||
struct slot **slot_p, *slot;
|
struct slot **slot_p, *slot;
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ char *str_pool_get(const char *value)
|
|||||||
return slot->value;
|
return slot->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *str_pool_dup(const char *value)
|
const char *str_pool_dup(const char *value)
|
||||||
{
|
{
|
||||||
struct slot *slot = value_to_slot(value);
|
struct slot *slot = value_to_slot(value);
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ char *str_pool_dup(const char *value)
|
|||||||
|
|
||||||
if (slot->ref < 0xff) {
|
if (slot->ref < 0xff) {
|
||||||
++slot->ref;
|
++slot->ref;
|
||||||
return (char *) value;
|
return value;
|
||||||
} else {
|
} else {
|
||||||
/* the reference counter overflows above 0xff;
|
/* the reference counter overflows above 0xff;
|
||||||
duplicate the value, and start with 1 */
|
duplicate the value, and start with 1 */
|
||||||
@@ -103,7 +103,7 @@ char *str_pool_dup(const char *value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void str_pool_put(char *value)
|
void str_pool_put(const char *value)
|
||||||
{
|
{
|
||||||
struct slot **slot_p, *slot;
|
struct slot **slot_p, *slot;
|
||||||
|
|
||||||
|
|||||||
@@ -25,11 +25,11 @@ extern "C" {
|
|||||||
|
|
||||||
unsigned calc_hash(const char *p);
|
unsigned calc_hash(const char *p);
|
||||||
|
|
||||||
char *str_pool_get(const char *value);
|
const char *str_pool_get(const char *value);
|
||||||
|
|
||||||
char *str_pool_dup(const char *value);
|
const char *str_pool_dup(const char *value);
|
||||||
|
|
||||||
void str_pool_put(char *value);
|
void str_pool_put(const char *value);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user