public ParseResult parse(string input_filename) { ParseResult result = new ParseResult(); if (input_filename == null) { throw new NullReferenceException(); } if (input_filename.Length == 0) { result.Remainder = input_filename; result.Stamp = null; return(result); } Stamp stamp_struct = new Stamp(); string redigit = "([0-9]|[xX])"; string redash = @"\-"; string releft = @"(([\[|\(])*)"; string reright = @"(([\]|\)])*)"; string reyyyymmdd = (releft) + (redigit + "{4}") + redash + (redigit + "{1,2}") + redash + (redigit + "{1,2}") + (reright); string remmddyyyy = (releft) + (redigit + "{1,2}") + redash + (redigit + "{1,2}") + redash + (redigit + "{4}") + (reright); System.Text.RegularExpressions.Regex regex_pattern; System.Text.RegularExpressions.Match regex_match; System.Text.RegularExpressions.Capture regex_capture = null; regex_pattern = new System.Text.RegularExpressions.Regex(reyyyymmdd); regex_match = regex_pattern.Match(input_filename); if (regex_match.Success) { regex_capture = regex_match.Captures[0]; string[] tokens = this.tokenize(regex_capture.ToString()); stamp_struct.Year = tokens[0]; stamp_struct.Month = tokens[1]; stamp_struct.Day = tokens[2]; stamp_struct.calc(); result.Stamp = stamp_struct; } else { regex_pattern = new System.Text.RegularExpressions.Regex(remmddyyyy); regex_match = regex_pattern.Match(input_filename); if (regex_match.Success) { regex_capture = regex_match.Captures[0]; string[] tokens = this.tokenize(regex_capture.ToString()); stamp_struct.Year = tokens[2]; stamp_struct.Month = tokens[0]; stamp_struct.Day = tokens[1]; stamp_struct.calc(); result.Stamp = stamp_struct; } else { result.Remainder = input_filename; result.Stamp = null; return(result); } } if (regex_match == null) { throw new Exception(); } string before = ""; string after = ""; if (regex_capture.Length > 0) { if (regex_capture.Index < 1) { before = ""; after = input_filename.Substring(regex_capture.Index + regex_capture.Length); } else { before = input_filename.Substring(0, regex_capture.Index); after = input_filename.Substring(regex_capture.Index + regex_capture.Length); } } result.Remainder = before + after; return(result); }
public ParseResult parse(string input_filename) { ParseResult result = new ParseResult(); if (input_filename == null) { throw new NullReferenceException(); } if (input_filename.Length == 0) { result.Remainder = input_filename; result.Stamp = null; return result; } Stamp stamp_struct = new Stamp(); string redigit = "([0-9]|[xX])"; string redash = @"\-"; string releft = @"(([\[|\(])*)"; string reright = @"(([\]|\)])*)"; string reyyyymmdd = (releft) + (redigit + "{4}") + redash + (redigit + "{1,2}") + redash + (redigit + "{1,2}") + (reright); string remmddyyyy = (releft) + (redigit + "{1,2}") + redash + (redigit + "{1,2}") + redash + (redigit + "{4}") + (reright); System.Text.RegularExpressions.Regex regex_pattern; System.Text.RegularExpressions.Match regex_match; System.Text.RegularExpressions.Capture regex_capture = null; regex_pattern = new System.Text.RegularExpressions.Regex(reyyyymmdd); regex_match = regex_pattern.Match(input_filename); if (regex_match.Success) { regex_capture = regex_match.Captures[0]; string[] tokens = this.tokenize(regex_capture.ToString()); stamp_struct.Year=tokens[0]; stamp_struct.Month = tokens[1]; stamp_struct.Day=tokens[2]; stamp_struct.calc(); result.Stamp=stamp_struct; } else { regex_pattern = new System.Text.RegularExpressions.Regex(remmddyyyy); regex_match = regex_pattern.Match(input_filename); if (regex_match.Success) { regex_capture = regex_match.Captures[0]; string[] tokens = this.tokenize(regex_capture.ToString()); stamp_struct.Year = tokens[2]; stamp_struct.Month = tokens[0]; stamp_struct.Day = tokens[1]; stamp_struct.calc(); result.Stamp = stamp_struct; } else { result.Remainder = input_filename; result.Stamp =null; return result; } } if (regex_match == null) { throw new Exception(); } string before = ""; string after = ""; if (regex_capture.Length > 0) { if (regex_capture.Index < 1) { before = ""; after = input_filename.Substring(regex_capture.Index + regex_capture.Length); } else { before = input_filename.Substring(0, regex_capture.Index); after = input_filename.Substring(regex_capture.Index + regex_capture.Length); } } result.Remainder = before + after; return result; }