text_input_stream: convert to class
This commit is contained in:
@@ -24,10 +24,7 @@
|
||||
#include "song.h"
|
||||
#include "input_stream.h"
|
||||
#include "cue/CueParser.hxx"
|
||||
|
||||
extern "C" {
|
||||
#include "text_input_stream.h"
|
||||
}
|
||||
#include "TextInputStream.hxx"
|
||||
|
||||
#include <glib.h>
|
||||
#include <assert.h>
|
||||
@@ -40,16 +37,15 @@ struct CuePlaylist {
|
||||
struct playlist_provider base;
|
||||
|
||||
struct input_stream *is;
|
||||
struct text_input_stream *tis;
|
||||
TextInputStream tis;
|
||||
CueParser parser;
|
||||
|
||||
CuePlaylist(struct input_stream *_is)
|
||||
:is(_is), tis(text_input_stream_new(is)) {
|
||||
:is(_is), tis(is) {
|
||||
playlist_provider_init(&base, &cue_playlist_plugin);
|
||||
}
|
||||
|
||||
~CuePlaylist() {
|
||||
text_input_stream_free(tis);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -76,9 +72,9 @@ cue_playlist_read(struct playlist_provider *_playlist)
|
||||
if (song != NULL)
|
||||
return song;
|
||||
|
||||
const char *line;
|
||||
while ((line = text_input_stream_read(playlist->tis)) != NULL) {
|
||||
playlist->parser.Feed(line);
|
||||
std::string line;
|
||||
while (playlist->tis.ReadLine(line)) {
|
||||
playlist->parser.Feed(line.c_str());
|
||||
song = playlist->parser.Get();
|
||||
if (song != NULL)
|
||||
return song;
|
||||
|
@@ -23,10 +23,7 @@
|
||||
#include "song.h"
|
||||
#include "tag.h"
|
||||
#include "util/StringUtil.hxx"
|
||||
|
||||
extern "C" {
|
||||
#include "text_input_stream.h"
|
||||
}
|
||||
#include "TextInputStream.hxx"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
@@ -36,20 +33,21 @@ extern "C" {
|
||||
struct ExtM3uPlaylist {
|
||||
struct playlist_provider base;
|
||||
|
||||
struct text_input_stream *tis;
|
||||
TextInputStream *tis;
|
||||
};
|
||||
|
||||
static struct playlist_provider *
|
||||
extm3u_open_stream(struct input_stream *is)
|
||||
{
|
||||
ExtM3uPlaylist *playlist = g_new(ExtM3uPlaylist, 1);
|
||||
playlist->tis = text_input_stream_new(is);
|
||||
playlist->tis = new TextInputStream(is);
|
||||
|
||||
const char *line = text_input_stream_read(playlist->tis);
|
||||
if (line == NULL || strcmp(line, "#EXTM3U") != 0) {
|
||||
std::string line;
|
||||
if (!playlist->tis->ReadLine(line)
|
||||
|| strcmp(line.c_str(), "#EXTM3U") != 0) {
|
||||
/* no EXTM3U header: fall back to the plain m3u
|
||||
plugin */
|
||||
text_input_stream_free(playlist->tis);
|
||||
delete playlist->tis;
|
||||
g_free(playlist);
|
||||
return NULL;
|
||||
}
|
||||
@@ -63,7 +61,7 @@ extm3u_close(struct playlist_provider *_playlist)
|
||||
{
|
||||
ExtM3uPlaylist *playlist = (ExtM3uPlaylist *)_playlist;
|
||||
|
||||
text_input_stream_free(playlist->tis);
|
||||
delete playlist->tis;
|
||||
g_free(playlist);
|
||||
}
|
||||
|
||||
@@ -112,29 +110,31 @@ extm3u_read(struct playlist_provider *_playlist)
|
||||
{
|
||||
ExtM3uPlaylist *playlist = (ExtM3uPlaylist *)_playlist;
|
||||
struct tag *tag = NULL;
|
||||
const char *line;
|
||||
std::string line;
|
||||
const char *line_s;
|
||||
struct song *song;
|
||||
|
||||
do {
|
||||
line = text_input_stream_read(playlist->tis);
|
||||
if (line == NULL) {
|
||||
if (!playlist->tis->ReadLine(line)) {
|
||||
if (tag != NULL)
|
||||
tag_free(tag);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
line_s = line.c_str();
|
||||
|
||||
if (g_str_has_prefix(line, "#EXTINF:")) {
|
||||
if (g_str_has_prefix(line_s, "#EXTINF:")) {
|
||||
if (tag != NULL)
|
||||
tag_free(tag);
|
||||
tag = extm3u_parse_tag(line + 8);
|
||||
tag = extm3u_parse_tag(line_s + 8);
|
||||
continue;
|
||||
}
|
||||
|
||||
while (*line != 0 && g_ascii_isspace(*line))
|
||||
++line;
|
||||
} while (line[0] == '#' || *line == 0);
|
||||
while (*line_s != 0 && g_ascii_isspace(*line_s))
|
||||
++line_s;
|
||||
} while (line_s[0] == '#' || *line_s == 0);
|
||||
|
||||
song = song_remote_new(line);
|
||||
song = song_remote_new(line_s);
|
||||
song->tag = tag;
|
||||
return song;
|
||||
}
|
||||
|
@@ -21,17 +21,14 @@
|
||||
#include "M3uPlaylistPlugin.hxx"
|
||||
#include "PlaylistPlugin.hxx"
|
||||
#include "song.h"
|
||||
|
||||
extern "C" {
|
||||
#include "text_input_stream.h"
|
||||
}
|
||||
#include "TextInputStream.hxx"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
struct M3uPlaylist {
|
||||
struct playlist_provider base;
|
||||
|
||||
struct text_input_stream *tis;
|
||||
TextInputStream *tis;
|
||||
};
|
||||
|
||||
static struct playlist_provider *
|
||||
@@ -40,7 +37,7 @@ m3u_open_stream(struct input_stream *is)
|
||||
M3uPlaylist *playlist = g_new(M3uPlaylist, 1);
|
||||
|
||||
playlist_provider_init(&playlist->base, &m3u_playlist_plugin);
|
||||
playlist->tis = text_input_stream_new(is);
|
||||
playlist->tis = new TextInputStream(is);
|
||||
|
||||
return &playlist->base;
|
||||
}
|
||||
@@ -50,7 +47,7 @@ m3u_close(struct playlist_provider *_playlist)
|
||||
{
|
||||
M3uPlaylist *playlist = (M3uPlaylist *)_playlist;
|
||||
|
||||
text_input_stream_free(playlist->tis);
|
||||
delete playlist->tis;
|
||||
g_free(playlist);
|
||||
}
|
||||
|
||||
@@ -58,18 +55,20 @@ static struct song *
|
||||
m3u_read(struct playlist_provider *_playlist)
|
||||
{
|
||||
M3uPlaylist *playlist = (M3uPlaylist *)_playlist;
|
||||
const char *line;
|
||||
std::string line;
|
||||
const char *line_s;
|
||||
|
||||
do {
|
||||
line = text_input_stream_read(playlist->tis);
|
||||
if (line == NULL)
|
||||
if (!playlist->tis->ReadLine(line))
|
||||
return NULL;
|
||||
|
||||
while (*line != 0 && g_ascii_isspace(*line))
|
||||
++line;
|
||||
} while (line[0] == '#' || *line == 0);
|
||||
line_s = line.c_str();
|
||||
|
||||
return song_remote_new(line);
|
||||
while (*line_s != 0 && g_ascii_isspace(*line_s))
|
||||
++line_s;
|
||||
} while (line_s[0] == '#' || *line_s == 0);
|
||||
|
||||
return song_remote_new(line_s);
|
||||
}
|
||||
|
||||
static const char *const m3u_suffixes[] = {
|
||||
|
Reference in New Issue
Block a user