TraceWizard.Diff.Diff.DiffCodes C# (CSharp) Method

DiffCodes() private static method

This function converts all textlines of the text into unique numbers for every unique textline so further work can work only with simple numbers.
private static DiffCodes ( string aText, Hashtable h, bool trimSpace, bool ignoreSpace, bool ignoreCase ) : int[]
aText string the input text
h System.Collections.Hashtable This extern initialized hashtable is used for storing all ever used textlines.
trimSpace bool ignore leading and trailing space characters
ignoreSpace bool
ignoreCase bool
return int[]
        private static int[] DiffCodes(string aText, Hashtable h, bool trimSpace, bool ignoreSpace, bool ignoreCase)
        {
            // get all codes of the text
            string[] Lines;
            int[] Codes;
            int lastUsedCode = h.Count;
            object aCode;
            string s;

            // strip off all cr, only use lf as textline separator.
            aText = aText.Replace("\r", "");
            Lines = aText.Split('\n');

            Codes = new int[Lines.Length];

            for (int i = 0; i < Lines.Length; ++i)
            {
                s = Lines[i];
                if (trimSpace)
                    s = s.Trim();

                if (ignoreSpace)
                {
                    s = Regex.Replace(s, "\\s+", " ");            // TODO: optimization: faster blank removal.
                }

                if (ignoreCase)
                    s = s.ToLower();

                aCode = h[s];
                if (aCode == null)
                {
                    lastUsedCode++;
                    h[s] = lastUsedCode;
                    Codes[i] = lastUsedCode;
                }
                else {
                    Codes[i] = (int)aCode;
                } // if
            } // for
            return (Codes);
        } // DiffCodes