From 4e2f4e2091103ea571602c444642ff04c2bf5a2f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 4 Dec 2014 17:43:01 +0100 Subject: util/StringUtil: add ToUpperASCII() Replaces g_ascii_strup() and allows building the Vorbis encoder without GLib. --- src/util/StringUtil.cxx | 20 ++++++++++++++++++++ src/util/StringUtil.hxx | 8 ++++++++ 2 files changed, 28 insertions(+) (limited to 'src/util') 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 -- cgit v1.2.3