示例#1
0
        /// <summary>Process_TimeFix</summary>
        private void Process_TimeFix(string regEx, string replace)
        {
            Regex r            = new Regex(@"\d{2}$");
            bool  foundHours   = false;
            bool  foundMinutes = false;
            bool  foundSeconds = false;

            // Test 10 11:30 pm 12:30:50 AM
            try
            {
                LinkedListNode <wordToken> itemNode = tokens.First;
                wordToken item = itemNode.Value;

                do
                {
                    Match m = r.Match(item.Token);
                    if (m.Success)
                    {
                        if (foundHours)
                        {
                            if (item.PreToken.s == ":")
                            {
                                if (foundMinutes)
                                {
                                    // we found Seconds, lets do something
                                    item.PreToken.s = "";
                                    item.Token      = "";
                                    foundHours      = false;
                                    foundMinutes    = false;
                                    foundSeconds    = false;
                                }
                                else
                                {
                                    if (item.PostToken.s == ":")
                                    {
                                        // we found minutes
                                        foundMinutes = true;
                                    }
                                    else
                                    {
                                        foundHours   = false;
                                        foundMinutes = false;
                                        foundSeconds = false;
                                    }
                                }
                            }
                            else
                            {
                                foundHours   = false;
                                foundMinutes = false;
                                foundSeconds = false;
                            }
                        }
                        else
                        {
                            // we found a 2 digit number, maybe hours
                            if (item.PostToken.s == ":")
                            {
                                foundHours = true;
                            }
                        }
                    }
                    else
                    {
                        foundHours   = false;
                        foundMinutes = false;
                        foundSeconds = false;
                    }

                    itemNode = itemNode.Next;
                    if (itemNode != null)
                    {
                        item = itemNode.Value;
                    }
                } while (itemNode != null);
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#2
0
        /// <summary>Process_MultiWordCaps: Break words with Caps to multiple words</summary>
        /// <param name="regEx">Regular Expression to use</param>
        /// <param name="replace">Text to use to replace</param>
        private void Process_MultiWordCaps(string regEx, string replace)
        {
            //StringBuilder toReplace = new StringBuilder(50);
            List <string> replaceList = new List <string>(50);

            StringBuilder currWord  = new StringBuilder();
            StringBuilder upperWord = new StringBuilder();

            bool foundMulti1 = false;
            bool foundMulti2 = false;
            bool foundMulti3 = false;

            try
            {
                //LinkedListNode<wordToken> item = tokens.First;
                for (LinkedListNode <wordToken> item = tokens.First;
                     item != null;
                     item = item.Next)
                {
                    currWord.Length  = 0;
                    upperWord.Length = 0;

                    foundMulti1 = false;
                    foundMulti2 = false;
                    foundMulti3 = false;

                    foreach (char wChar in item.Value.Token)
                    {
                        if ((wChar.CompareTo('A') >= 0) && (wChar.CompareTo('Z') <= 0))
                        {
                            // Process Upper case letter
                            if (foundMulti1)
                            {
                                foundMulti2 = true;
                            }
                            foundMulti1 = true;
                            if (currWord.Length == 1)
                            {
                                upperWord.Append(currWord);
                                currWord.Length = 0;
                            }
                            else if (currWord.Length > 1)
                            {
                                if (upperWord.Length > 0)
                                {
                                    replaceList.Add(upperWord.ToString());
                                    upperWord.Length = 0;
                                }
                                replaceList.Add(currWord.ToString());
                                currWord.Length = 0;
                            }
                            currWord.Append(wChar);
                        }
                        else                         // Process lower case letter
                        {
                            foundMulti3 = true;
                            currWord.Append(wChar);
                        }
                    }

                    if (currWord.Length == 1)
                    {
                        if ((currWord[0].CompareTo('A') >= 0) && (currWord[0].CompareTo('Z') <= 0))
                        {
                            upperWord.Append(currWord);
                            currWord.Length = 0;
                        }
                    }

                    if (upperWord.Length > 0)
                    {
                        replaceList.Add(upperWord.ToString());
                    }

                    if (currWord.Length > 0)
                    {
                        replaceList.Add(currWord.ToString());
                    }
                    currWord.Length  = 0;
                    upperWord.Length = 0;

                    // Check if word contained Multi-Words
                    if (foundMulti1 && foundMulti2 && foundMulti3)
                    {
                        PrePost   spacePrePost = new PrePost(replace);
                        wordToken newToken     = new wordToken(item.Value.PreToken, replaceList[0], spacePrePost);
                        tokens.AddBefore(item, newToken);

                        for (int i = 1; i < replaceList.Count; i++)
                        {
                            PrePost AnotherPrePost = new PrePost(replace);
                            newToken = new wordToken(spacePrePost, replaceList[i], AnotherPrePost);
                            tokens.AddBefore(item, newToken);
                        }
                        newToken.PostToken = item.Value.PostToken;
                        LinkedListNode <wordToken> PrevItem = item.Previous;
                        tokens.Remove(item);
                        item     = PrevItem;
                        PrevItem = null;
                    }
                    replaceList.Clear();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }