public void Parse(string siteAsString) { siteAsString = siteAsString.Trim(); SiteAddress = StringSplitOff.SplitOffBySpace(ref siteAsString); Protocol = (Protocols)Enum.Parse(typeof(Protocols), StringSplitOff.SplitOffBySpace(ref siteAsString)); Port = StringSplitOff.SplitOffBySpace(ref siteAsString); AdditionalAddressInfo = StringSplitOff.SplitOffBySpace(ref siteAsString); Latitude = StringSplitOff.SplitOffBySpace(ref siteAsString); Longitude = StringSplitOff.SplitOffBySpace(ref siteAsString); Description = siteAsString.Trim(); }
private static Release ParseRelease(string text, bool exactMatch) { if (exactMatch) { string responseCode = StringSplitOff.SplitOffBySpace(ref text); } Release release = new Release(); release.Genre = StringSplitOff.SplitOffBySpace(ref text); release.Id = UInt32.Parse(StringSplitOff.SplitOffBySpace(ref text), NumberStyles.HexNumber).ToString(); release.Artist = StringSplitOff.SplitOffByDivide(ref text); release.Title = text; return(release); }
public IDictionary <FrameMeaning, string> FromString(string text) { FrameMeaning[] variables = Items.Variables.ToArray(); string[] delimiters = Items.Delimiters.ToArray(); Dictionary <FrameMeaning, string> variableMap = new Dictionary <FrameMeaning, string>(); int i = 0; for (; i < delimiters.Length; i++) { string token = StringSplitOff.SplitOff(ref text, delimiters[i]); if (!String.IsNullOrEmpty(token)) { variableMap.Add(variables[i], token); } else { throw new Exception("Could not apply pattern \"" + Items + "\" to \"" + text + "\""); } } if (i == variables.Length - 1) { if (!String.IsNullOrEmpty(text)) { variableMap.Add(variables[i], text); } } else { throw new Exception("Could not apply pattern \"" + Items + "\" to \"" + text + "\""); } return(variableMap); }
public static Release CreateReleaseFromResponse(IEnumerable <string> data) { Release release = new Release(); List <Track> tracks = new List <Track>(); release.Tracks = tracks; foreach (string line in data) { // check for comment if (line.Length == 0 || line[0] == '#') { continue; } int index = line.IndexOf('='); // couldn't find equal sign have no clue what the data is if (index == -1) { continue; } string field = line.Substring(0, index); // move it past the equal sign index++; switch (field) { case "DISCID": release.Id = line.Substring(index); continue; case "DTITLE": release.Artist += line.Substring(index); continue; case "DYEAR": release.Year = line.Substring(index); continue; case "DGENRE": release.Genre += line.Substring(index); continue; case "EXTD": release.AdditionalData += line.Substring(index); continue; case "PLAYORDER": //release.PlayOrder += line.Substring(index); continue; default: if (field.StartsWith("TTITLE")) { int trackNumber = int.Parse(field.Substring("TTITLE".Length)); string title = line.Substring(index); if (trackNumber < tracks.Count) { tracks[trackNumber].Title += title; } else { tracks.Add(new Track(title)); } } else if (field.StartsWith("EXTT")) { int trackNumber = int.Parse(field.Substring("EXTT".Length)); string extendedData = line.Substring(index); if (trackNumber < tracks.Count) { tracks[trackNumber].AdditionalData += extendedData; } else { tracks.Add(new Track("", extendedData)); } } continue; } } // split the title and artist from DTITLE; see if we have a slash if (release.Artist.IndexOf(" / ") != -1) { string titleArtist = release.Artist; release.Artist = StringSplitOff.SplitOffByDivide(ref titleArtist); release.Title = titleArtist.Trim(); } return(release); }