CssCharsetRule.cs :  » GUI » SharpVectorGraphics » SharpVectors » Dom » Css » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » SharpVectorGraphics 
SharpVectorGraphics » SharpVectors » Dom » Css » CssCharsetRule.cs
using System;
using System.Text.RegularExpressions;
using SharpVectors.Dom;

namespace SharpVectors.Dom.Css{
  /// <summary>
  /// The CSSCharsetRule interface represents a @charset rule in a CSS style sheet. The value of the encoding attribute does not affect the encoding of text data in the DOM objects; this encoding is always UTF-16. After a stylesheet is loaded, the value of the encoding attribute is the value found in the @charset rule. If there was no @charset in the original document, then no CSSCharsetRule is created. The value of the encoding attribute may also be used as a hint for the encoding used on serialization of the style sheet.
  ///  The value of the @charset rule (and therefore of the CSSCharsetRule) may not correspond to the encoding the document actually came in; character encoding information e.g. in an HTTP header, has priority (see CSS document representation) but this is not reflected in the CSSCharsetRule.
  /// </summary>
  /// <developer>niklas@protocol7.com</developer>
  /// <completed>80</completed>
  public class CssCharsetRule : CssRule, ICssCharsetRule
  {
    #region Static members
    private static Regex regex = new Regex(@"^@charset\s""(?<charsetencoding>[^""]+)"";");

    internal static CssRule Parse(ref string css, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin)
    {
      Match match = regex.Match(css);
      if(match.Success)
      {
        CssCharsetRule rule = new CssCharsetRule(match, parent, readOnly, replacedStrings, origin);
        css = css.Substring(match.Length);
        return rule;
      }
      else
      {
        // didn't match => do nothing
        return null;
      }
    }
    #endregion

    #region Constructors
    /// <summary>
    /// The constructor for CssCharSetRule
    /// </summary>
    /// <param name="match">The Regex match that found the charset rule</param>
    /// <param name="parent">The parent rule or parent stylesheet</param>
    /// <param name="readOnly">True if this instance is readonly</param>
    /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param>
    /// <param name="origin">The type of CssStyleSheet</param>
    internal CssCharsetRule(Match match, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin) : base(parent, readOnly, replacedStrings, origin)
    {
      _Encoding = DeReplaceStrings(match.Groups["charsetencoding"].Value);
    }
    #endregion
    
    #region Implementation of ICssCharsetRule
    private string _Encoding;
    /// <summary>
    /// The encoding information used in this @charset rule
    /// </summary>
    public string Encoding
    {
      get
      {
        return _Encoding;
      }
      set
      {
        /*
         * TODO: SYNTAX_ERR: Raised if the specified encoding value has a syntax error and is unparsable.
         * */

        if(ReadOnly) throw new DomException(DomExceptionType.NoModificationAllowedErr);

        _Encoding = value;
      }
    }
    #endregion

    #region Implementation of ICssRule
    /// <summary>
    /// The type of the rule. The expectation is that binding-specific casting methods can be used to cast down from an instance of the CSSRule interface to the specific derived interface implied by the type.
    /// </summary>
    public override CssRuleType Type
    {
      get
      {
        return CssRuleType.CharsetRule;
      }
    }
    #endregion
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.