示例#1
0
        /// <summary>
        /// Match hex values that are 6 long, can ignore length 3 for now, and compress them down to 3 if possible, 
        /// Grab all the hex strings and see if the literal color name is shorter than the hex value, if so, replace it.
        /// </summary>
        private static void CompressHexValues( ref string source )
        {
            var colors = new ColorConversions();
            string tmp = string.Empty;

            source = Regex.Replace( source, "#[0-9a-fA-F]{6}(?=,|;|\\}\\)\\s)", m => {
                tmp = colors.CompressHex( m.Value.Replace( "#", string.Empty ) );
                return m.Value.Replace( m.Value, tmp );
            } );

            source = Regex.Replace( source, "#([0-9a-fA-F]{3}){1,2}(?=,|;|\\}\\)\\s)", m => {
                tmp = colors.SwapOutHex( m.Value );
                return m.Value.Replace( m.Value, tmp );
            } );
        }