public static bool IsTagGlobal(string s, string tag) { TagPair tagPair = GetTagPair(tag); int stringLength = s.Length; int tagEnd = s.IndexOf(tagPair.end) + tagPair.end.Length; return(stringLength == tagEnd); }
public static string getNextTagContent(string s) { string tag = FindNextTagName(s); TagPair tagPair = GetTagPair(tag); int stringLength = s.Length; string end = tagPair.end; int contentLength = s.IndexOf(end) + end.Length; return(s.Substring(0, contentLength)); }
public static string getRemainder(string s, string tag) { TagPair tagPair = GetTagPair(tag); if (IsTagGlobal(s, tag)) { return(""); } else { int stringLength = s.Length; string end = tagPair.end; int remainderStart = s.IndexOf(end) + end.Length; return(s.Substring(remainderStart)); } }
protected string CheckTagAndGetInner(string trackPoint, string tagName) { TagPair formattedTag = XMLHelper.GetTagPair(tagName); string pattern = formattedTag.start + "(.*)" + formattedTag.end; Regex tag = new Regex(pattern); Match match = tag.Match(trackPoint); if (match.Success) { return(match.Groups[1].Value); } else { return("NOK"); } }
public bool loadSessionBody(string content) { // Spilitting the string at each <Track> will yield N packages + the preamble.. TagPair tagPair = XMLHelper.GetTagPair("Track"); string tagPairStart = tagPair.start; string tagPairEnd = tagPair.end; string[] body = content.Split(tagPairStart); bool isFirst = true; // loop variable starts at 1 since body[0] is discardable preamble for (int p = 1; p < body.Length; p++) { // Removing stuff from </Track> onwards string package = body[p]; int trackEnd = package.IndexOf(tagPairEnd); package = package.Substring(0, trackEnd); string tag = XMLHelper.FindNextTagName(package); bool isEmpty = false; while (!isEmpty && Misc.AreStringEnumEqual(tag, typeof(Enums.SessionTag), Enums.SessionTag.Trackpoint)) { string tp = XMLHelper.getNextTagContent(package); if (loadTrackPoint(tp, isFirst)) { mTicks++; } else { Console.WriteLine("Warning in loadTrackPoint: Tracking point not loaded correctly. Discarding session"); return(false); } isFirst = false; package = XMLHelper.getRemainder(package, "Trackpoint"); if (package.Length == 0) { isEmpty = true; break; } tag = XMLHelper.FindNextTagName(package); } } return(true); }
public static string GetInnerString(string s, string tag) { TagPair tagPair = GetTagPair(tag); if (!s.StartsWith(tagPair.start)) { Exception ex = new Exception("String: " + s + " doesn't start with start tag: " + tagPair.start); throw ex; } int innerStart = tagPair.start.Length; int innerEnd = s.IndexOf(tagPair.end) - 1; if (innerEnd < innerStart) { Exception ex = new Exception("Empty tag"); throw ex; } return(s.Substring(innerStart, innerEnd - innerStart + 1)); }