diff options
author | Denis Krjuchkov <denis@crazydev.net> | 2013-05-12 20:02:27 +0600 |
---|---|---|
committer | Denis Krjuchkov <denis@crazydev.net> | 2013-05-12 20:02:27 +0600 |
commit | e9e55b08127dc45b4c6045e1f42e34115086a521 (patch) | |
tree | c79558219a5605584dc6c81cc1dea348afdf3d75 /src/playlist | |
parent | 49a3845135142ada6d581d5a6f4a5192aaed49be (diff) | |
download | mpd-e9e55b08127dc45b4c6045e1f42e34115086a521.tar.gz mpd-e9e55b08127dc45b4c6045e1f42e34115086a521.tar.xz mpd-e9e55b08127dc45b4c6045e1f42e34115086a521.zip |
text_input_stream: convert to class
Diffstat (limited to 'src/playlist')
-rw-r--r-- | src/playlist/CuePlaylistPlugin.cxx | 16 | ||||
-rw-r--r-- | src/playlist/ExtM3uPlaylistPlugin.cxx | 38 | ||||
-rw-r--r-- | src/playlist/M3uPlaylistPlugin.cxx | 27 |
3 files changed, 38 insertions, 43 deletions
diff --git a/src/playlist/CuePlaylistPlugin.cxx b/src/playlist/CuePlaylistPlugin.cxx index 730ef783b..3d8098672 100644 --- a/src/playlist/CuePlaylistPlugin.cxx +++ b/src/playlist/CuePlaylistPlugin.cxx @@ -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; diff --git a/src/playlist/ExtM3uPlaylistPlugin.cxx b/src/playlist/ExtM3uPlaylistPlugin.cxx index 2043bea52..923536ea9 100644 --- a/src/playlist/ExtM3uPlaylistPlugin.cxx +++ b/src/playlist/ExtM3uPlaylistPlugin.cxx @@ -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; } diff --git a/src/playlist/M3uPlaylistPlugin.cxx b/src/playlist/M3uPlaylistPlugin.cxx index eeecd2779..e1e0a803b 100644 --- a/src/playlist/M3uPlaylistPlugin.cxx +++ b/src/playlist/M3uPlaylistPlugin.cxx @@ -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(); + + while (*line_s != 0 && g_ascii_isspace(*line_s)) + ++line_s; + } while (line_s[0] == '#' || *line_s == 0); - return song_remote_new(line); + return song_remote_new(line_s); } static const char *const m3u_suffixes[] = { |