diff options
author | Max Kellermann <max@duempel.org> | 2013-10-17 22:47:09 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-10-17 22:47:09 +0200 |
commit | 7fec2b02d419ab1de5589fb34d4fad90e9998aab (patch) | |
tree | a69e1f46c54aa0e3c3f2f1e1098bc2dc78df97a2 | |
parent | 608a98c873b94826a98b8dbdf17aa02320de8776 (diff) | |
download | mpd-7fec2b02d419ab1de5589fb34d4fad90e9998aab.tar.gz mpd-7fec2b02d419ab1de5589fb34d4fad90e9998aab.tar.xz mpd-7fec2b02d419ab1de5589fb34d4fad90e9998aab.zip |
fs/Charset: GetFSCharset() returns "utf-8" by default
If fs_charset is empty, i.e. we're using the default "utf-8",
GetFSCharset() should return exactly that instead of an empty
std::string.
-rw-r--r-- | src/DatabaseSave.cxx | 11 | ||||
-rw-r--r-- | src/fs/Charset.cxx | 4 | ||||
-rw-r--r-- | src/fs/Charset.hxx | 2 |
3 files changed, 8 insertions, 9 deletions
diff --git a/src/DatabaseSave.cxx b/src/DatabaseSave.cxx index 67df236ef..b7077b413 100644 --- a/src/DatabaseSave.cxx +++ b/src/DatabaseSave.cxx @@ -56,8 +56,7 @@ db_save_internal(FILE *fp, const Directory *music_root) fprintf(fp, "%s\n", DIRECTORY_INFO_BEGIN); fprintf(fp, DB_FORMAT_PREFIX "%u\n", DB_FORMAT); fprintf(fp, "%s%s\n", DIRECTORY_MPD_VERSION, VERSION); - fprintf(fp, "%s%s\n", DIRECTORY_FS_CHARSET, - GetFSCharset().c_str()); + fprintf(fp, "%s%s\n", DIRECTORY_FS_CHARSET, GetFSCharset()); for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) if (!ignore_tag_items[i]) @@ -110,14 +109,14 @@ db_load_internal(TextFile &file, Directory *music_root, Error &error) found_charset = true; new_charset = line + sizeof(DIRECTORY_FS_CHARSET) - 1; - const std::string &old_charset = GetFSCharset(); - if (!old_charset.empty() - && strcmp(new_charset, old_charset.c_str())) { + const char *const old_charset = GetFSCharset(); + if (*old_charset != 0 + && strcmp(new_charset, old_charset) != 0) { error.Format(db_domain, "Existing database has charset " "\"%s\" instead of \"%s\"; " "discarding database file", - new_charset, old_charset.c_str()); + new_charset, old_charset); return false; } } else if (g_str_has_prefix(line, DB_TAG_PREFIX)) { diff --git a/src/fs/Charset.cxx b/src/fs/Charset.cxx index 3e324f470..39bb36e77 100644 --- a/src/fs/Charset.cxx +++ b/src/fs/Charset.cxx @@ -70,10 +70,10 @@ SetFSCharset(const char *charset) "SetFSCharset: fs charset is: %s", fs_charset.c_str()); } -const std::string & +const char * GetFSCharset() { - return fs_charset; + return fs_charset.empty() ? "utf-8" : fs_charset.c_str(); } std::string diff --git a/src/fs/Charset.hxx b/src/fs/Charset.hxx index 19dabeb2b..a89cb0459 100644 --- a/src/fs/Charset.hxx +++ b/src/fs/Charset.hxx @@ -29,7 +29,7 @@ * Gets file system character set name. */ gcc_const -const std::string & +const char * GetFSCharset(); void |