playlist/pls: use std::string instead of GString

This commit is contained in:
Max Kellermann 2013-08-06 09:32:08 +02:00
parent 3f04a4d635
commit 132971f8eb

View File

@ -26,6 +26,8 @@
#include <glib.h> #include <glib.h>
#include <string>
static void static void
pls_parser(GKeyFile *keyfile, std::forward_list<SongPointer> &songs) pls_parser(GKeyFile *keyfile, std::forward_list<SongPointer> &songs)
{ {
@ -106,14 +108,14 @@ pls_open_stream(struct input_stream *is)
char buffer[1024]; char buffer[1024];
bool success; bool success;
GKeyFile *keyfile; GKeyFile *keyfile;
GString *kf_data = g_string_new("");
std::string kf_data;
do { do {
nbytes = input_stream_lock_read(is, buffer, sizeof(buffer), nbytes = input_stream_lock_read(is, buffer, sizeof(buffer),
&error); &error);
if (nbytes == 0) { if (nbytes == 0) {
if (error != NULL) { if (error != NULL) {
g_string_free(kf_data, TRUE);
g_warning("%s", error->message); g_warning("%s", error->message);
g_error_free(error); g_error_free(error);
return NULL; return NULL;
@ -122,23 +124,20 @@ pls_open_stream(struct input_stream *is)
break; break;
} }
kf_data = g_string_append_len(kf_data, buffer,nbytes); kf_data.append(buffer, nbytes);
/* Limit to 64k */ /* Limit to 64k */
} while(kf_data->len < 65536); } while (kf_data.length() < 65536);
if (kf_data->len == 0) { if (kf_data.empty()) {
g_warning("KeyFile parser failed: No Data"); g_warning("KeyFile parser failed: No Data");
g_string_free(kf_data, TRUE);
return NULL; return NULL;
} }
keyfile = g_key_file_new(); keyfile = g_key_file_new();
success = g_key_file_load_from_data(keyfile, success = g_key_file_load_from_data(keyfile,
kf_data->str, kf_data->len, kf_data.data(), kf_data.length(),
G_KEY_FILE_NONE, &error); G_KEY_FILE_NONE, &error);
g_string_free(kf_data, TRUE);
if (!success) { if (!success) {
g_warning("KeyFile parser failed: %s", error->message); g_warning("KeyFile parser failed: %s", error->message);
g_error_free(error); g_error_free(error);