From eea5d753164080fc6f23cce658160f29560e91c6 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Tue, 22 Mar 2016 16:27:24 -0700 Subject: [PATCH] Remove unused files from CoreCLR [tfs-changeset: 1588782] --- src/mscorlib/mscorlib.shared.sources.props | 12 - .../src/System/CompatibilitySwitches.cs | 26 + .../Serialization/Formatters/CommonEnums.cs | 43 - .../Serialization/Formatters/IFieldInfo.cs | 40 - .../Serialization/Formatters/ISoapMessage.cs | 47 - .../Serialization/Formatters/SerTrace.cs | 136 --- .../Serialization/Formatters/SoapFault.cs | 159 --- .../Serialization/Formatters/SoapMessage.cs | 77 -- .../src/System/Security/SecurityDocument.cs | 378 ------- .../src/System/Security/Util/Parser.cs | 510 ---------- .../src/System/Security/Util/Tokenizer.cs | 944 ------------------ .../src/System/Security/XMLSyntaxException.cs | 54 - 12 files changed, 26 insertions(+), 2400 deletions(-) delete mode 100644 src/mscorlib/src/System/Runtime/Serialization/Formatters/CommonEnums.cs delete mode 100644 src/mscorlib/src/System/Runtime/Serialization/Formatters/IFieldInfo.cs delete mode 100644 src/mscorlib/src/System/Runtime/Serialization/Formatters/ISoapMessage.cs delete mode 100644 src/mscorlib/src/System/Runtime/Serialization/Formatters/SerTrace.cs delete mode 100644 src/mscorlib/src/System/Runtime/Serialization/Formatters/SoapFault.cs delete mode 100644 src/mscorlib/src/System/Runtime/Serialization/Formatters/SoapMessage.cs delete mode 100644 src/mscorlib/src/System/Security/SecurityDocument.cs delete mode 100644 src/mscorlib/src/System/Security/Util/Parser.cs delete mode 100644 src/mscorlib/src/System/Security/Util/Tokenizer.cs delete mode 100644 src/mscorlib/src/System/Security/XMLSyntaxException.cs diff --git a/src/mscorlib/mscorlib.shared.sources.props b/src/mscorlib/mscorlib.shared.sources.props index 3761d6e4dd..d865f1a75c 100644 --- a/src/mscorlib/mscorlib.shared.sources.props +++ b/src/mscorlib/mscorlib.shared.sources.props @@ -957,14 +957,6 @@ - - - - - - - - @@ -1023,10 +1015,6 @@ - - - - diff --git a/src/mscorlib/src/System/CompatibilitySwitches.cs b/src/mscorlib/src/System/CompatibilitySwitches.cs index 52961ba322..7facf85df3 100644 --- a/src/mscorlib/src/System/CompatibilitySwitches.cs +++ b/src/mscorlib/src/System/CompatibilitySwitches.cs @@ -63,6 +63,32 @@ namespace System return s_useLatestBehaviorWhenTFMNotSpecified; } } +#else //FEATURE_CORECLR + + public static bool IsAppEarlierThanSilverlight4 + { + get + { + return false; + } + } + + public static bool IsAppEarlierThanWindowsPhone8 + { + get + { + return false; + } + } + + public static bool IsAppEarlierThanWindowsPhoneMango + { + get + { + return false; + } + } + #endif //FEATURE_CORECLR public static bool IsNetFx40TimeSpanLegacyFormatMode diff --git a/src/mscorlib/src/System/Runtime/Serialization/Formatters/CommonEnums.cs b/src/mscorlib/src/System/Runtime/Serialization/Formatters/CommonEnums.cs deleted file mode 100644 index daa0ff4eb0..0000000000 --- a/src/mscorlib/src/System/Runtime/Serialization/Formatters/CommonEnums.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -/*============================================================ - ** - ** - ** - ** Purpose: Soap XML Formatter Enums - ** - ** - ===========================================================*/ - -namespace System.Runtime.Serialization.Formatters { - using System.Threading; - using System.Runtime.Remoting; - using System.Runtime.Serialization; - using System; - // Enums which specify options to the XML and Binary formatters - // These will be public so that applications can use them - [Serializable] -[System.Runtime.InteropServices.ComVisible(true)] - public enum FormatterTypeStyle - { - TypesWhenNeeded = 0, // Types are outputted only for Arrays of Objects, Object Members of type Object, and ISerializable non-primitive value types - TypesAlways = 0x1, // Types are outputted for all Object members and ISerialiable object members. - XsdString = 0x2 // Strings are outputed as xsd rather then SOAP-ENC strings. No string ID's are transmitted - } - - [Serializable] -[System.Runtime.InteropServices.ComVisible(true)] - public enum FormatterAssemblyStyle - { - Simple = 0, - Full = 1, - } - -[System.Runtime.InteropServices.ComVisible(true)] - public enum TypeFilterLevel { - Low = 0x2, - Full = 0x3 - } -} diff --git a/src/mscorlib/src/System/Runtime/Serialization/Formatters/IFieldInfo.cs b/src/mscorlib/src/System/Runtime/Serialization/Formatters/IFieldInfo.cs deleted file mode 100644 index c8c9576c12..0000000000 --- a/src/mscorlib/src/System/Runtime/Serialization/Formatters/IFieldInfo.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - - /*============================================================ - ** - ** - ** - ** Purpose: Interface For Returning FieldNames and FieldTypes - ** - ** - ===========================================================*/ - -namespace System.Runtime.Serialization.Formatters { - - using System.Runtime.Remoting; - using System.Runtime.Serialization; - using System.Security.Permissions; - using System; - -[System.Runtime.InteropServices.ComVisible(true)] - public interface IFieldInfo - { - // Name of parameters, if null the default param names will be used - String[] FieldNames - { - [System.Security.SecurityCritical] // auto-generated_required - get; - [System.Security.SecurityCritical] // auto-generated_required - set; - } - Type[] FieldTypes - { - [System.Security.SecurityCritical] // auto-generated_required - get; - [System.Security.SecurityCritical] // auto-generated_required - set; - } - } -} diff --git a/src/mscorlib/src/System/Runtime/Serialization/Formatters/ISoapMessage.cs b/src/mscorlib/src/System/Runtime/Serialization/Formatters/ISoapMessage.cs deleted file mode 100644 index 7a4ac1e8bb..0000000000 --- a/src/mscorlib/src/System/Runtime/Serialization/Formatters/ISoapMessage.cs +++ /dev/null @@ -1,47 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - - /*============================================================ - ** - ** - ** - ** Purpose: Interface For Soap Method Call - ** - ** - ===========================================================*/ -#if FEATURE_REMOTING -namespace System.Runtime.Serialization.Formatters { - - using System.Runtime.Remoting; - using System.Runtime.Serialization; - using System.Runtime.Remoting.Messaging; - using System; - // Used to specify a call record to either the binary or xml serializer - // The call record can be transmitted as the SOAP Top record which contains - // a method name instead of an object name as the Top record's element name -[System.Runtime.InteropServices.ComVisible(true)] - public interface ISoapMessage - { - // Name of parameters, if null the default param names will be used - - String[] ParamNames {get; set;} - - // Parameter Values - Object[] ParamValues {get; set;} - - // Parameter Types - Type[] ParamTypes {get; set;} - - // MethodName - String MethodName {get; set;} - - // MethodName XmlNameSpace - String XmlNameSpace {get; set;} - - // Headers - Header[] Headers {get; set;} - } -} -#endif // FEATURE_REMOTING - diff --git a/src/mscorlib/src/System/Runtime/Serialization/Formatters/SerTrace.cs b/src/mscorlib/src/System/Runtime/Serialization/Formatters/SerTrace.cs deleted file mode 100644 index 078edee561..0000000000 --- a/src/mscorlib/src/System/Runtime/Serialization/Formatters/SerTrace.cs +++ /dev/null @@ -1,136 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -/*============================================================ - ** - ** - ** - ** Purpose: Routine used for Debugging - ** - ** - ===========================================================*/ - -namespace System.Runtime.Serialization.Formatters { - using System; - using System.Runtime.Serialization; - using System.Security.Permissions; - using System.Reflection; - using System.Diagnostics; - using System.Diagnostics.Contracts; - - // To turn on tracing the set registry - // HKEY_CURRENT_USER -> Software -> Microsoft -> .NETFramework - // new DWORD value ManagedLogFacility 0x32 where - // 0x2 is System.Runtime.Serialization - // 0x10 is Binary Formatter - // 0x20 is Soap Formatter - // - // Turn on Logging in the jitmgr - - - // remoting Wsdl logging - /// - [System.Security.SecurityCritical] // auto-generated_required - [System.Runtime.InteropServices.ComVisible(true)] - public sealed class InternalRM - { - /// - [System.Diagnostics.Conditional("_LOGGING")] - public static void InfoSoap(params Object[]messages) - { - BCLDebug.Trace("SOAP", messages); - } - - //[System.Diagnostics.Conditional("_LOGGING")] - /// - public static bool SoapCheckEnabled() - { - return BCLDebug.CheckEnabled("SOAP"); - } - } - - /// - [System.Security.SecurityCritical] // auto-generated_required - [System.Runtime.InteropServices.ComVisible(true)] - public sealed class InternalST - { - private InternalST() - { - } - - /// - [System.Diagnostics.Conditional("_LOGGING")] - public static void InfoSoap(params Object[]messages) - { - BCLDebug.Trace("SOAP", messages); - } - - //[System.Diagnostics.Conditional("_LOGGING")] - /// - public static bool SoapCheckEnabled() - { - return BCLDebug.CheckEnabled("Soap"); - } - - /// - [System.Diagnostics.Conditional("SER_LOGGING")] - public static void Soap(params Object[]messages) - { - if (!(messages[0] is String)) - messages[0] = (messages[0].GetType()).Name+" "; - else - messages[0] = messages[0]+" "; - - BCLDebug.Trace("SOAP",messages); - } - - /// - [System.Diagnostics.Conditional("_DEBUG")] - public static void SoapAssert(bool condition, String message) - { - Contract.Assert(condition, message); - } - - /// - public static void SerializationSetValue(FieldInfo fi, Object target, Object value) - { - if (fi == null) - throw new ArgumentNullException("fi"); - - if (target == null) - throw new ArgumentNullException("target"); - - if (value == null) - throw new ArgumentNullException("value"); - Contract.EndContractBlock(); - - FormatterServices.SerializationSetValue(fi, target, value); - } - - /// - public static Assembly LoadAssemblyFromString(String assemblyString) - { - return FormatterServices.LoadAssemblyFromString(assemblyString); - } - } - - internal static class SerTrace - { - [Conditional("_LOGGING")] - internal static void InfoLog(params Object[]messages) - { - BCLDebug.Trace("BINARY", messages); - } - - [Conditional("SER_LOGGING")] - internal static void Log(params Object[]messages) - { - if (!(messages[0] is String)) - messages[0] = (messages[0].GetType()).Name+" "; - else - messages[0] = messages[0]+" "; - BCLDebug.Trace("BINARY",messages); - } - } -} diff --git a/src/mscorlib/src/System/Runtime/Serialization/Formatters/SoapFault.cs b/src/mscorlib/src/System/Runtime/Serialization/Formatters/SoapFault.cs deleted file mode 100644 index bbc6768acb..0000000000 --- a/src/mscorlib/src/System/Runtime/Serialization/Formatters/SoapFault.cs +++ /dev/null @@ -1,159 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -/*============================================================ - ** - ** - ** Purpose: Specifies information for a Soap Fault - ** - ** - ===========================================================*/ -#if FEATURE_REMOTING -namespace System.Runtime.Serialization.Formatters -{ - using System; - using System.Runtime.Serialization; - using System.Runtime.Remoting; - using System.Runtime.Remoting.Metadata; - using System.Globalization; - using System.Security.Permissions; - - //* Class holds soap fault information - -[Serializable] -[SoapType(Embedded=true)] -[System.Runtime.InteropServices.ComVisible(true)] - public sealed class SoapFault : ISerializable - { - String faultCode; - String faultString; - String faultActor; - [SoapField(Embedded=true)] Object detail; - - public SoapFault() - { - } - - public SoapFault(String faultCode, String faultString, String faultActor, ServerFault serverFault) - { - this.faultCode = faultCode; - this.faultString = faultString; - this.faultActor = faultActor; - this.detail = serverFault; - } - - internal SoapFault(SerializationInfo info, StreamingContext context) - { - SerializationInfoEnumerator siEnum = info.GetEnumerator(); - - while(siEnum.MoveNext()) - { - String name = siEnum.Name; - Object value = siEnum.Value; - SerTrace.Log(this, "SetObjectData enum ",name," value ",value); - if (String.Compare(name, "faultCode", true, CultureInfo.InvariantCulture) == 0) - { - int index = ((String)value).IndexOf(':'); - if (index > -1) - faultCode = ((String)value).Substring(++index); - else - faultCode = (String)value; - } - else if (String.Compare(name, "faultString", true, CultureInfo.InvariantCulture) == 0) - faultString = (String)value; - else if (String.Compare(name, "faultActor", true, CultureInfo.InvariantCulture) == 0) - faultActor = (String)value; - else if (String.Compare(name, "detail", true, CultureInfo.InvariantCulture) == 0) - detail = value; - } - } - - [System.Security.SecurityCritical] // auto-generated_required - public void GetObjectData(SerializationInfo info, StreamingContext context) - { - info.AddValue("faultcode", "SOAP-ENV:"+faultCode); - info.AddValue("faultstring", faultString); - if (faultActor != null) - info.AddValue("faultactor", faultActor); - info.AddValue("detail", detail, typeof(Object)); - } - - public String FaultCode - { - get {return faultCode;} - set { faultCode = value;} - } - - public String FaultString - { - get {return faultString;} - set { faultString = value;} - } - - - public String FaultActor - { - get {return faultActor;} - set { faultActor = value;} - } - - - public Object Detail - { - get {return detail;} - set {detail = value;} - } - } - -[Serializable] -[SoapType(Embedded=true)] -[System.Runtime.InteropServices.ComVisible(true)] - public sealed class ServerFault - { - String exceptionType; - String message; - String stackTrace; - Exception exception; - - internal ServerFault(Exception exception) - { - this.exception = exception; - //this.exceptionType = exception.GetType().AssemblyQualifiedName; - //this.message = exception.Message; - } - - public ServerFault(String exceptionType, String message, String stackTrace) - { - this.exceptionType = exceptionType; - this.message = message; - this.stackTrace = stackTrace; - } - - - public String ExceptionType - { - get {return exceptionType;} - set { exceptionType = value;} - } - - public String ExceptionMessage - { - get {return message;} - set { message = value;} - } - - - public String StackTrace - { - get {return stackTrace;} - set {stackTrace = value;} - } - - internal Exception Exception - { - get {return exception;} - } - } -} -#endif // FEATURE_REMOTING diff --git a/src/mscorlib/src/System/Runtime/Serialization/Formatters/SoapMessage.cs b/src/mscorlib/src/System/Runtime/Serialization/Formatters/SoapMessage.cs deleted file mode 100644 index 8289e731c3..0000000000 --- a/src/mscorlib/src/System/Runtime/Serialization/Formatters/SoapMessage.cs +++ /dev/null @@ -1,77 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -/*============================================================ - ** - ** - ** - ** Purpose: Interface For Soap Method Call - ** - ** - ===========================================================*/ -#if FEATURE_REMOTING -namespace System.Runtime.Serialization.Formatters { - using System.Runtime.Remoting; - using System.Runtime.Remoting.Messaging; - using System.Runtime.Serialization; - using System; - // Class is used to return the call object for a SOAP call. - // This is used when the top SOAP object is a fake object, it contains - // a method name as the element name instead of the object name. - [Serializable] -[System.Runtime.InteropServices.ComVisible(true)] - public class SoapMessage : ISoapMessage - { - internal String[] paramNames; - internal Object[] paramValues; - internal Type[] paramTypes; - internal String methodName; - internal String xmlNameSpace; - internal Header[] headers; - - // Name of parameters, if null the default param names will be used - public String[] ParamNames - { - get {return paramNames;} - set {paramNames = value;} - } - - // Parameter Values - public Object[] ParamValues - { - get {return paramValues;} - set {paramValues = value;} - } - - public Type[] ParamTypes - { - get {return paramTypes;} - set {paramTypes = value;} - } - - // MethodName - public String MethodName - { - get {return methodName;} - set {methodName = value;} - } - - // MethodName XmlNameSpace - public String XmlNameSpace - { - get {return xmlNameSpace;} - set {xmlNameSpace = value;} - } - - // Headers - public Header[] Headers - { - get {return headers;} - set {headers = value;} - } - - - } -} -#endif // FEATURE_REMOTING diff --git a/src/mscorlib/src/System/Security/SecurityDocument.cs b/src/mscorlib/src/System/Security/SecurityDocument.cs deleted file mode 100644 index 71f69599ef..0000000000 --- a/src/mscorlib/src/System/Security/SecurityDocument.cs +++ /dev/null @@ -1,378 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -//--------------------------------------------------------------------------- -// -// -// -// PURPOSE: Represent an XML document -// -// -//--------------------------------------------------------------------------- - -namespace System.Security -{ - using System; - using System.Collections; - using System.Security.Util; - using System.Text; - using System.Globalization; - using System.IO; - using System.Diagnostics.Contracts; - using StringMaker = System.Security.Util.Tokenizer.StringMaker; - - [Serializable] - sealed internal class SecurityDocumentElement : ISecurityElementFactory - { - private int m_position; - private SecurityDocument m_document; - - internal SecurityDocumentElement( SecurityDocument document, int position ) - { - m_document = document; - m_position = position; - } - - SecurityElement ISecurityElementFactory.CreateSecurityElement() - { - return m_document.GetElement( m_position, true ); - } - - Object ISecurityElementFactory.Copy() - { - return new SecurityDocumentElement( m_document, m_position ); - } - - String ISecurityElementFactory.GetTag() - { - return m_document.GetTagForElement( m_position ); - } - - String ISecurityElementFactory.Attribute( String attributeName ) - { - return m_document.GetAttributeForElement( m_position, attributeName ); - } - - } - - - [Serializable] - sealed internal class SecurityDocument - { - internal byte[] m_data; - - internal const byte c_element = 1; - internal const byte c_attribute = 2; - internal const byte c_text = 3; - internal const byte c_children = 4; - internal const int c_growthSize = 32; - - public SecurityDocument( int numData ) - { - m_data = new byte[numData]; - } - - public SecurityDocument( byte[] data ) - { - this.m_data = data; - } - - public SecurityDocument( SecurityElement elRoot ) - { - m_data = new byte[c_growthSize]; - - int position = 0; - ConvertElement( elRoot, ref position ); - } - - public void GuaranteeSize( int size ) - { - if (m_data.Length < size) - { - byte[] m_newData = new byte[((size / c_growthSize) + 1) * c_growthSize]; - Array.Copy( m_data, 0, m_newData, 0, m_data.Length ); - m_data = m_newData; - } - } - - public void AddString( String str, ref int position ) - { - GuaranteeSize( position + str.Length * 2 + 2 ); - - for (int i = 0; i < str.Length; ++i) - { - m_data[position+(2*i)] = (byte)(str[i] >> 8); - m_data[position+(2*i)+1] = (byte)(str[i] & 0x00FF); - } - m_data[position + str.Length * 2] = 0; - m_data[position + str.Length * 2 + 1] = 0; - - position += str.Length * 2 + 2; - } - - public void AppendString( String str, ref int position ) - { - if (position <= 1 || - m_data[position - 1] != 0 || - m_data[position - 2] != 0 ) - throw new XmlSyntaxException(); - - position -= 2; - - AddString( str, ref position ); - } - - public static int EncodedStringSize( String str ) - { - return str.Length * 2 + 2; - } - - public String GetString( ref int position ) - { - return GetString( ref position, true ); - } - - public String GetString( ref int position, bool bCreate ) - { - int stringEnd; - bool bFoundEnd = false; - for (stringEnd = position; stringEnd < m_data.Length-1; stringEnd += 2) - { - if (m_data[stringEnd] == 0 && m_data[stringEnd + 1] == 0) - { - bFoundEnd = true; - break; - } - } - - Contract.Assert(bFoundEnd, "Malformed string in parse data"); - - StringMaker m = System.SharedStatics.GetSharedStringMaker(); - - try - { - - if (bCreate) - { - m._outStringBuilder = null; - m._outIndex = 0; - - for (int i = position; i < stringEnd; i += 2) - { - char c = (char)(m_data[i] << 8 | m_data[i+1]); - - // add character to the string - if (m._outIndex < StringMaker.outMaxSize) - { - // easy case - m._outChars[m._outIndex++] = c; - } - else - { - if (m._outStringBuilder == null) - { - // OK, first check if we have to init the StringBuilder - m._outStringBuilder = new StringBuilder(); - } - - // OK, copy from _outChars to _outStringBuilder - m._outStringBuilder.Append(m._outChars, 0, StringMaker.outMaxSize); - - // reset _outChars pointer - m._outChars[0] = c; - m._outIndex = 1; - } - } - } - - position = stringEnd + 2; - - if (bCreate) - return m.MakeString(); - else - return null; - } - finally - { - System.SharedStatics.ReleaseSharedStringMaker(ref m); - } - } - - - public void AddToken( byte b, ref int position ) - { - GuaranteeSize( position + 1 ); - m_data[position++] = b; - } - - public void ConvertElement( SecurityElement elCurrent, ref int position ) - { - AddToken( c_element, ref position ); - AddString( elCurrent.m_strTag, ref position ); - - if (elCurrent.m_lAttributes != null) - { - for (int i = 0; i < elCurrent.m_lAttributes.Count; i+=2) - { - AddToken( c_attribute, ref position ); - AddString( (String)elCurrent.m_lAttributes[i], ref position ); - AddString( (String)elCurrent.m_lAttributes[i+1], ref position ); - } - } - - if (elCurrent.m_strText != null) - { - AddToken( c_text, ref position ); - AddString( elCurrent.m_strText, ref position ); - } - - if (elCurrent.InternalChildren != null) - { - for (int i = 0; i < elCurrent.InternalChildren.Count; ++i) - { - ConvertElement( (SecurityElement)elCurrent.Children[i], ref position ); - } - } - AddToken( c_children, ref position ); - } - - public SecurityElement GetRootElement() - { - return GetElement( 0, true ); - } - - public SecurityElement GetElement( int position, bool bCreate ) - { - SecurityElement elRoot = InternalGetElement( ref position, bCreate ); - return elRoot; - } - - internal SecurityElement InternalGetElement( ref int position, bool bCreate ) - { - if (m_data.Length <= position) - throw new XmlSyntaxException(); - - if (m_data[position++] != c_element) - throw new XmlSyntaxException(); - - SecurityElement elCurrent = null; - String strTag = GetString( ref position, bCreate ); - if (bCreate) - elCurrent = new SecurityElement( strTag ); - - while (m_data[position] == c_attribute) - { - position++; - String strName = GetString( ref position, bCreate ); - String strValue = GetString( ref position, bCreate ); - if (bCreate) - elCurrent.AddAttribute( strName, strValue ); - } - - if (m_data[position] == c_text) - { - position++; - String strText = GetString( ref position, bCreate ); - if (bCreate) - elCurrent.m_strText = strText; - } - - while (m_data[position] != c_children) - { - SecurityElement elChild = InternalGetElement( ref position, bCreate ); - if (bCreate) - elCurrent.AddChild( elChild ); - } - position++; - - return elCurrent; - } - - public String GetTagForElement( int position ) - { - if (m_data.Length <= position) - throw new XmlSyntaxException(); - - if (m_data[position++] != c_element) - throw new XmlSyntaxException(); - - String strTag = GetString( ref position ); - return strTag; - } - - public ArrayList GetChildrenPositionForElement( int position ) - { - if (m_data.Length <= position) - throw new XmlSyntaxException(); - - if (m_data[position++] != c_element) - throw new XmlSyntaxException(); - - ArrayList children = new ArrayList(); - - // This is to move past the tag string - GetString( ref position ); - - while (m_data[position] == c_attribute) - { - position++; - // Read name and value, then throw them away - GetString( ref position, false ); - GetString( ref position, false ); - } - - if (m_data[position] == c_text) - { - position++; - // Read text, then throw it away. - GetString( ref position, false ); - } - - while (m_data[position] != c_children) - { - children.Add( position ); - InternalGetElement( ref position, false ); - } - position++; - - return children; - } - - public String GetAttributeForElement( int position, String attributeName ) - { - if (m_data.Length <= position) - throw new XmlSyntaxException(); - - if (m_data[position++] != c_element) - throw new XmlSyntaxException(); - - String strRetValue = null; - // This is to move past the tag string. - GetString( ref position, false ); - - - while (m_data[position] == c_attribute) - { - position++; - String strName = GetString( ref position ); - String strValue = GetString( ref position ); - - if (String.Equals( strName, attributeName )) - { - strRetValue = strValue; - break; - } - } - - - return strRetValue; - } - } -} - - - - - - diff --git a/src/mscorlib/src/System/Security/Util/Parser.cs b/src/mscorlib/src/System/Security/Util/Parser.cs deleted file mode 100644 index 49c9a266f6..0000000000 --- a/src/mscorlib/src/System/Security/Util/Parser.cs +++ /dev/null @@ -1,510 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -/*============================================================ -** -** -** -** -** -** PURPOSE: Parse "Elementary XML", that is, XML without -** attributes or DTDs, in other words, XML with -** elements only. -** -** -===========================================================*/ -namespace System.Security.Util { - using System.Text; - using System.Runtime.InteropServices; - using System; - using BinaryReader = System.IO.BinaryReader ; - using ArrayList = System.Collections.ArrayList; - using Stream = System.IO.Stream; - using StreamReader = System.IO.StreamReader; - using Encoding = System.Text.Encoding; - - sealed internal class Parser - { - private SecurityDocument _doc; - private Tokenizer _t; - - internal SecurityElement GetTopElement() - { - return _doc.GetRootElement(); - } - - private const short c_flag = 0x4000; - private const short c_elementtag = (short)(SecurityDocument.c_element << 8 | c_flag); - private const short c_attributetag = (short)(SecurityDocument.c_attribute << 8 | c_flag); - private const short c_texttag = (short)(SecurityDocument.c_text << 8 | c_flag); - private const short c_additionaltexttag = (short)(SecurityDocument.c_text << 8 | c_flag | 0x2000); - private const short c_childrentag = (short)(SecurityDocument.c_children << 8 | c_flag); - private const short c_wastedstringtag = (short)(0x1000 | c_flag); - - private void GetRequiredSizes( TokenizerStream stream, ref int index ) - { - // - // Iteratively collect stuff up until the next end-tag. - // We've already seen the open-tag. - // - - bool needToBreak = false; - bool needToPop = false; - bool createdNode = false; - bool intag = false; - int stackDepth = 1; - SecurityElementType type = SecurityElementType.Regular; - String strValue = null; - bool sawEquals = false; - bool sawText = false; - int status = 0; - - short i; - - do - { - for (i = stream.GetNextToken() ; i != -1 ; i = stream.GetNextToken()) - { - switch (i & 0x00FF) - { - case Tokenizer.cstr: - { - if (intag) - { - if (type == SecurityElementType.Comment) - { - // Ignore data in comments but still get the data - // to keep the stream in the right place. - stream.ThrowAwayNextString(); - stream.TagLastToken( c_wastedstringtag ); - } - else - { - // We're in a regular tag, so we've found an attribute/value pair. - - if (strValue == null) - { - // Found attribute name, save it for later. - - strValue = stream.GetNextString(); - } - else - { - // Found attribute text, add the pair to the current element. - - if (!sawEquals) - throw new XmlSyntaxException( _t.LineNo ); - - stream.TagLastToken( c_attributetag ); - index += SecurityDocument.EncodedStringSize( strValue ) + - SecurityDocument.EncodedStringSize( stream.GetNextString() ) + - 1; - strValue = null; - sawEquals = false; - } - } - } - else - { - // We're not in a tag, so we've found text between tags. - - if (sawText) - { - stream.TagLastToken( c_additionaltexttag ); - index += SecurityDocument.EncodedStringSize( stream.GetNextString() ) + - SecurityDocument.EncodedStringSize( " " ); - } - else - { - stream.TagLastToken( c_texttag ); - index += SecurityDocument.EncodedStringSize( stream.GetNextString() ) + - 1; - sawText = true; - } - } - } - break; - - case Tokenizer.bra: - intag = true; - sawText = false; - i = stream.GetNextToken(); - - if (i == Tokenizer.slash) - { - stream.TagLastToken( c_childrentag ); - while (true) - { - // spin; don't care what's in here - i = stream.GetNextToken(); - if (i == Tokenizer.cstr) - { - stream.ThrowAwayNextString(); - stream.TagLastToken( c_wastedstringtag ); - } - else if (i == -1) - throw new XmlSyntaxException (_t.LineNo, Environment.GetResourceString( "XMLSyntax_UnexpectedEndOfFile" )); - else - break; - } - - if (i != Tokenizer.ket) - { - throw new XmlSyntaxException (_t.LineNo, Environment.GetResourceString( "XMLSyntax_ExpectedCloseBracket" )); - } - - intag = false; - - // Found the end of this element - index++; - - sawText = false; - stackDepth--; - - needToBreak = true; - } - else if (i == Tokenizer.cstr) - { - // Found a child - - createdNode = true; - - stream.TagLastToken( c_elementtag ); - index += SecurityDocument.EncodedStringSize( stream.GetNextString() ) + - 1; - - if (type != SecurityElementType.Regular) - throw new XmlSyntaxException( _t.LineNo ); - - needToBreak = true; - stackDepth++; - } - else if (i == Tokenizer.bang) - { - // Found a child that is a comment node. Next up better be a cstr. - - status = 1; - - do - { - i = stream.GetNextToken(); - - switch (i) - { - case Tokenizer.bra: - status++; - break; - - case Tokenizer.ket: - status--; - break; - - case Tokenizer.cstr: - stream.ThrowAwayNextString(); - stream.TagLastToken( c_wastedstringtag ); - break; - - default: - break; - } - } while (status > 0); - - intag = false; - sawText = false; - needToBreak = true; - } - else if (i == Tokenizer.quest) - { - // Found a child that is a format node. Next up better be a cstr. - - i = stream.GetNextToken(); - - if (i != Tokenizer.cstr) - throw new XmlSyntaxException( _t.LineNo ); - - createdNode = true; - - type = SecurityElementType.Format; - - stream.TagLastToken( c_elementtag ); - index += SecurityDocument.EncodedStringSize( stream.GetNextString() ) + - 1; - - status = 1; - stackDepth++; - - needToBreak = true; - } - else - { - throw new XmlSyntaxException (_t.LineNo, Environment.GetResourceString( "XMLSyntax_ExpectedSlashOrString" )); - } - break ; - - case Tokenizer.equals: - sawEquals = true; - break; - - case Tokenizer.ket: - if (intag) - { - intag = false; - continue; - } - else - { - throw new XmlSyntaxException (_t.LineNo, Environment.GetResourceString( "XMLSyntax_UnexpectedCloseBracket" )); - } - // not reachable - - case Tokenizer.slash: - i = stream.GetNextToken(); - - if (i == Tokenizer.ket) - { - // Found the end of this element - stream.TagLastToken( c_childrentag ); - index++; - stackDepth--; - sawText = false; - - needToBreak = true; - } - else - { - throw new XmlSyntaxException (_t.LineNo, Environment.GetResourceString( "XMLSyntax_ExpectedCloseBracket" )); - } - break; - - case Tokenizer.quest: - if (intag && type == SecurityElementType.Format && status == 1) - { - i = stream.GetNextToken(); - - if (i == Tokenizer.ket) - { - stream.TagLastToken( c_childrentag ); - index++; - stackDepth--; - sawText = false; - - needToBreak = true; - } - else - { - throw new XmlSyntaxException (_t.LineNo, Environment.GetResourceString( "XMLSyntax_ExpectedCloseBracket" )); - } - } - else - { - throw new XmlSyntaxException (_t.LineNo); - } - break; - - case Tokenizer.dash: - default: - throw new XmlSyntaxException (_t.LineNo) ; - } - - if (needToBreak) - { - needToBreak = false; - needToPop = false; - break; - } - else - { - needToPop = true; - } - } - - if (needToPop) - { - index++; - stackDepth--; - sawText = false; - } - else if (i == -1 && (stackDepth != 1 || !createdNode)) - { - // This means that we still have items on the stack, but the end of our - // stream has been reached. - - throw new XmlSyntaxException( _t.LineNo, Environment.GetResourceString( "XMLSyntax_UnexpectedEndOfFile" )); - } - } - while (stackDepth > 1); - } - - private int DetermineFormat( TokenizerStream stream ) - { - if (stream.GetNextToken() == Tokenizer.bra) - { - if (stream.GetNextToken() == Tokenizer.quest) - { - _t.GetTokens( stream, -1, true ); - stream.GoToPosition( 2 ); - - bool sawEquals = false; - bool sawEncoding = false; - - short i; - - for (i = stream.GetNextToken(); i != -1 && i != Tokenizer.ket; i = stream.GetNextToken()) - { - switch (i) - { - case Tokenizer.cstr: - if (sawEquals && sawEncoding) - { - _t.ChangeFormat( System.Text.Encoding.GetEncoding( stream.GetNextString() ) ); - return 0; - } - else if (!sawEquals) - { - if (String.Compare( stream.GetNextString(), "encoding", StringComparison.Ordinal) == 0) - sawEncoding = true; - } - else - { - sawEquals = false; - sawEncoding = false; - stream.ThrowAwayNextString(); - } - break; - - case Tokenizer.equals: - sawEquals = true; - break; - - default: - throw new XmlSyntaxException (_t.LineNo, Environment.GetResourceString( "XMLSyntax_UnexpectedEndOfFile" )); - } - } - - return 0; - } - } - - return 2; - } - - - private void ParseContents() - { - short i; - - TokenizerStream stream = new TokenizerStream(); - - _t.GetTokens( stream, 2, false ); - stream.Reset(); - - int gotoPosition = DetermineFormat( stream ); - - stream.GoToPosition( gotoPosition ); - _t.GetTokens( stream, -1, false ); - stream.Reset(); - - int neededIndex = 0; - - GetRequiredSizes( stream, ref neededIndex ); - - _doc = new SecurityDocument( neededIndex ); - int position = 0; - - stream.Reset(); - - for (i = stream.GetNextFullToken(); i != -1; i = stream.GetNextFullToken()) - { - if ((i & c_flag) != c_flag) - continue; - else - { - switch((short)(i & 0xFF00)) - { - case c_elementtag: - _doc.AddToken( SecurityDocument.c_element, ref position ); - _doc.AddString( stream.GetNextString(), ref position ); - break; - - case c_attributetag: - _doc.AddToken( SecurityDocument.c_attribute, ref position ); - _doc.AddString( stream.GetNextString(), ref position ); - _doc.AddString( stream.GetNextString(), ref position ); - break; - - case c_texttag: - _doc.AddToken( SecurityDocument.c_text, ref position ); - _doc.AddString( stream.GetNextString(), ref position ); - break; - - case c_additionaltexttag: - _doc.AppendString( " ", ref position ); - _doc.AppendString( stream.GetNextString(), ref position ); - break; - - case c_childrentag: - _doc.AddToken( SecurityDocument.c_children, ref position ); - break; - - case c_wastedstringtag: - stream.ThrowAwayNextString(); - break; - - default: - throw new XmlSyntaxException(); - } - } - } - } - - private Parser(Tokenizer t) - { - _t = t; - _doc = null; - - try - { - ParseContents(); - } - finally - { - _t.Recycle(); - } - } - - internal Parser (String input) - : this (new Tokenizer (input)) - { - } - - internal Parser (String input, String[] searchStrings, String[] replaceStrings) - : this (new Tokenizer (input, searchStrings, replaceStrings)) - { - } - - internal Parser( byte[] array, Tokenizer.ByteTokenEncoding encoding ) - : this (new Tokenizer( array, encoding, 0 ) ) - { - } - - - internal Parser( byte[] array, Tokenizer.ByteTokenEncoding encoding, int startIndex ) - : this (new Tokenizer( array, encoding, startIndex ) ) - { - } - - internal Parser( StreamReader input ) - : this (new Tokenizer( input ) ) - { - } - - internal Parser( char[] array ) - : this (new Tokenizer( array ) ) - { - } - - } - -} - diff --git a/src/mscorlib/src/System/Security/Util/Tokenizer.cs b/src/mscorlib/src/System/Security/Util/Tokenizer.cs deleted file mode 100644 index 39cfed3a71..0000000000 --- a/src/mscorlib/src/System/Security/Util/Tokenizer.cs +++ /dev/null @@ -1,944 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -/*============================================================ -** -** -** -** -** -** PURPOSE: Tokenize "Elementary XML", that is, XML without -** attributes or DTDs, in other words, XML with -** elements only. -** -** -===========================================================*/ -namespace System.Security.Util -{ - using System.Text; - using System; - using System.IO; - using System.Globalization; - using System.Diagnostics.Contracts; - - internal sealed class Tokenizer - { - // There are five externally knowable token types: bras, kets, - // slashes, cstrs, and equals. - - internal const byte bra = 0; - internal const byte ket = 1; - internal const byte slash = 2; - internal const byte cstr = 3; - internal const byte equals = 4; - internal const byte quest = 5; - internal const byte bang = 6; - internal const byte dash = 7; - - // these are the assorted text characters that the tokenizer must - // understand to do its job - - internal const int intOpenBracket = (int) '<'; - internal const int intCloseBracket = (int) '>'; - internal const int intSlash = (int) '/'; - internal const int intEquals = (int) '='; - internal const int intQuote = (int) '\"'; - internal const int intQuest = (int) '?'; - internal const int intBang = (int) '!'; - internal const int intDash = (int) '-'; - internal const int intTab = (int) '\t'; - internal const int intCR = (int) '\r'; - internal const int intLF = (int) '\n'; - internal const int intSpace = (int) ' '; - - // this tells us where we will be getting our input from - // and what the encoding is (if any) - - private enum TokenSource - { - UnicodeByteArray, // this is little-endian unicode (there are other encodings) - UTF8ByteArray, - ASCIIByteArray, - CharArray, - String, - NestedStrings, - Other - } - - // byte streams can come in 3 different flavors - - internal enum ByteTokenEncoding - { - UnicodeTokens, // this is little-endian unicode (there are other encodings) - UTF8Tokens, - ByteTokens - } - - public int LineNo; - - // these variables represent the input state of the of the tokenizer - - private int _inProcessingTag; - private byte[] _inBytes; - private char[] _inChars; - private String _inString; - private int _inIndex; - private int _inSize; - private int _inSavedCharacter; - private TokenSource _inTokenSource; - private ITokenReader _inTokenReader; - - // these variables are used to build and deliver tokenizer output strings - - private StringMaker _maker = null; - - private String[] _searchStrings; - private String[] _replaceStrings; - - private int _inNestedIndex; - private int _inNestedSize; - private String _inNestedString; - - - //================================================================ - // Constructor uses given ICharInputStream - // - - internal void BasicInitialization() - { - LineNo = 1 ; - _inProcessingTag = 0; - _inSavedCharacter = -1; - _inIndex = 0; - _inSize = 0; - _inNestedSize = 0; - _inNestedIndex = 0; - _inTokenSource = TokenSource.Other; - _maker = System.SharedStatics.GetSharedStringMaker(); - } - - public void Recycle() - { - System.SharedStatics.ReleaseSharedStringMaker(ref _maker); // will set _maker to null - } - - internal Tokenizer (String input) - { - BasicInitialization(); - _inString = input; - _inSize = input.Length; - _inTokenSource = TokenSource.String; - } - - internal Tokenizer (String input, String[] searchStrings, String[] replaceStrings) - { - BasicInitialization(); - _inString = input; - _inSize = _inString.Length; - _inTokenSource = TokenSource.NestedStrings; - _searchStrings = searchStrings; - _replaceStrings = replaceStrings; - -#if DEBUG - Contract.Assert(searchStrings.Length == replaceStrings.Length, "different number of search/replace strings"); - Contract.Assert(searchStrings.Length != 0, "no search replace strings, shouldn't be using this ctor"); - - for (int istr=0; istr= 3 , "XML Slug too small"); - Contract.Assert( str[0] == '{', "XML Slug doesn't start with '{'" ); - Contract.Assert( str[str.Length-1] == '}', "XML Slug doesn't end with '}'" ); - - str = replaceStrings[istr]; - Contract.Assert( str != null, "XML Replacement null"); - Contract.Assert( str.Length >= 1, "XML Replacement empty"); - } -#endif - } - - internal Tokenizer (byte[] array, ByteTokenEncoding encoding, int startIndex) - { - BasicInitialization(); - _inBytes = array; - _inSize = array.Length; - _inIndex = startIndex; - - switch (encoding) - { - case ByteTokenEncoding.UnicodeTokens: - _inTokenSource = TokenSource.UnicodeByteArray; - break; - - case ByteTokenEncoding.UTF8Tokens: - _inTokenSource = TokenSource.UTF8ByteArray; - break; - - case ByteTokenEncoding.ByteTokens: - _inTokenSource = TokenSource.ASCIIByteArray; - break; - - default: - throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)encoding)); - } - } - - internal Tokenizer (char[] array) - { - BasicInitialization(); - _inChars = array; - _inSize = array.Length; - _inTokenSource = TokenSource.CharArray; - } - - internal Tokenizer (StreamReader input) - { - BasicInitialization(); - _inTokenReader = new StreamTokenReader(input); - } - - internal void ChangeFormat( System.Text.Encoding encoding ) - { - if (encoding == null) - { - return; - } - - Contract.Assert( _inSavedCharacter == -1, "There was a lookahead character at the stream change point, that means the parser is changing encodings too late" ); - - switch (_inTokenSource) - { - case TokenSource.UnicodeByteArray: - case TokenSource.UTF8ByteArray: - case TokenSource.ASCIIByteArray: - // these are the ones we can change on the fly - - if (encoding == System.Text.Encoding.Unicode) - { - _inTokenSource = TokenSource.UnicodeByteArray; - return; - } - - if (encoding == System.Text.Encoding.UTF8) - { - _inTokenSource = TokenSource.UTF8ByteArray; - return; - } -#if FEATURE_ASCII - if (encoding == System.Text.Encoding.ASCII) - { - _inTokenSource = TokenSource.ASCIIByteArray; - return; - } -#endif - break; - - case TokenSource.String: - case TokenSource.CharArray: - case TokenSource.NestedStrings: - // these are already unicode and encoding changes are moot - // they can't be further decoded - return; - } - - // if we're here it means we don't know how to change - // to the desired encoding with the memory that we have - // we'll have to do this the hard way -- that means - // creating a suitable stream from what we've got - - // this is thankfully the rare case as UTF8 and unicode - // dominate the scene - - Stream stream = null; - - switch (_inTokenSource) - { - case TokenSource.UnicodeByteArray: - case TokenSource.UTF8ByteArray: - case TokenSource.ASCIIByteArray: - stream = new MemoryStream(_inBytes, _inIndex, _inSize - _inIndex); - break; - - case TokenSource.CharArray: - case TokenSource.String: - case TokenSource.NestedStrings: - Contract.Assert(false, "attempting to change encoding on a non-changable source, should have been prevented earlier" ); - return; - - default: - StreamTokenReader reader = _inTokenReader as StreamTokenReader; - - if (reader == null) - { - Contract.Assert(false, "A new input source type has been added to the Tokenizer but it doesn't support encoding changes"); - return; - } - - stream = reader._in.BaseStream; - - Contract.Assert( reader._in.CurrentEncoding != null, "Tokenizer's StreamReader does not have an encoding" ); - - String fakeReadString = new String(' ', reader.NumCharEncountered); - stream.Position = reader._in.CurrentEncoding.GetByteCount( fakeReadString ); - break; - } - - Contract.Assert(stream != null, "The XML stream with new encoding was not properly initialized for kind of input we had"); - - // we now have an initialized memory stream based on whatever source we had before - _inTokenReader = new StreamTokenReader( new StreamReader( stream, encoding ) ); - _inTokenSource = TokenSource.Other; - } - - internal void GetTokens( TokenizerStream stream, int maxNum, bool endAfterKet ) - { - while (maxNum == -1 || stream.GetTokenCount() < maxNum) - { - int i = -1; - byte ch; - int cb = 0; - bool inLiteral = false; - bool inQuotedString = false; - - StringMaker m = _maker; - - m._outStringBuilder = null; - m._outIndex = 0; - - BEGINNING: - - if (_inSavedCharacter != -1) - { - i = _inSavedCharacter; - _inSavedCharacter = -1; - } - else switch (_inTokenSource) - { - case TokenSource.UnicodeByteArray: - if (_inIndex + 1 >= _inSize) - { - stream.AddToken( -1 ); - return; - } - - i = (int)((_inBytes[_inIndex+1]<<8) + _inBytes[_inIndex]); - _inIndex += 2; - break; - - case TokenSource.UTF8ByteArray: - if (_inIndex >= _inSize) - { - stream.AddToken( -1 ); - return; - } - - i = (int)(_inBytes[_inIndex++]); - - // single byte -- case, early out as we're done already - if ((i & 0x80) == 0x00) - break; - - // to decode the lead byte switch on the high nibble - // shifted down so the switch gets dense integers - switch ((i & 0xf0) >>4) - { - case 0x8: // 1000 (together these 4 make 10xxxxx) - case 0x9: // 1001 - case 0xa: // 1010 - case 0xb: // 1011 - // trail byte is an error - throw new XmlSyntaxException( LineNo ); - - case 0xc: // 1100 (these two make 110xxxxx) - case 0xd: // 1101 - // two byte encoding (1 trail byte) - i &= 0x1f; - cb = 2; - break; - - case 0xe: // 1110 (this gets us 1110xxxx) - // three byte encoding (2 trail bytes) - i &= 0x0f; - cb = 3; - break; - - case 0xf: // 1111 (and finally 1111xxxx) - // 4 byte encoding is an error - throw new XmlSyntaxException( LineNo ); - } - - // at least one trail byte, fetch it - if (_inIndex >= _inSize) - throw new XmlSyntaxException (LineNo, Environment.GetResourceString( "XMLSyntax_UnexpectedEndOfFile" )); - - ch = _inBytes[_inIndex++]; - - // must be trail byte encoding - if ((ch & 0xc0) != 0x80) - throw new XmlSyntaxException( LineNo ); - - i = (i<<6) | (ch & 0x3f); - - // done now if 2 byte encoding, otherwise go for 3 - if (cb == 2) - break; - - if (_inIndex >= _inSize) - throw new XmlSyntaxException (LineNo, Environment.GetResourceString( "XMLSyntax_UnexpectedEndOfFile" )); - - ch = _inBytes[_inIndex++]; - - // must be trail byte encoding - if ((ch & 0xc0) != 0x80) - throw new XmlSyntaxException( LineNo ); - - i = (i<<6) | (ch & 0x3f); - break; - - case TokenSource.ASCIIByteArray: - if (_inIndex >= _inSize) - { - stream.AddToken( -1 ); - return; - } - - i = (int)(_inBytes[_inIndex++]); - break; - - case TokenSource.CharArray: - if (_inIndex >= _inSize) - { - stream.AddToken( -1 ); - return; - } - - i = (int)(_inChars[_inIndex++]); - break; - - case TokenSource.String: - if (_inIndex >= _inSize) - { - stream.AddToken( -1 ); - return; - } - - i = (int)(_inString[_inIndex++]); - break; - - case TokenSource.NestedStrings: - if (_inNestedSize != 0) - { - if (_inNestedIndex < _inNestedSize) - { - i = _inNestedString[_inNestedIndex++]; - break; - } - - _inNestedSize = 0; - } - - if (_inIndex >= _inSize) - { - stream.AddToken( -1 ); - return; - } - - i = (int)(_inString[_inIndex++]); - - if (i != '{') - break; - - for (int istr=0; istr < _searchStrings.Length; istr++) - { - if (0==String.Compare(_searchStrings[istr], 0, _inString, _inIndex-1, _searchStrings[istr].Length, StringComparison.Ordinal)) - { - _inNestedString = _replaceStrings[istr]; - _inNestedSize = _inNestedString.Length; - _inNestedIndex = 1; - i = _inNestedString[0]; - _inIndex += _searchStrings[istr].Length - 1; - break; - } - } - - break; - - default: - i = _inTokenReader.Read(); - if (i == -1) - { - stream.AddToken( -1 ); - return; - } - break; - } - - if (!inLiteral) - { - switch (i) - { - // skip whitespace - case intSpace: - case intTab: - case intCR: - goto BEGINNING; - - // count linefeeds - case intLF: - LineNo++; - goto BEGINNING; - - case intOpenBracket: - _inProcessingTag++; - stream.AddToken( bra ); - continue; - - case intCloseBracket: - _inProcessingTag--; - stream.AddToken( ket ); - if (endAfterKet) - return; - continue; - - case intEquals: - stream.AddToken( equals ); - continue; - - case intSlash: - if (_inProcessingTag != 0) - { - stream.AddToken( slash ); - continue; - } - break; - - case intQuest: - if (_inProcessingTag != 0) - { - stream.AddToken( quest ); - continue; - } - break; - - case intBang: - if (_inProcessingTag != 0) - { - stream.AddToken( bang ); - continue; - } - break; - - case intDash: - if (_inProcessingTag != 0) - { - stream.AddToken( dash ); - continue; - } - break; - - case intQuote: - inLiteral = true; - inQuotedString = true; - goto BEGINNING; - } - } - else - { - switch (i) - { - case intOpenBracket: - if (!inQuotedString) - { - _inSavedCharacter = i; - stream.AddToken( cstr ); - stream.AddString( this.GetStringToken() ); - continue; - } - break; - - case intCloseBracket: - case intEquals: - case intSlash: - if (!inQuotedString && _inProcessingTag != 0) - { - _inSavedCharacter = i; - stream.AddToken( cstr ); - stream.AddString( this.GetStringToken() ); - continue; - } - break; - - case intQuote: - if (inQuotedString) - { - stream.AddToken( cstr ); - stream.AddString( this.GetStringToken() ); - continue; - } - break; - - case intTab: - case intCR: - case intSpace: - if (!inQuotedString) - { - stream.AddToken( cstr ); - stream.AddString( this.GetStringToken() ); - continue; - } - break; - - // count linefeeds - case intLF: - LineNo++; - - if (!inQuotedString) - { - stream.AddToken( cstr ); - stream.AddString( this.GetStringToken() ); - continue; - } - break; - } - } - - inLiteral = true; - - // add character to the string - if (m._outIndex < StringMaker.outMaxSize) - { - // easy case - m._outChars[m._outIndex++] = (char)i; - } - else - { - if (m._outStringBuilder == null) - { - // OK, first check if we have to init the StringBuilder - m._outStringBuilder = new StringBuilder(); - } - - // OK, copy from _outChars to _outStringBuilder - m._outStringBuilder.Append(m._outChars, 0, StringMaker.outMaxSize); - - // reset _outChars pointer - m._outChars[0] = (char)i; - m._outIndex = 1; - } - - goto BEGINNING; - } - } - - [Serializable] - internal sealed class StringMaker - { - String[] aStrings; - uint cStringsMax; - uint cStringsUsed; - - public StringBuilder _outStringBuilder; - public char[] _outChars; - public int _outIndex; - - public const int outMaxSize = 512; - - static uint HashString(String str) - { - uint hash = 0; - - int l = str.Length; - - // rotate in string character - for (int i=0; i < l; i++) - { - hash = (hash << 3) ^ (uint)str[i] ^ (hash >> 29); - } - - return hash; - } - - static uint HashCharArray(char[] a, int l) - { - uint hash = 0; - - // rotate in a character - for (int i=0; i < l; i++) - { - hash = (hash << 3) ^ (uint)a[i] ^ (hash >> 29); - } - - return hash; - } - - public StringMaker() - { - cStringsMax = 2048; - cStringsUsed = 0; - aStrings = new String[cStringsMax]; - _outChars = new char[outMaxSize]; - } - - bool CompareStringAndChars(String str, char [] a, int l) - { - if (str.Length != l) - return false; - - for (int i=0; i (cStringsMax / 4) * 3) - { - // we need to rehash - - uint cNewMax = cStringsMax * 2; - String [] aStringsNew = new String[cNewMax]; - - for (int i=0; i < cStringsMax;i++) - { - if (aStrings[i] != null) - { - hash = HashString(aStrings[i]) % cNewMax; - - while (aStringsNew[hash] != null) - { - // slot full, skip - if (++hash >= cNewMax) - hash = 0; - } - - aStringsNew[hash] = aStrings[i]; - } - } - - // all done, cutover to the new hash table - cStringsMax = cNewMax; - aStrings = aStringsNew; - } - - hash = HashCharArray(a, l) % cStringsMax; - - String str; - - while ((str = aStrings[hash]) != null) - { - if (CompareStringAndChars(str, a, l)) - return str; - - if (++hash >= cStringsMax) - hash = 0; - } - - str = new String(a,0,l); - aStrings[hash] = str; - cStringsUsed++; - - return str; - } - } - - //================================================================ - // - // - - private String GetStringToken () - { - return _maker.MakeString(); - } - - internal interface ITokenReader - { - int Read(); - } - - internal class StreamTokenReader : ITokenReader - { - - internal StreamReader _in; - internal int _numCharRead; - - internal StreamTokenReader(StreamReader input) - { - _in = input; - _numCharRead = 0; - } - - public virtual int Read() - { - int value = _in.Read(); - if (value != -1) - _numCharRead++; - return value; - } - - internal int NumCharEncountered - { - get - { - return _numCharRead; - } - } - } - } - - internal sealed class TokenizerShortBlock - { - internal short[] m_block = new short[16]; - internal TokenizerShortBlock m_next = null; - } - - internal sealed class TokenizerStringBlock - { - internal String[] m_block = new String[16]; - internal TokenizerStringBlock m_next = null; - } - - - internal sealed class TokenizerStream - { - private int m_countTokens; - - private TokenizerShortBlock m_headTokens; - private TokenizerShortBlock m_lastTokens; - private TokenizerShortBlock m_currentTokens; - private int m_indexTokens; - - private TokenizerStringBlock m_headStrings; - private TokenizerStringBlock m_currentStrings; - private int m_indexStrings; - -#if _DEBUG - private bool m_bLastWasCStr; -#endif - - internal TokenizerStream() - { - m_countTokens = 0; - m_headTokens = new TokenizerShortBlock(); - m_headStrings = new TokenizerStringBlock(); - Reset(); - } - - internal void AddToken( short token ) - { - if (m_currentTokens.m_block.Length <= m_indexTokens) - { - m_currentTokens.m_next = new TokenizerShortBlock(); - m_currentTokens = m_currentTokens.m_next; - m_indexTokens = 0; - } - - m_countTokens++; - m_currentTokens.m_block[m_indexTokens++] = token; - } - - internal void AddString( String str ) - { - if (m_currentStrings.m_block.Length <= m_indexStrings) - { - m_currentStrings.m_next = new TokenizerStringBlock(); - m_currentStrings = m_currentStrings.m_next; - m_indexStrings = 0; - } - - m_currentStrings.m_block[m_indexStrings++] = str; - } - - internal void Reset() - { - m_lastTokens = null; - m_currentTokens = m_headTokens; - m_currentStrings = m_headStrings; - m_indexTokens = 0; - m_indexStrings = 0; -#if _DEBUG - m_bLastWasCStr = false; -#endif - } - - internal short GetNextFullToken() - { - if (m_currentTokens.m_block.Length <= m_indexTokens) - { - m_lastTokens = m_currentTokens; - m_currentTokens = m_currentTokens.m_next; - m_indexTokens = 0; - } - - return m_currentTokens.m_block[m_indexTokens++]; - } - - internal short GetNextToken() - { - short retval = (short)(GetNextFullToken() & 0x00FF); -#if _DEBUG - Contract.Assert( !m_bLastWasCStr, "CStr token not followed by GetNextString()" ); - m_bLastWasCStr = (retval == Tokenizer.cstr); -#endif - return retval; - } - - internal String GetNextString() - { - if (m_currentStrings.m_block.Length <= m_indexStrings) - { - m_currentStrings = m_currentStrings.m_next; - m_indexStrings = 0; - } -#if _DEBUG - m_bLastWasCStr = false; -#endif - return m_currentStrings.m_block[m_indexStrings++]; - } - - internal void ThrowAwayNextString() - { - GetNextString(); - } - - internal void TagLastToken( short tag ) - { - if (m_indexTokens == 0) - m_lastTokens.m_block[m_lastTokens.m_block.Length-1] = (short)((ushort)m_lastTokens.m_block[m_lastTokens.m_block.Length-1] | (ushort)tag); - else - m_currentTokens.m_block[m_indexTokens-1] = (short)((ushort)m_currentTokens.m_block[m_indexTokens-1] | (ushort)tag); - } - - internal int GetTokenCount() - { - return m_countTokens; - } - - internal void GoToPosition( int position ) - { - Reset(); - - for (int count = 0; count < position; ++count) - { - if (GetNextToken() == Tokenizer.cstr) - ThrowAwayNextString(); - } - } - } -} diff --git a/src/mscorlib/src/System/Security/XMLSyntaxException.cs b/src/mscorlib/src/System/Security/XMLSyntaxException.cs deleted file mode 100644 index bb332907d6..0000000000 --- a/src/mscorlib/src/System/Security/XMLSyntaxException.cs +++ /dev/null @@ -1,54 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// - -namespace System.Security { - using System; - using System.Runtime.Serialization; - using System.Globalization; - - [System.Runtime.InteropServices.ComVisible(true)] - [Serializable] sealed public class XmlSyntaxException : SystemException - { - public - XmlSyntaxException () - : base (Environment.GetResourceString( "XMLSyntax_InvalidSyntax" )) - { - SetErrorCode(__HResults.CORSEC_E_XMLSYNTAX); - } - - public - XmlSyntaxException (String message) - : base (message) - { - SetErrorCode(__HResults.CORSEC_E_XMLSYNTAX); - } - - public - XmlSyntaxException (String message, Exception inner) - : base (message, inner) - { - SetErrorCode(__HResults.CORSEC_E_XMLSYNTAX); - } - - public - XmlSyntaxException (int lineNumber) - : base (String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "XMLSyntax_SyntaxError" ), lineNumber ) ) - { - SetErrorCode(__HResults.CORSEC_E_XMLSYNTAX); - } - - public - XmlSyntaxException( int lineNumber, String message ) - : base( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "XMLSyntax_SyntaxErrorEx" ), lineNumber, message ) ) - { - SetErrorCode(__HResults.CORSEC_E_XMLSYNTAX); - } - - internal XmlSyntaxException(SerializationInfo info, StreamingContext context) : base(info, context) - { - } - } -} -- 2.34.1