Commit 222dc8a2 authored by Max Kellermann's avatar Max Kellermann

Util/ASCII: add StringEqualsCaseASCII() overload with length

Replaces GLib's g_ascii_strncasecmp().
parent 0e4d2e72
......@@ -25,6 +25,7 @@
#include "tag/TagTable.hxx"
#include "tag/TagBuilder.hxx"
#include "ReplayGainInfo.hxx"
#include "util/ASCII.hxx"
#include <glib.h>
......@@ -135,7 +136,7 @@ flac_comment_value(const FLAC__StreamMetadata_VorbisComment_Entry *entry,
const char *comment = (const char*)entry->entry;
if (entry->length <= name_length ||
g_ascii_strncasecmp(comment, name, name_length) != 0)
StringEqualsCaseASCII(comment, name, name_length))
return nullptr;
if (comment[name_length] == '=') {
......
......@@ -25,6 +25,7 @@
#include "tag/TagHandler.hxx"
#include "tag/TagBuilder.hxx"
#include "ReplayGainInfo.hxx"
#include "util/ASCII.hxx"
#include <glib.h>
......@@ -38,7 +39,7 @@ vorbis_comment_value(const char *comment, const char *needle)
{
size_t len = strlen(needle);
if (g_ascii_strncasecmp(comment, needle, len) == 0 &&
if (StringEqualsCaseASCII(comment, needle, len) &&
comment[len] == '=')
return comment + len + 1;
......
......@@ -21,12 +21,11 @@
#include "MixerInternal.hxx"
#include "OutputAPI.hxx"
#include "system/fd_util.h"
#include "util/ASCII.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h>
#include <assert.h>
#include <string.h>
#include <sys/stat.h>
......@@ -71,7 +70,7 @@ oss_find_mixer(const char *name)
size_t name_length = strlen(name);
for (unsigned i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
if (g_ascii_strncasecmp(name, labels[i], name_length) == 0 &&
if (StringEqualsCaseASCII(name, labels[i], name_length) &&
(labels[i][name_length] == 0 ||
labels[i][name_length] == ' '))
return i;
......
......@@ -20,7 +20,7 @@
#include "config.h"
#include "HttpdClient.hxx"
#include "HttpdInternal.hxx"
#include "util/fifo_buffer.h"
#include "util/ASCII.hxx"
#include "Page.hxx"
#include "IcyMetaDataServer.hxx"
#include "system/SocketError.hxx"
......@@ -102,13 +102,13 @@ HttpdClient::HandleLine(const char *line)
return true;
}
if (g_ascii_strncasecmp(line, "Icy-MetaData: 1", 15) == 0) {
if (StringEqualsCaseASCII(line, "Icy-MetaData: 1", 15)) {
/* Send icy metadata */
metadata_requested = metadata_supported;
return true;
}
if (g_ascii_strncasecmp(line, "transferMode.dlna.org: Streaming", 32) == 0) {
if (StringEqualsCaseASCII(line, "transferMode.dlna.org: Streaming", 32)) {
/* Send as dlna */
dlna_streaming_requested = true;
/* metadata is not supported by dlna streaming, so disable it */
......
......@@ -19,12 +19,11 @@
#include "config.h"
#include "PcmResampleInternal.hxx"
#include "util/ASCII.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include <glib.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
......@@ -54,7 +53,7 @@ lsr_parse_converter(const char *s)
if (name == nullptr)
break;
if (g_ascii_strncasecmp(s, name, length) == 0) {
if (StringEqualsCaseASCII(s, name, length)) {
lsr_converter = i;
return true;
}
......
......@@ -51,4 +51,16 @@ StringEqualsCaseASCII(const char *a, const char *b)
return strcasecmp(a, b) == 0;
}
gcc_pure gcc_nonnull_all
static inline bool
StringEqualsCaseASCII(const char *a, const char *b, size_t n)
{
assert(a != nullptr);
assert(b != nullptr);
/* note: strcasecmp() depends on the locale, but for ASCII-only
strings, it's safe to use */
return strncasecmp(a, b, n) == 0;
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment