diff options
author | Max Kellermann <max@duempel.org> | 2014-12-04 17:43:01 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-12-04 17:43:01 +0100 |
commit | 4e2f4e2091103ea571602c444642ff04c2bf5a2f (patch) | |
tree | c9673af59272ac77d3ee594e79e7bacb462b1f2c /src | |
parent | e69bef3ce389967b8239648e4b9eaec42217bc95 (diff) | |
download | mpd-4e2f4e2091103ea571602c444642ff04c2bf5a2f.tar.gz mpd-4e2f4e2091103ea571602c444642ff04c2bf5a2f.tar.xz mpd-4e2f4e2091103ea571602c444642ff04c2bf5a2f.zip |
util/StringUtil: add ToUpperASCII()
Replaces g_ascii_strup() and allows building the Vorbis encoder
without GLib.
Diffstat (limited to 'src')
-rw-r--r-- | src/encoder/plugins/VorbisEncoderPlugin.cxx | 7 | ||||
-rw-r--r-- | src/util/StringUtil.cxx | 20 | ||||
-rw-r--r-- | src/util/StringUtil.hxx | 8 |
3 files changed, 31 insertions, 4 deletions
diff --git a/src/encoder/plugins/VorbisEncoderPlugin.cxx b/src/encoder/plugins/VorbisEncoderPlugin.cxx index 3cc941220..01c9910a0 100644 --- a/src/encoder/plugins/VorbisEncoderPlugin.cxx +++ b/src/encoder/plugins/VorbisEncoderPlugin.cxx @@ -25,14 +25,13 @@ #include "tag/Tag.hxx" #include "AudioFormat.hxx" #include "config/ConfigError.hxx" +#include "util/StringUtil.hxx" #include "util/NumberParser.hxx" #include "util/Error.hxx" #include "util/Domain.hxx" #include <vorbis/vorbisenc.h> -#include <glib.h> - struct vorbis_encoder { /** the base class */ Encoder encoder; @@ -273,9 +272,9 @@ static void copy_tag_to_vorbis_comment(vorbis_comment *vc, const Tag &tag) { for (const auto &item : tag) { - char *name = g_ascii_strup(tag_item_names[item.type], -1); + char name[64]; + ToUpperASCII(name, tag_item_names[item.type], sizeof(name)); vorbis_comment_add_tag(vc, name, item.value); - g_free(name); } } diff --git a/src/util/StringUtil.cxx b/src/util/StringUtil.cxx index bcade2b3b..f5b4b7a8b 100644 --- a/src/util/StringUtil.cxx +++ b/src/util/StringUtil.cxx @@ -120,3 +120,23 @@ string_array_contains(const char *const* haystack, const char *needle) return false; } + +void +ToUpperASCII(char *dest, const char *src, size_t size) +{ + assert(dest != nullptr); + assert(src != nullptr); + assert(size > 1); + + char *const end = dest + size - 1; + + do { + char ch = *src++; + if (ch == 0) + break; + + *dest++ = ToUpperASCII(ch); + } while (dest < end); + + *dest = 0; +} diff --git a/src/util/StringUtil.hxx b/src/util/StringUtil.hxx index 9beda5441..77fe1be18 100644 --- a/src/util/StringUtil.hxx +++ b/src/util/StringUtil.hxx @@ -114,4 +114,12 @@ gcc_pure bool string_array_contains(const char *const* haystack, const char *needle); +/** + * Convert the specified ASCII string (0x00..0x7f) to upper case. + * + * @param size the destination buffer size + */ +void +ToUpperASCII(char *dest, const char *src, size_t size); + #endif |