public static void Append_Entry_To_List(ref List <Tuple <string, FormDataEntryValue> > entryList, string name, dynamic value, bool prevent_line_break_normalization_flag = false) {/* Docs: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#append-an-entry */ /* 1) For name, replace every occurrence of U+000D (CR) not followed by U+000A (LF), and every occurrence of U+000A (LF) not preceded by U+000D (CR), by a string consisting of a U+000D (CR) and U+000A (LF). */ var normalizedName = StringCommon.Replace(name.AsMemory(), FilterCRLF.Instance, strNewline.AsSpan()); /* 2) Replace name with the result of converting to a sequence of Unicode scalar values. */ name = UnicodeCommon.Convert_To_Scalar_Values(normalizedName.AsMemory()); /* 3) If value is not a File object, then: */ if (!(value is FileBlob valueFile)) { if (!(value is string)) { throw new ArgumentException($"Expected value to be string, not: {value.GetType().Name}"); } if (!prevent_line_break_normalization_flag) { string normalizedValue = StringCommon.Replace(((string)value).AsMemory(), FilterCRLF.Instance, strNewline.AsSpan()); value = UnicodeCommon.Convert_To_Scalar_Values(normalizedValue.AsMemory()); } var entryValue = new FormDataEntryValue(EFormDataValueType.String, name, value); entryList.Add(new Tuple <string, FormDataEntryValue>(name, entryValue)); }
private string To_XML_Safe_Name(string Name) { int idx = Name.IndexOf('-'); if (idx >= 0 && Name.Length < 2) { throw new DomSyntaxError(); } if (idx >= 0 && (Name[idx + 1] >= 'a' || Name[idx + 1] <= 'z')) { throw new DomSyntaxError(); } bool hasAlpha = false; for (int i = 0; i < Name.Length; i++) { if (UnicodeCommon.Is_ASCII_Upper_Alpha(Name[i])) { hasAlpha = true; break; } } /* 2) For each ASCII upper alpha in name, insert a U+002D HYPHEN-MINUS character (-) before the character and replace the character with the same character converted to ASCII lowercase. */ StringBuilder sb = new StringBuilder(); if (hasAlpha) { for (int i = 0; i < Name.Length; i++) { if (UnicodeCommon.Is_ASCII_Upper_Alpha(Name[i])) { sb.Append('-'); sb.Append(UnicodeCommon.To_ASCII_Lower_Alpha(Name[i])); } else { sb.Append(Name[i]); } } } else { sb.Append(Name); } /* 3) Insert the string data- at the front of name. */ sb.Insert(0, "data-"); string safeName = sb.ToString(); /* 4) If name does not match the XML Name production, throw an "InvalidCharacterError" DOMException. */ if (!XMLCommon.Is_Valid_Name(safeName)) { throw new InvalidCharacterError($"The Name '{safeName}' is not a valid XML name production."); } return(safeName); }
public override EFilterResult acceptData(char data) { if (UnicodeCommon.Is_Ascii_Whitespace(data)) { return(EFilterResult.FILTER_SKIP); } return(EFilterResult.FILTER_ACCEPT); }
public override EFilterResult acceptData(char data) { if (UnicodeCommon.Is_Selectable_Char(data)) { return(EFilterResult.FILTER_ACCEPT); } return(EFilterResult.FILTER_REJECT); }
/// <summary> /// Deletes a named value from the list. /// </summary> /// <param name="Name"></param> public void delete(string Name) { bool hasAlpha = false; for (int i = 0; i < Name.Length; i++) { if (UnicodeCommon.Is_ASCII_Upper_Alpha(Name[i])) { hasAlpha = true; break; } } /* 1) For each ASCII upper alpha in name, insert a U+002D HYPHEN-MINUS character (-) before the character and replace the character with the same character converted to ASCII lowercase. */ StringBuilder sb = new StringBuilder(); if (hasAlpha) { for (int i = 0; i < Name.Length; i++) { if (UnicodeCommon.Is_ASCII_Upper_Alpha(Name[i])) { sb.Append(UnicodeCommon.CHAR_HYPHEN_MINUS); sb.Append(UnicodeCommon.To_ASCII_Lower_Alpha(Name[i])); } else { sb.Append(Name[i]); } } } else { sb.Append(Name); } /* 2) Insert the string data- at the front of name. */ sb.Insert(0, "data-"); Name = sb.ToString(); /* 3) Remove an attribute by name given name and the DOMStringMap's associated element. */ if (Owner.find_attribute(Name, out Attr attr)) { Owner.remove_attribute(attr); } }
private string From_XML_Safe_Name(string Name) { if (0 == Name.IndexOf("data-") && !UnicodeCommon.Has_ASCII_Upper_Alpha(Name.AsSpan())) { string str = Name.Substring(5); StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.Length; i++) { if (str[i] == '-' && (i + 1) < str.Length && UnicodeCommon.Is_ASCII_Lower_Alpha(str[i + 1])) { i++;// skip the hypen sb.Append(UnicodeCommon.To_ASCII_Upper_Alpha(str[i + 1])); } else { sb.Append(str[i]); } } return(sb.ToString()); } return(null); }
public string Serialize() {/* Docs: https://url.spec.whatwg.org/#concept-ipv6-serializer */ StringBuilder output = new StringBuilder(); int? compress = null; bool bCompress = false; for (int i = 0; i < Parts.Length; i++) { var part = Parts[i]; if (part == 0) { if (bCompress) { compress = i; break; } } else if (!bCompress) { bCompress = true; continue; } } bool ignore0 = false; for (int pieceIndex = 0; pieceIndex < Parts.Length; pieceIndex++) { if (ignore0 && Parts[pieceIndex] == 0) { continue; } else if (ignore0) { ignore0 = false; } if (compress == pieceIndex) { if (pieceIndex == 0) { output.Append(UnicodeCommon.CHAR_COLON); output.Append(UnicodeCommon.CHAR_COLON); } else { output.Append(UnicodeCommon.CHAR_COLON); } ignore0 = true; continue; } output.Append(UnicodeCommon.Ascii_Value_To_Hex(Parts[pieceIndex])); if (pieceIndex != 7) { output.Append(UnicodeCommon.CHAR_COLON); } } return(output.ToString()); }