<commit_before>package pman.utils;

import tannus.ds.*;
import tannus.io.*;
import tannus.sys.*;

import pman.core.*;

import Slambda.fn;

using StringTools;
using Lambda;
using tannus.ds.ArrayTools;
using tannus.ds.StringUtils;
using Slambda;
using pman.commands.Tools;

class M3UDecoder {
	/* Constructor Function */
	public function new():Void {
		buffer = new Stack();
		playlist = new Array();
	}

/* === Instance Methods === */

	/**
	  * decode the given String
	  */
	public inline function decodeString(s : String):Array<Path> {
		return decode(s.split( '\n' ));
	}

	/**
	  * decode the given Array of Strings
	  */
	public function decode(lines : Array<String>):Array<Path> {
		buffer = new Stack( lines );
		playlist = new Array();

		parse();

		return playlist;
	}

	/**
	  * parse the buffer
	  */
	private function parse():Void {
		while ( !buffer.empty ) {
			parseNextLine();
		}
	}

	/**
	  * parse and process the next line of input
	  */
	private function parseNextLine():Void {
		if ( buffer.empty ) {
			return ;
		}
		else {
			var line:String = nextLine();

			if (line.empty()) {
				parseNextLine();
			}
			else if (line.startsWith('#EXTINF:')) {
				var infoLine:String = line.after( '#EXTINF:' );
				line = nextLine();
				if (!line.empty()) {
					playlist.push(Path.fromString( line ));
				}
				nextLine();
			}
		}
	}

	/**
	  * get the next line of text
	  */
	private function nextLine():String {
		var line = buffer.pop();
		if (line == null) line = '';
		return line.trim();
	}

/* === Instance Fields === */

	private var buffer : Stack<String>;
	private var playlist : Array<Path>;

/* === Class Methods === */

	public static inline function run(s : String):Array<Path> {
		return new M3UDecoder().decodeString( s );
	}
}<commit_msg>refactored pman.format.m3u.Reader to read m3u files into pman Playlist objects<commit_after>package pman.format.m3u;

import tannus.ds.*;
import tannus.io.*;
import tannus.sys.*;

import pman.core.*;
import pman.media.*;

import Slambda.fn;

using StringTools;
using Lambda;
using tannus.ds.ArrayTools;
using tannus.ds.StringUtils;
using Slambda;
using pman.media.MediaTools;

class Reader {
	/* Constructor Function */
	public function new():Void {
		buffer = new Stack();
		playlist = new Playlist();
	}

/* === Instance Methods === */

	/**
	  * decode the given String
	  */
	public inline function readString(s : String):Playlist {
		return read(s.split( '\n' ));
	}

	/**
	  * decode the given Array of Strings
	  */
	public function read(lines : Array<String>):Playlist {
		buffer = new Stack( lines );
		playlist = new Playlist();

		parse();

		return playlist;
	}

	/**
	  * parse the buffer
	  */
	private function parse():Void {
		while ( !buffer.empty ) {
			parseNextLine();
		}
	}

	/**
	  * parse and process the next line of input
	  */
	private function parseNextLine():Void {
		if ( buffer.empty ) {
			return ;
		}
		else {
			var line:String = nextLine();

			if (line.empty()) {
				parseNextLine();
			}
			else if (line.startsWith('#EXTINF:')) {
				var infoLine:String = line.after( '#EXTINF:' );
				line = nextLine();
				if (!line.empty()) {
					var track:Track = line.parseToTrack();
					playlist.push( track );
				}
				nextLine();
			}
		}
	}

	/**
	  * get the next line of text
	  */
	private function nextLine():String {
		var line = buffer.pop();
		if (line == null) line = '';
		return line.trim();
	}

/* === Instance Fields === */

	private var buffer : Stack<String>;
	private var playlist : Playlist;

/* === Class Methods === */

	/**
	  * shorthand to create a new Reader instance, and use it to decode the given String
	  */
	public static inline function run(s : String):Playlist {
		return new Reader().readString( s );
	}
}
{'fraction_non_alphanumeric': 0.15314834578441835, 'fraction_numerical': 0.0013340448239060833, 'mean_word_length': 3.031182795698925, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '900771', 'n_tokens_mistral': 1397, 'n_tokens_neox': 1243, 'n_words': 339}