/// <summary> /// Suggests the initial Encoding for the given locale. /// </summary> /// <param name="locale"> /// The locale defined by the BCP 47 language tag. /// </param> /// <returns>The suggested encoding.</returns> public Encoding Suggest(String locale) { if (!String.IsNullOrEmpty(locale) && locale.Length > 1) { var encoding = default(Encoding); if (suggestions.TryGetValue(locale.Substring(0, 2), out encoding)) return encoding; else if (locale.Isi("zh-cn")) return TextEncoding.Gb18030; else if (locale.Isi("zh-tw")) return TextEncoding.Big5; } return TextEncoding.Windows1252; }
/// <summary> /// Gets the drawing context. /// </summary> /// <param name="contextId">A context id like 2d.</param> /// <returns>An object that defines the drawing context.</returns> public IRenderingContext GetContext(String contextId) { if (_current == null || contextId.Isi(_current.ContextId)) { var renderServices = Owner.Options.GetServices<IRenderingService>(); foreach (var renderService in renderServices) { if (renderService.IsSupportingContext(contextId)) { var context = renderService.CreateContext(this, contextId); if (context != null) { _mode = GetModeFrom(contextId); _current = context; } return context; } } return null; } return _current; }
public static Stream CreateBody(this FormDataSet formDataSet, String enctype, Encoding encoding) { if (enctype.Isi(MimeTypeNames.UrlencodedForm)) { return formDataSet.AsUrlEncoded(encoding); } else if (enctype.Isi(MimeTypeNames.MultipartForm)) { return formDataSet.AsMultipart(encoding); } else if (enctype.Isi(MimeTypeNames.Plain)) { return formDataSet.AsPlaintext(encoding); } else if (enctype.Isi(MimeTypeNames.ApplicationJson)) { return formDataSet.AsJson(); } return MemoryStream.Null; }
/// <summary> /// Gets the drawing context. /// </summary> /// <param name="contextId">A context id like 2d.</param> /// <returns>An object that defines the drawing context.</returns> public IRenderingContext GetContext(String contextId) { if (_current != null && contextId.Isi(_current.ContextId)) return _current; var renderService = Owner.Options.GetService<IRenderingService>(); if (renderService == null) return null; var context = renderService.CreateContext(this, contextId); if (context != null) { _mode = GetModeFrom(contextId); _current = context; } return context; }
static String CheckEncType(String encType) { if (encType.Isi(MimeTypeNames.Plain) || encType.Isi(MimeTypeNames.MultipartForm) || encType.Isi(MimeTypeNames.ApplicationJson)) { return encType; } return MimeTypeNames.UrlencodedForm; }
public CssKeyframeRule Find(String key) { return _rules.OfType<CssKeyframeRule>().FirstOrDefault(m => key.Isi(m.KeyText)); }
public void SetProperty(String propertyName, String propertyValue, String priority = null) { if (IsReadOnly) throw new DomException(DomError.NoModificationAllowed); if (!String.IsNullOrEmpty(propertyValue)) { if (priority == null || priority.Isi(Keywords.Important)) { var value = _parser.ParseValue(propertyValue); if (value != null) { var property = CreateProperty(propertyName); if (property != null && property.TrySetValue(value)) { property.IsImportant = priority != null; SetProperty(property); RaiseChanged(); } } } } else { RemoveProperty(propertyName); } }
public void SetPropertyPriority(String propertyName, String priority) { if (IsReadOnly) throw new DomException(DomError.NoModificationAllowed); if (String.IsNullOrEmpty(priority) || priority.Isi(Keywords.Important)) { var important = !String.IsNullOrEmpty(priority); var mappings = IsStrictMode && Factory.Properties.IsShorthand(propertyName) ? Factory.Properties.GetLonghands(propertyName) : Enumerable.Repeat(propertyName, 1); foreach (var mapping in mappings) { var property = GetProperty(mapping); if (property != null) { property.IsImportant = important; } } } }
static ContextMode GetModeFrom(String contextId) { if (contextId.Isi("2d")) { return ContextMode.Direct2d; } else if (contextId.Isi("webgl")) { return ContextMode.DirectWebGl; } return ContextMode.None; }
public SimpleSelector(String match) : this(el => match.Isi(el.LocalName), Priority.OneTag, match) { }
/// <summary> /// Opens a document stream for writing. For information see: /// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-open /// </summary> public IDocument Open(String type = "text/html", String replace = null) { if (!_contentType.Is(MimeTypeNames.Html)) { throw new DomException(DomError.InvalidState); } if (IsInBrowsingContext && _context.Active != this) { return null; } var shallReplace = replace.Isi(Keywords.Replace); if (_loadingScripts.Count > 0) { return this; } if (shallReplace) { type = MimeTypeNames.Html; } var index = type.IndexOf(Symbols.Semicolon); if (index >= 0) { type = type.Substring(0, index); } type = type.StripLeadingTrailingSpaces(); //TODO further steps needed. //see https://html.spec.whatwg.org/multipage/webappapis.html#dom-document-open _contentType = type; ReplaceAll(null, false); return this; }
/// <summary> /// Checks if the given mime-type is one of the JavaScript variants. /// </summary> /// <param name="type">The type to check for.</param> /// <returns> /// True if it is a legal JavaScript mime-type, otherwise false. /// </returns> public static Boolean IsJavaScript(String type) { foreach (var commonJsType in commonJsTypes) { if (type.Isi(commonJsType)) { return true; } } return false; }