util/StringCompare: add StringIsEmpty()
This commit is contained in:
parent
42f5ecd4a1
commit
c880099deb
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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] == '/'));
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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) ||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user