Ejemplo n.º 1
0
        /* 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);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void EPT_Parsing_Success_Test_3()
        {
            string testEPTRaw = "teststring test</ept>";

            EPT parsedEPT = new EPT(testEPTRaw);

            Assert.AreEqual(false, parsedEPT.ParsingSuccess);
        }
Ejemplo n.º 3
0
        public void EPT_Parsing_Success_Test_2()
        {
            string testEPTRaw = "<ept id=\"1\">";

            EPT parsedEPT = new EPT(testEPTRaw);

            Assert.AreEqual(false, parsedEPT.ParsingSuccess);
        }
Ejemplo n.º 4
0
        public void EPT_Initialize_Test_3()
        {
            string testEPTRaw = "<ept></ept>";
            string innerText  = string.Empty;

            EPT parsedEPT = new EPT(testEPTRaw);

            Assert.AreEqual(-1, parsedEPT.ID);
            Assert.AreEqual(innerText, parsedEPT.Content);
        }
Ejemplo n.º 5
0
        public void EPT_Initialize_Test_1()
        {
            string testEPTRaw = "<ept id=\"1\">&lt;/cf&gt;</ept>";
            string innerText  = "&lt;/cf&gt;";

            EPT parsedEPT = new EPT(testEPTRaw);

            Assert.AreEqual(1, parsedEPT.ID);
            Assert.AreEqual(innerText, parsedEPT.Content);
        }
Ejemplo n.º 6
0
        /*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);
                }
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// This compress algorithm only works for 8, 16 or 32 bit data types.
 /// </summary>
 /// <param name="dataType"></param>
 /// <returns></returns>
 public bool QueryDataTypeSupported(EPT dataType)
 {
     int nBits = dataType.GetBitCount();
     return (nBits == 8 || nBits == 16 || nBits == 32);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a new instance of HfaCompress from the data byte, and starts at the data offset.
        /// </summary>
        public HfaCompress(byte[] data, long dataOffset, int blockSize, EPT dataType)
        {
            _compressed = false;
            _data = data;
            _dataOffset = dataOffset;
            _dataTypeNumBits = dataType.GetBitCount();

            _blockSize = blockSize;
            _blockCount = blockSize/(_dataTypeNumBits/8);

            // Allocate memory for the count and values, probably too big
            // about right for worst case scenario
            _counts = new byte[_blockSize + sizeof(UInt32)];
            _values = new byte[_blockSize + sizeof(UInt32)];
        }