/// <summary> /// Split a QualifiedName into prefix and localname, w/o any checking. /// (Used for XmlReader/XPathNavigator MoveTo(name) methods) /// </summary> internal static void SplitQName(string name, out string prefix, out string lname) { int colonPos = name.IndexOf(':'); if (-1 == colonPos) { prefix = string.Empty; lname = name; } else if (0 == colonPos || (name.Length - 1) == colonPos) { throw new ArgumentException(SR.Format("SR.Xml_BadNameChar", XmlExceptionHelper.BuildCharExceptionArgs(':', '\0')), nameof(name)); } else { prefix = name.Substring(0, colonPos); colonPos++; // move after colon lname = name.Substring(colonPos, name.Length - colonPos); } }
/// <summary> /// Throws an invalid name exception. /// </summary> /// <param name="s">String that was parsed.</param> /// <param name="offsetStartChar">Offset in string where parsing began.</param> /// <param name="offsetBadChar">Offset in string where parsing failed.</param> internal static void ThrowInvalidName(string s, int offsetStartChar, int offsetBadChar) { // If the name is empty, throw an exception if (offsetStartChar >= s.Length) { throw new XmlException("SR.Xml_EmptyName"); } Debug.Assert(offsetBadChar < s.Length); if (xmlCharType.IsNCNameSingleChar(s[offsetBadChar]) && !XmlCharType.Instance.IsStartNCNameSingleChar(s[offsetBadChar])) { // The error character is a valid name character, but is not a valid start name character throw new XmlException(SR.Format("SR.Xml_BadStartNameChar", XmlExceptionHelper.BuildCharExceptionArgs(s, offsetBadChar))); } else { // The error character is an invalid name character throw new XmlException(SR.Format("SR.Xml_BadNameChar", XmlExceptionHelper.BuildCharExceptionArgs(s, offsetBadChar))); } }
public static Exception CreateInvalidCharException(string data, int invCharPos, ExceptionType exceptionType) { return(CreateException("SR.Xml_InvalidCharacter", XmlExceptionHelper.BuildCharExceptionArgs(data, invCharPos), exceptionType, 0, invCharPos + 1)); }