aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-11-06 09:37:07 +0100
committerMax Kellermann <max@duempel.org>2015-11-06 09:37:07 +0100
commitc880099deb41c09ea7844daa27a42dac4142c0cd (patch)
tree571482d1e6e7efc95ab7d443f246232188d3c23f
parent42f5ecd4a116c96d30bf407859dadaa9a053ea39 (diff)
downloadmpd-c880099deb41c09ea7844daa27a42dac4142c0cd.tar.gz
mpd-c880099deb41c09ea7844daa27a42dac4142c0cd.tar.xz
mpd-c880099deb41c09ea7844daa27a42dac4142c0cd.zip
util/StringCompare: add StringIsEmpty()
-rw-r--r--src/Mapper.cxx3
-rw-r--r--src/PlaylistFile.cxx2
-rw-r--r--src/db/update/Archive.cxx3
-rw-r--r--src/db/update/InotifyQueue.cxx3
-rw-r--r--src/db/update/Walk.cxx3
-rw-r--r--src/input/plugins/AlsaInputPlugin.cxx2
-rw-r--r--src/sticker/StickerDatabase.cxx5
-rw-r--r--src/storage/CompositeStorage.cxx3
-rw-r--r--src/storage/plugins/LocalStorage.cxx7
-rw-r--r--src/storage/plugins/NfsStorage.cxx5
-rw-r--r--src/storage/plugins/SmbclientStorage.cxx5
-rw-r--r--src/util/StringCompare.hxx6
-rw-r--r--src/util/WStringCompare.hxx6
13 files changed, 37 insertions, 16 deletions
diff --git a/src/Mapper.cxx b/src/Mapper.cxx
index 15d706922..7e326b421 100644
--- a/src/Mapper.cxx
+++ b/src/Mapper.cxx
@@ -27,6 +27,7 @@
#include "fs/Traits.hxx"
#include "fs/Charset.hxx"
#include "fs/CheckFile.hxx"
+#include "util/StringCompare.hxx"
#ifdef ENABLE_DATABASE
#include "storage/StorageInterface.hxx"
@@ -98,7 +99,7 @@ map_fs_to_utf8(Path path_fs)
return std::string();
auto relative = music_dir_fs.Relative(path_fs);
- if (relative == nullptr || *relative == 0)
+ if (relative == nullptr || StringIsEmpty(relative))
return std::string();
path_fs = Path::FromFS(relative);
diff --git a/src/PlaylistFile.cxx b/src/PlaylistFile.cxx
index 911a4fc17..d8c15841b 100644
--- a/src/PlaylistFile.cxx
+++ b/src/PlaylistFile.cxx
@@ -70,7 +70,7 @@ spl_global_init(void)
bool
spl_valid_name(const char *name_utf8)
{
- if (*name_utf8 == 0)
+ if (StringIsEmpty(name_utf8))
/* empty name not allowed */
return false;
diff --git a/src/db/update/Archive.cxx b/src/db/update/Archive.cxx
index e818ab279..78ebbdb10 100644
--- a/src/db/update/Archive.cxx
+++ b/src/db/update/Archive.cxx
@@ -31,6 +31,7 @@
#include "archive/ArchiveFile.hxx"
#include "archive/ArchiveVisitor.hxx"
#include "util/Error.hxx"
+#include "util/StringCompare.hxx"
#include "Log.hxx"
#include <string>
@@ -54,7 +55,7 @@ UpdateWalk::UpdateArchiveTree(Directory &directory, const char *name)
//create directories first
UpdateArchiveTree(*subdir, tmp + 1);
} else {
- if (strlen(name) == 0) {
+ if (StringIsEmpty(name)) {
LogWarning(update_domain,
"archive returned directory only");
return;
diff --git a/src/db/update/InotifyQueue.cxx b/src/db/update/InotifyQueue.cxx
index 4b5269427..392ac4110 100644
--- a/src/db/update/InotifyQueue.cxx
+++ b/src/db/update/InotifyQueue.cxx
@@ -22,6 +22,7 @@
#include "InotifyDomain.hxx"
#include "Service.hxx"
#include "Log.hxx"
+#include "util/StringCompare.hxx"
#include <string.h>
@@ -59,7 +60,7 @@ path_in(const char *path, const char *possible_parent)
{
size_t length = strlen(possible_parent);
- return path[0] == 0 ||
+ return StringIsEmpty(path) ||
(memcmp(possible_parent, path, length) == 0 &&
(path[length] == 0 || path[length] == '/'));
}
diff --git a/src/db/update/Walk.cxx b/src/db/update/Walk.cxx
index 3e5654a3c..38c6df71d 100644
--- a/src/db/update/Walk.cxx
+++ b/src/db/update/Walk.cxx
@@ -38,6 +38,7 @@
#include "fs/Charset.hxx"
#include "storage/FileInfo.hxx"
#include "util/Alloc.hxx"
+#include "util/StringCompare.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
@@ -435,7 +436,7 @@ UpdateWalk::DirectoryMakeUriParentChecked(Directory &root, const char *uri)
while ((slash = strchr(name_utf8, '/')) != nullptr) {
*slash = 0;
- if (*name_utf8 == 0)
+ if (StringIsEmpty(name_utf8))
continue;
directory = DirectoryMakeChildChecked(*directory,
diff --git a/src/input/plugins/AlsaInputPlugin.cxx b/src/input/plugins/AlsaInputPlugin.cxx
index ea428c0ca..f39574e43 100644
--- a/src/input/plugins/AlsaInputPlugin.cxx
+++ b/src/input/plugins/AlsaInputPlugin.cxx
@@ -164,7 +164,7 @@ AlsaInputStream::Create(const char *uri, Mutex &mutex, Cond &cond,
return nullptr;
const char *device = uri + strlen(scheme);
- if (strlen(device) == 0)
+ if (*device == 0)
device = default_device;
/* placeholders - eventually user-requested audio format will
diff --git a/src/sticker/StickerDatabase.cxx b/src/sticker/StickerDatabase.cxx
index 02eed362e..6aea88b0c 100644
--- a/src/sticker/StickerDatabase.cxx
+++ b/src/sticker/StickerDatabase.cxx
@@ -25,6 +25,7 @@
#include "Idle.hxx"
#include "util/Error.hxx"
#include "util/Macros.hxx"
+#include "util/StringCompare.hxx"
#include <string>
#include <map>
@@ -178,7 +179,7 @@ sticker_load_value(const char *type, const char *uri, const char *name,
assert(uri != nullptr);
assert(name != nullptr);
- if (*name == 0)
+ if (StringIsEmpty(name))
return std::string();
if (!BindAll(error, stmt, type, uri, name))
@@ -287,7 +288,7 @@ sticker_store_value(const char *type, const char *uri,
assert(name != nullptr);
assert(value != nullptr);
- if (*name == 0)
+ if (StringIsEmpty(name))
return false;
return sticker_update_value(type, uri, name, value, error) ||
diff --git a/src/storage/CompositeStorage.cxx b/src/storage/CompositeStorage.cxx
index 10a478c0d..eb3a9546f 100644
--- a/src/storage/CompositeStorage.cxx
+++ b/src/storage/CompositeStorage.cxx
@@ -23,6 +23,7 @@
#include "fs/AllocatedPath.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
+#include "util/StringCompare.hxx"
#include <set>
@@ -164,7 +165,7 @@ CompositeStorage::Directory::Unmount()
bool
CompositeStorage::Directory::Unmount(const char *uri)
{
- if (*uri == 0)
+ if (StringIsEmpty(uri))
return Unmount();
const std::string name = NextSegment(uri);
diff --git a/src/storage/plugins/LocalStorage.cxx b/src/storage/plugins/LocalStorage.cxx
index 83903ec81..b35161dd1 100644
--- a/src/storage/plugins/LocalStorage.cxx
+++ b/src/storage/plugins/LocalStorage.cxx
@@ -22,10 +22,11 @@
#include "storage/StoragePlugin.hxx"
#include "storage/StorageInterface.hxx"
#include "storage/FileInfo.hxx"
-#include "util/Error.hxx"
#include "fs/FileInfo.hxx"
#include "fs/AllocatedPath.hxx"
#include "fs/DirectoryReader.hxx"
+#include "util/Error.hxx"
+#include "util/StringCompare.hxx"
#include <string>
@@ -108,7 +109,7 @@ LocalStorage::MapUTF8(const char *uri_utf8) const
{
assert(uri_utf8 != nullptr);
- if (*uri_utf8 == 0)
+ if (StringIsEmpty(uri_utf8))
return base_utf8;
return PathTraitsUTF8::Build(base_utf8.c_str(), uri_utf8);
@@ -119,7 +120,7 @@ LocalStorage::MapFS(const char *uri_utf8, Error &error) const
{
assert(uri_utf8 != nullptr);
- if (*uri_utf8 == 0)
+ if (StringIsEmpty(uri_utf8))
return base_fs;
AllocatedPath path_fs = AllocatedPath::FromUTF8(uri_utf8, error);
diff --git a/src/storage/plugins/NfsStorage.cxx b/src/storage/plugins/NfsStorage.cxx
index fc4fd5c07..517e0c93a 100644
--- a/src/storage/plugins/NfsStorage.cxx
+++ b/src/storage/plugins/NfsStorage.cxx
@@ -30,13 +30,14 @@
#include "lib/nfs/Connection.hxx"
#include "lib/nfs/Glue.hxx"
#include "fs/AllocatedPath.hxx"
-#include "util/Error.hxx"
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
#include "event/Loop.hxx"
#include "event/Call.hxx"
#include "event/DeferredMonitor.hxx"
#include "event/TimeoutMonitor.hxx"
+#include "util/Error.hxx"
+#include "util/StringCompare.hxx"
extern "C" {
#include <nfsc/libnfs.h>
@@ -232,7 +233,7 @@ NfsStorage::MapUTF8(const char *uri_utf8) const
{
assert(uri_utf8 != nullptr);
- if (*uri_utf8 == 0)
+ if (StringIsEmpty(uri_utf8))
return base;
return PathTraitsUTF8::Build(base.c_str(), uri_utf8);
diff --git a/src/storage/plugins/SmbclientStorage.cxx b/src/storage/plugins/SmbclientStorage.cxx
index 84b212cd1..a3d392a8a 100644
--- a/src/storage/plugins/SmbclientStorage.cxx
+++ b/src/storage/plugins/SmbclientStorage.cxx
@@ -25,8 +25,9 @@
#include "lib/smbclient/Init.hxx"
#include "lib/smbclient/Mutex.hxx"
#include "fs/Traits.hxx"
-#include "util/Error.hxx"
#include "thread/Mutex.hxx"
+#include "util/Error.hxx"
+#include "util/StringCompare.hxx"
#include <libsmbclient.h>
@@ -80,7 +81,7 @@ SmbclientStorage::MapUTF8(const char *uri_utf8) const
{
assert(uri_utf8 != nullptr);
- if (*uri_utf8 == 0)
+ if (StringIsEmpty(uri_utf8))
return base;
return PathTraitsUTF8::Build(base.c_str(), uri_utf8);
diff --git a/src/util/StringCompare.hxx b/src/util/StringCompare.hxx
index 2c23b312f..a29892bc9 100644
--- a/src/util/StringCompare.hxx
+++ b/src/util/StringCompare.hxx
@@ -36,6 +36,12 @@
#include "WStringCompare.hxx"
#endif
+static inline bool
+StringIsEmpty(const char *string)
+{
+ return *string == 0;
+}
+
gcc_pure
bool
StringStartsWith(const char *haystack, const char *needle);
diff --git a/src/util/WStringCompare.hxx b/src/util/WStringCompare.hxx
index 3547076ca..bddd62120 100644
--- a/src/util/WStringCompare.hxx
+++ b/src/util/WStringCompare.hxx
@@ -34,6 +34,12 @@
#include <wchar.h>
+static inline bool
+StringIsEmpty(const wchar_t *string)
+{
+ return *string == 0;
+}
+
gcc_pure
bool
StringStartsWith(const wchar_t *haystack, const wchar_t *needle);