/* Methods * * * /* Constructors */ public BptEptElement(string matchBptEpt) { Regex regexBptEpt = new Regex("(<bpt.*?(id=\"(\\d+)\")?>.*?</bpt>)(.*)(<ept.*?(id=\"(\\d+)\")?>.*?</ept>)"); Match matchesBptEpt = regexBptEpt.Match(matchBptEpt); if (matchesBptEpt.Value != string.Empty) { parsingSuccess = true; /* Initializing value of bptID with the valuse of the third group in the regex pattern and converting to int32.*/ string bptElementRaw = matchesBptEpt.Groups[1].Value; string eptElementRaw = matchesBptEpt.Groups[5].Value; bptElement = new BPT(bptElementRaw); eptElement = new EPT(eptElementRaw); if (bptElement.ID == eptElement.ID) { isPaired = true; elementID = bptElement.ID; textBetween = matchesBptEpt.Groups[4].Value; Match matchesNestedBptEpt = regexBptEpt.Match(textBetween); if (matchesNestedBptEpt.Value != string.Empty) { hasNestedNodes = true; nestedElement = new BptEptElement(matchesNestedBptEpt.Value); } } } }
public void BPT_YellowHighlight_Test_2() { string testBPTRaw = "<bpt id=\"1\"><cf bold=\"on\" complexscriptsbold=\"on\"></bpt>"; BPT parsedBPT = new BPT(testBPTRaw); Assert.AreEqual(false, parsedBPT.IsYellowHighlight()); }
public void BPT_Parsing_Success_Test_3() { string testBPTRaw = "teststring test</bpt>"; BPT parsedBPT = new BPT(testBPTRaw); Assert.AreEqual(false, parsedBPT.ParsingSuccess); }
public void BPT_Parsing_Success_Test_2() { string testBPTRaw = "<bpt id=\"1\">"; BPT parsedBPT = new BPT(testBPTRaw); Assert.AreEqual(false, parsedBPT.ParsingSuccess); }
public void BPT_Initialize_Test_3() { string testBPTRaw = "<bpt></bpt>"; string innerText = string.Empty; BPT parsedBPT = new BPT(testBPTRaw); Assert.AreEqual(-1, parsedBPT.ID); Assert.AreEqual(innerText, parsedBPT.Content); }
public void BPT_Initialize_Test_1() { string testBPTRaw = "<bpt id=\"1\"><cf font=\"Arial\" asiantextfont=\"Arial\" complexscriptsfont=\"Arial\"></bpt>"; string innerText = "<cf font=\"Arial\" asiantextfont=\"Arial\" complexscriptsfont=\"Arial\">"; BPT parsedBPT = new BPT(testBPTRaw); Assert.AreEqual(1, parsedBPT.ID); Assert.AreEqual(innerText, parsedBPT.Content); }
/*Constructors*/ public TransUnitElements(string transUnitText) { Regex bptTag = new Regex("<bpt.*?id=\"\\d+\"?>.*?</bpt>"); Regex eptTag = new Regex("<ept.*?id=\"\\d+\"?>.*?</ept>"); Regex itTag = new Regex("<it.*?(id=\"(\\d+)\")?>.*?</it>"); Regex phTag = new Regex("<ph.*?(id=\"(\\d+)\")?>.*?</ph>"); MatchCollection bptMatchList = bptTag.Matches(transUnitText); var listOfBptStrings = bptMatchList.Cast <Match>().Select(match => match.Value).ToList(); MatchCollection eptMatchList = eptTag.Matches(transUnitText); var listOfEptStrings = eptMatchList.Cast <Match>().Select(match => match.Value).ToList(); MatchCollection itMatchList = itTag.Matches(transUnitText); var listOfItStrings = itMatchList.Cast <Match>().Select(match => match.Value).ToList(); MatchCollection phMatchList = phTag.Matches(transUnitText); var listOfPhStrings = phMatchList.Cast <Match>().Select(match => match.Value).ToList(); /*I think that here there should be validation added to check if all corresponding elements in the list string * have the same index as matcheslist. */ BPT auxiliaryBpt; EPT auxiliaryEpt; IT auxiliaryIt; PH auxiliaryPh; BptEptElement auxiliaryBptEptElement; int auxiliaryIndex; Match bptMatch; Match eptMatch; /*Initializing list of BPT, EPT, PH and IT objects.*/ foreach (string bpt in listOfBptStrings) { auxiliaryBpt = new BPT(bpt); listOfBpt.Add(auxiliaryBpt); } foreach (string ept in listOfEptStrings) { auxiliaryEpt = new EPT(ept); listOfEpt.Add(auxiliaryEpt); } foreach (string ph in listOfPhStrings) { auxiliaryPh = new PH(ph); listOfPh.Add(auxiliaryPh); } foreach (string it in listOfItStrings) { auxiliaryIt = new IT(it); listOfIt.Add(auxiliaryIt); } /*All all bpt tag has to have ept tag but not otherwise, so that's why I search through ept list and initialize * BptEpt objects. * 1 Case - Ept tag list is not empty. We want all pairs bpt-ept in this case. * 2 Case - Some Ept doesn't have a paired Bpt tag - so corresponding Bpt tag should be places in some previous * trans-unit note. We should be able to save this information. * 3 Case - Some Bpt tag doesn't have paired Ept tag so this information should be stored and used in the Case 2. * And in case of 2 and 3 we want to create a EptBpt object on the level of Xliff document. */ if (listOfEpt.Count != 0) { foreach (EPT ept in listOfEpt) { if (listOfBpt.Exists(x => x.ID == ept.ID)) { auxiliaryIndex = listOfBpt.FindIndex(x => x.ID == ept.ID); bptMatch = bptMatchList[auxiliaryIndex]; auxiliaryIndex = listOfEpt.FindIndex(x => x.ID == ept.ID); eptMatch = eptMatchList[auxiliaryIndex]; auxiliaryBptEptElement = new BptEptElement(transUnitText.Substring(bptMatch.Index, eptMatch.Index + eptMatch.Length - bptMatch.Index)); listOfBptEpt.Add(auxiliaryBptEptElement); } else { listEptNotPairedIDs.Add(ept.ID); } } } else if (listOfBpt.Count != 0) { foreach (BPT bpt in listOfBpt) { listBptNotPairedIDs.Add(bpt.ID); } } }