Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Xml / System / Xml / Core / CharEntityEncoderFallback.cs / 1 / CharEntityEncoderFallback.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System.Text; using System.Diagnostics; using System.Globalization; namespace System.Xml { // // CharEntityEncoderFallback // internal class CharEntityEncoderFallback : EncoderFallback { private CharEntityEncoderFallbackBuffer fallbackBuffer; private int[] textContentMarks; private int endMarkPos; private int curMarkPos; private int startOffset; internal CharEntityEncoderFallback() { } public override EncoderFallbackBuffer CreateFallbackBuffer() { if ( fallbackBuffer == null ) { fallbackBuffer = new CharEntityEncoderFallbackBuffer( this ); } return fallbackBuffer; } public override int MaxCharCount { get { return 12; } } internal int StartOffset { get { return startOffset; } set { startOffset = value; } } internal void Reset( int[] textContentMarks, int endMarkPos ) { this.textContentMarks = textContentMarks; this.endMarkPos = endMarkPos; curMarkPos = 0; } internal bool CanReplaceAt( int index ) { int mPos = curMarkPos; int charPos = startOffset + index; while ( mPos < endMarkPos && charPos >= textContentMarks[mPos+1] ) { mPos++; } curMarkPos = mPos; return (mPos & 1) != 0; } } // // CharEntityFallbackBuffer // internal class CharEntityEncoderFallbackBuffer : EncoderFallbackBuffer { private CharEntityEncoderFallback parent; private string charEntity = string.Empty; private int charEntityIndex = -1; internal CharEntityEncoderFallbackBuffer( CharEntityEncoderFallback parent ) { this.parent = parent; } public override bool Fallback( char charUnknown, int index ) { // If we are already in fallback, throw, it's probably at the suspect character in charEntity if ( charEntityIndex >= 0 ) { (new EncoderExceptionFallbackBuffer()).Fallback( charUnknown, index ); } // find out if we can replace the character with entity if ( parent.CanReplaceAt( index ) ) { // Create the replacement character entity charEntity = string.Format( CultureInfo.InvariantCulture, "{0:X};", new object[] { (int)charUnknown } ); charEntityIndex = 0; return true; } else { EncoderFallbackBuffer errorFallbackBuffer = ( new EncoderExceptionFallback() ).CreateFallbackBuffer(); errorFallbackBuffer.Fallback( charUnknown, index ); return false; } } public override bool Fallback( char charUnknownHigh, char charUnknownLow, int index ) { // check input surrogate pair if ( !char.IsSurrogatePair( charUnknownHigh, charUnknownLow ) ) { throw XmlConvert.CreateInvalidSurrogatePairException( charUnknownHigh, charUnknownLow ); } // If we are already in fallback, throw, it's probably at the suspect character in charEntity if ( charEntityIndex >= 0 ) { (new EncoderExceptionFallbackBuffer()).Fallback( charUnknownHigh, charUnknownLow, index ); } if ( parent.CanReplaceAt( index ) ) { // Create the replacement character entity charEntity = string.Format( CultureInfo.InvariantCulture, "{0:X};", new object[] { char.ConvertToUtf32( charUnknownHigh, charUnknownLow ) } ); charEntityIndex = 0; return true; } else { EncoderFallbackBuffer errorFallbackBuffer = ( new EncoderExceptionFallback() ).CreateFallbackBuffer(); errorFallbackBuffer.Fallback( charUnknownHigh, charUnknownLow, index ); return false; } } public override char GetNextChar() { if ( charEntityIndex == -1 ) { return (char)0; } else { Debug.Assert( charEntityIndex < charEntity.Length ); char ch = charEntity[charEntityIndex++]; if ( charEntityIndex == charEntity.Length ) { charEntityIndex = -1; } return ch; } } public override bool MovePrevious() { if ( charEntityIndex == -1 ) { return false; } else { Debug.Assert( charEntityIndex < charEntity.Length ); if ( charEntityIndex > 0 ) { charEntityIndex--; return true; } else { return false; } } } public override int Remaining { get { if ( charEntityIndex == -1 ) { return 0; } else { return charEntity.Length - charEntityIndex; } } } public override void Reset() { charEntityIndex = -1; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CodeDelegateCreateExpression.cs
- DataGrid.cs
- Convert.cs
- EdmFunction.cs
- EndpointConfigContainer.cs
- TemplateContent.cs
- MissingMemberException.cs
- Double.cs
- MobileCapabilities.cs
- ipaddressinformationcollection.cs
- ClientBuildManager.cs
- DataFormats.cs
- ElementNotAvailableException.cs
- ImpersonationContext.cs
- TreeView.cs
- Model3D.cs
- HtmlInputReset.cs
- isolationinterop.cs
- DurableDispatcherAddressingFault.cs
- TreeViewItemAutomationPeer.cs
- RuntimeWrappedException.cs
- DisplayNameAttribute.cs
- TextModifier.cs
- PropertyDescriptorCollection.cs
- EntityContainerEmitter.cs
- DynamicILGenerator.cs
- EdmComplexPropertyAttribute.cs
- XamlBrushSerializer.cs
- DelayLoadType.cs
- KeyValuePairs.cs
- ScalarType.cs
- FormViewCommandEventArgs.cs
- HtmlContainerControl.cs
- QueryGeneratorBase.cs
- VisualTransition.cs
- ScriptingJsonSerializationSection.cs
- SizeAnimationBase.cs
- ReflectionHelper.cs
- Nodes.cs
- IndexedString.cs
- PasswordDeriveBytes.cs
- ISAPIApplicationHost.cs
- OleDbWrapper.cs
- RectangleGeometry.cs
- PageSetupDialog.cs
- DoubleCollectionConverter.cs
- DataGridViewRowConverter.cs
- DirtyTextRange.cs
- SqlRowUpdatingEvent.cs
- SequenceFullException.cs
- ReadOnlyObservableCollection.cs
- Point3DAnimationUsingKeyFrames.cs
- Constraint.cs
- XMLDiffLoader.cs
- Substitution.cs
- DataGridViewCellEventArgs.cs
- EditCommandColumn.cs
- ParentControlDesigner.cs
- CodeDesigner.cs
- RawUIStateInputReport.cs
- XPathSelfQuery.cs
- PrefixHandle.cs
- DataGridViewComboBoxColumn.cs
- PointKeyFrameCollection.cs
- TreeNodeCollection.cs
- NetworkAddressChange.cs
- PeerToPeerException.cs
- TcpAppDomainProtocolHandler.cs
- TypeDescriptionProvider.cs
- ConditionCollection.cs
- IPEndPointCollection.cs
- KeyboardInputProviderAcquireFocusEventArgs.cs
- ColumnHeaderCollectionEditor.cs
- SQLDecimal.cs
- FixedSOMElement.cs
- DataGridViewAutoSizeColumnsModeEventArgs.cs
- SqlDataSourceCache.cs
- WebScriptMetadataMessageEncodingBindingElement.cs
- ParallelTimeline.cs
- InlineCollection.cs
- _SslSessionsCache.cs
- _UncName.cs
- ParallelTimeline.cs
- BasicExpandProvider.cs
- NetworkAddressChange.cs
- CompilerLocalReference.cs
- ListControl.cs
- VarRefManager.cs
- EntityDataSourceDataSelection.cs
- SwitchLevelAttribute.cs
- EdgeProfileValidation.cs
- InvokePatternIdentifiers.cs
- DefaultMemberAttribute.cs
- XPathEmptyIterator.cs
- CopyEncoder.cs
- TogglePattern.cs
- ContractMapping.cs
- WorkflowQueuingService.cs
- CodeEventReferenceExpression.cs
- Button.cs