util/StringView: new utility class

This commit is contained in:
Max Kellermann
2015-09-30 22:03:01 +02:00
parent ffbb5c48ed
commit 356c829b76
18 changed files with 208 additions and 111 deletions

View File

@@ -24,6 +24,7 @@
#include "TagTable.hxx"
#include "TagHandler.hxx"
#include "fs/Path.hxx"
#include "util/StringView.hxx"
#include <string>
@@ -75,17 +76,18 @@ ForEachValue(const char *value, const char *end, C &&callback)
*/
static bool
tag_ape_import_item(unsigned long flags,
const char *key, const char *value, size_t value_length,
const char *key, StringView value,
const struct tag_handler *handler, void *handler_ctx)
{
/* we only care about utf-8 text tags */
if ((flags & (0x3 << 1)) != 0)
return false;
const char *const end = value + value_length;
const auto begin = value.begin();
const auto end = value.end();
if (handler->pair != nullptr)
ForEachValue(value, end, [handler, handler_ctx,
ForEachValue(begin, end, [handler, handler_ctx,
key](const char *_value) {
handler->pair(key, _value, handler_ctx);
});
@@ -94,8 +96,8 @@ tag_ape_import_item(unsigned long flags,
if (type == TAG_NUM_OF_ITEM_TYPES)
return false;
ForEachValue(value, end, [handler, handler_ctx,
type](const char *_value) {
ForEachValue(begin, end, [handler, handler_ctx,
type](const char *_value) {
tag_handler_invoke_tag(handler, handler_ctx,
type, _value);
});
@@ -111,10 +113,8 @@ tag_ape_scan2(Path path_fs,
auto callback = [handler, handler_ctx, &recognized]
(unsigned long flags, const char *key,
const char *value,
size_t value_length) {
StringView value) {
recognized |= tag_ape_import_item(flags, key, value,
value_length,
handler, handler_ctx);
return true;
};