9 [__DynamicallyInvokable]
15 [__DynamicallyInvokable]
18 [__DynamicallyInvokable]
26 [__DynamicallyInvokable]
32 internal override void SetDefaultFallbacks()
50 [SecuritySafeCritical]
51 [__DynamicallyInvokable]
52 public unsafe
override int GetByteCount(
char[] chars,
int index,
int count)
58 if (index < 0 || count < 0)
62 if (chars.Length - index < count)
66 if (chars.Length == 0)
70 fixed (
char* ptr = chars)
84 [SecuritySafeCritical]
85 [__DynamicallyInvokable]
92 fixed (
char* chars2 = chars)
109 [CLSCompliant(
false)]
142 [SecuritySafeCritical]
143 [__DynamicallyInvokable]
144 public unsafe
override int GetBytes(
string chars,
int charIndex,
int charCount,
byte[] bytes,
int byteIndex)
146 if (chars ==
null || bytes ==
null)
150 if (charIndex < 0 || charCount < 0)
154 if (chars.Length - charIndex < charCount)
158 if (byteIndex < 0 || byteIndex > bytes.Length)
162 int byteCount = bytes.Length - byteIndex;
163 if (bytes.Length == 0)
167 fixed (
char* ptr = chars)
169 byte[] array = bytes;
170 fixed (
byte* ptr2 = array)
172 return GetBytes(ptr + charIndex, charCount, ptr2 + byteIndex, byteCount,
null);
195 [SecuritySafeCritical]
196 [__DynamicallyInvokable]
197 public unsafe
override int GetBytes(
char[] chars,
int charIndex,
int charCount,
byte[] bytes,
int byteIndex)
199 if (chars ==
null || bytes ==
null)
203 if (charIndex < 0 || charCount < 0)
207 if (chars.Length - charIndex < charCount)
211 if (byteIndex < 0 || byteIndex > bytes.Length)
215 if (chars.Length == 0)
219 int byteCount = bytes.Length - byteIndex;
220 if (bytes.Length == 0)
224 fixed (
char* ptr = chars)
226 byte[] array = bytes;
227 fixed (
byte* ptr2 = array)
229 return GetBytes(ptr + charIndex, charCount, ptr2 + byteIndex, byteCount,
null);
250 [CLSCompliant(
false)]
252 public unsafe
override int GetBytes(
char* chars,
int charCount,
byte* bytes,
int byteCount)
254 if (bytes ==
null || chars ==
null)
258 if (charCount < 0 || byteCount < 0)
262 return GetBytes(chars, charCount, bytes, byteCount,
null);
277 [SecuritySafeCritical]
278 [__DynamicallyInvokable]
279 public unsafe
override int GetCharCount(
byte[] bytes,
int index,
int count)
285 if (index < 0 || count < 0)
289 if (bytes.Length - index < count)
293 if (bytes.Length == 0)
297 fixed (
byte* ptr = bytes)
314 [CLSCompliant(
false)]
347 [SecuritySafeCritical]
348 [__DynamicallyInvokable]
349 public unsafe
override int GetChars(
byte[] bytes,
int byteIndex,
int byteCount,
char[] chars,
int charIndex)
351 if (bytes ==
null || chars ==
null)
355 if (byteIndex < 0 || byteCount < 0)
359 if (bytes.Length - byteIndex < byteCount)
363 if (charIndex < 0 || charIndex > chars.Length)
367 if (bytes.Length == 0)
371 int charCount = chars.Length - charIndex;
372 if (chars.Length == 0)
376 fixed (
byte* ptr = bytes)
378 char[] array = chars;
379 fixed (
char* ptr2 = array)
381 return GetChars(ptr + byteIndex, byteCount, ptr2 + charIndex, charCount,
null);
402 [CLSCompliant(
false)]
404 public unsafe
override int GetChars(
byte* bytes,
int byteCount,
char* chars,
int charCount)
406 if (bytes ==
null || chars ==
null)
410 if (charCount < 0 || byteCount < 0)
414 return GetChars(bytes, byteCount, chars, charCount,
null);
429 [SecuritySafeCritical]
430 [__DynamicallyInvokable]
431 public unsafe
override string GetString(
byte[] bytes,
int byteIndex,
int byteCount)
437 if (byteIndex < 0 || byteCount < 0)
441 if (bytes.Length - byteIndex < byteCount)
445 if (bytes.Length == 0)
449 fixed (
byte* ptr = bytes)
451 return string.CreateStringFromEncoding(ptr + byteIndex, byteCount,
this);
456 internal unsafe
override int GetByteCount(
char* chars,
int charCount, EncoderNLS encoder)
460 char* ptr = chars + charCount;
464 c = encoder.charLeftOver;
466 if (encoder.InternalHasFallbackBuffer)
468 encoderFallbackBuffer = encoder.FallbackBuffer;
469 if (encoderFallbackBuffer.
Remaining > 0 && encoder.m_throwOnOverflow)
473 encoderFallbackBuffer.InternalInitialize(chars, ptr, encoder, setEncoder:
false);
478 encoderReplacementFallback = (base.EncoderFallback as EncoderReplacementFallback);
480 if (encoderReplacementFallback !=
null && encoderReplacementFallback.
MaxCharCount == 1)
491 encoderFallbackBuffer = encoder.FallbackBuffer;
492 encoderFallbackBuffer.InternalInitialize(chars, ptr, encoder, setEncoder:
false);
493 encoderFallbackBuffer.InternalFallback(c, ref chars);
497 char num2 = encoderFallbackBuffer?.InternalGetNextChar() ??
'\0';
499 if (num2 ==
'\0' && chars >= ptr)
510 if (encoderFallbackBuffer ==
null)
512 encoderFallbackBuffer = ((encoder !=
null) ? encoder.FallbackBuffer : encoderFallback.CreateFallbackBuffer());
513 encoderFallbackBuffer.InternalInitialize(ptr - charCount, ptr, encoder, setEncoder:
false);
515 encoderFallbackBuffer.InternalFallback(c2, ref chars);
526 internal unsafe
override int GetBytes(
char* chars,
int charCount,
byte* bytes,
int byteCount, EncoderNLS encoder)
529 EncoderReplacementFallback encoderReplacementFallback =
null;
530 EncoderFallbackBuffer encoderFallbackBuffer =
null;
531 char* ptr = chars + charCount;
536 c = encoder.charLeftOver;
537 encoderReplacementFallback = (encoder.Fallback as EncoderReplacementFallback);
538 if (encoder.InternalHasFallbackBuffer)
540 encoderFallbackBuffer = encoder.FallbackBuffer;
541 if (encoderFallbackBuffer.Remaining > 0 && encoder.m_throwOnOverflow)
543 throw new ArgumentException(Environment.GetResourceString(
"Argument_EncoderFallbackNotEmpty",
EncodingName, encoder.Fallback.GetType()));
545 encoderFallbackBuffer.InternalInitialize(ptr3, ptr, encoder, setEncoder:
true);
550 encoderReplacementFallback = (base.EncoderFallback as EncoderReplacementFallback);
552 if (encoderReplacementFallback !=
null && encoderReplacementFallback.MaxCharCount == 1)
554 char c2 = encoderReplacementFallback.DefaultString[0];
561 ThrowBytesOverflow(encoder, nothingEncoded:
true);
563 byte* intPtr = bytes;
568 if (byteCount < charCount)
570 ThrowBytesOverflow(encoder, byteCount < 1);
571 ptr = chars + byteCount;
575 char* intPtr2 = chars;
580 byte* intPtr3 = bytes;
586 byte* intPtr4 = bytes;
593 encoder.charLeftOver =
'\0';
594 encoder.m_charsUsed = (int)(chars - ptr3);
596 return (
int)(bytes - ptr2);
599 byte* ptr4 = bytes + byteCount;
602 encoderFallbackBuffer = encoder.FallbackBuffer;
603 encoderFallbackBuffer.InternalInitialize(chars, ptr, encoder, setEncoder:
true);
604 encoderFallbackBuffer.InternalFallback(c, ref chars);
608 char num = encoderFallbackBuffer?.InternalGetNextChar() ??
'\0';
610 if (num ==
'\0' && chars >= ptr)
621 if (encoderFallbackBuffer ==
null)
623 encoderFallbackBuffer = ((encoder !=
null) ? encoder.FallbackBuffer : encoderFallback.CreateFallbackBuffer());
624 encoderFallbackBuffer.InternalInitialize(ptr - charCount, ptr, encoder, setEncoder:
true);
626 encoderFallbackBuffer.InternalFallback(c4, ref chars);
631 if (encoderFallbackBuffer ==
null || !encoderFallbackBuffer.bFallingBack)
637 encoderFallbackBuffer.MovePrevious();
639 ThrowBytesOverflow(encoder, bytes == ptr2);
647 if (encoderFallbackBuffer !=
null && !encoderFallbackBuffer.bUsedEncoder)
649 encoder.charLeftOver =
'\0';
651 encoder.m_charsUsed = (int)(chars - ptr3);
653 return (
int)(bytes - ptr2);
657 internal unsafe
override int GetCharCount(
byte* bytes,
int count, DecoderNLS decoder)
659 DecoderReplacementFallback decoderReplacementFallback =
null;
660 decoderReplacementFallback = ((decoder !=
null) ? (decoder.Fallback as DecoderReplacementFallback) : (base.DecoderFallback as DecoderReplacementFallback));
661 if (decoderReplacementFallback !=
null && decoderReplacementFallback.MaxCharCount == 1)
665 DecoderFallbackBuffer decoderFallbackBuffer =
null;
667 byte[] array =
new byte[1];
668 byte* ptr = bytes + count;
675 if (decoderFallbackBuffer ==
null)
677 decoderFallbackBuffer = ((decoder !=
null) ? decoder.FallbackBuffer : base.DecoderFallback.CreateFallbackBuffer());
678 decoderFallbackBuffer.InternalInitialize(ptr - count,
null);
682 num += decoderFallbackBuffer.InternalFallback(array, bytes);
689 internal unsafe
override int GetChars(
byte* bytes,
int byteCount,
char* chars,
int charCount, DecoderNLS decoder)
691 byte* ptr = bytes + byteCount;
694 DecoderReplacementFallback decoderReplacementFallback =
null;
695 decoderReplacementFallback = ((decoder !=
null) ? (decoder.Fallback as DecoderReplacementFallback) : (base.DecoderFallback as DecoderReplacementFallback));
696 if (decoderReplacementFallback !=
null && decoderReplacementFallback.MaxCharCount == 1)
698 char c = decoderReplacementFallback.DefaultString[0];
699 if (charCount < byteCount)
701 ThrowCharsOverflow(decoder, charCount < 1);
702 ptr = bytes + charCount;
706 byte* intPtr = bytes;
711 char* intPtr2 = chars;
717 char* intPtr3 = chars;
724 decoder.m_bytesUsed = (int)(bytes - ptr2);
726 return (
int)(chars - ptr3);
728 DecoderFallbackBuffer decoderFallbackBuffer =
null;
729 byte[] array =
new byte[1];
730 char* ptr4 = chars + charCount;
737 if (decoderFallbackBuffer ==
null)
739 decoderFallbackBuffer = ((decoder !=
null) ? decoder.FallbackBuffer : base.DecoderFallback.CreateFallbackBuffer());
740 decoderFallbackBuffer.InternalInitialize(ptr - byteCount, ptr4);
743 if (!decoderFallbackBuffer.InternalFallback(array, bytes, ref chars))
746 decoderFallbackBuffer.InternalReset();
747 ThrowCharsOverflow(decoder, chars == ptr3);
756 ThrowCharsOverflow(decoder, chars == ptr3);
765 decoder.m_bytesUsed = (int)(bytes - ptr2);
767 return (
int)(chars - ptr3);
775 [__DynamicallyInvokable]
782 long num = (long)charCount + 1
L;
783 if (base.EncoderFallback.MaxCharCount > 1)
785 num *= base.EncoderFallback.MaxCharCount;
787 if (num >
int.MaxValue)
799 [__DynamicallyInvokable]
806 long num = byteCount;
807 if (base.DecoderFallback.MaxCharCount > 1)
809 num *= base.DecoderFallback.MaxCharCount;
811 if (num >
int.MaxValue)
821 [__DynamicallyInvokable]
824 return new DecoderNLS(
this);
830 [__DynamicallyInvokable]
833 return new EncoderNLS(
this);
static EncoderFallback ReplacementFallback
Gets an object that outputs a substitute string in place of an input character that cannot be encoded...
override int GetMaxByteCount(int charCount)
Calculates the maximum number of bytes produced by encoding the specified number of characters.
Represents a character encoding.To browse the .NET Framework source code for this type,...
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
unsafe override int GetByteCount(string chars)
Calculates the number of bytes produced by encoding the characters in the specified T:System....
override Encoder GetEncoder()
Obtains an encoder that converts a sequence of Unicode characters into an ASCII encoded sequence of b...
Converts a set of characters into a sequence of bytes.
unsafe override int GetByteCount(char *chars, int count)
Calculates the number of bytes produced by encoding a set of characters starting at the specified cha...
override int GetMaxCharCount(int byteCount)
Calculates the maximum number of characters produced by decoding the specified number of bytes.
The exception that is thrown when the value of an argument is outside the allowable range of values a...
abstract int Remaining
When overridden in a derived class, gets the number of characters in the current T:System....
unsafe override int GetBytes(string chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
Encodes a set of characters from the specified T:System.String into the specified byte array.
unsafe override int GetCharCount(byte *bytes, int count)
Calculates the number of characters produced by decoding a sequence of bytes starting at the specifie...
Provides a failure-handling mechanism, called a fallback, for an input character that cannot be conve...
unsafe override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
Decodes a sequence of bytes from the specified byte array into the specified character array.
static DecoderFallback ReplacementFallback
Gets an object that outputs a substitute string in place of an input byte sequence that cannot be dec...
unsafe override string GetString(byte[] bytes, int byteIndex, int byteCount)
Decodes a range of bytes from a byte array into a string.
Provides a failure handling mechanism, called a fallback, for an input character that cannot be conve...
Provides information about, and means to manipulate, the current environment and platform....
Converts a sequence of encoded bytes into a set of characters.
virtual string EncodingName
When overridden in a derived class, gets the human-readable description of the current encoding.
Provides a failure-handling mechanism, called a fallback, for an encoded input byte sequence that can...
unsafe override int GetBytes(char *chars, int charCount, byte *bytes, int byteCount)
Encodes a set of characters starting at the specified character pointer into a sequence of bytes that...
Represents an ASCII character encoding of Unicode characters.
override bool IsSingleByte
Gets a value indicating whether the current encoding uses single-byte code points.
override Decoder GetDecoder()
Obtains a decoder that converts an ASCII encoded sequence of bytes into a sequence of Unicode charact...
The exception that is thrown when one of the arguments provided to a method is not valid.
unsafe override int GetChars(byte *bytes, int byteCount, char *chars, int charCount)
Decodes a sequence of bytes starting at the specified byte pointer into a set of characters that are ...
unsafe override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
Encodes a set of characters from the specified character array into the specified byte array.
override int MaxCharCount
Gets the number of characters in the replacement string for the T:System.Text.EncoderReplacementFallb...
Provides a buffer that allows a fallback handler to return an alternate string to an encoder when it ...
unsafe override int GetCharCount(byte[] bytes, int index, int count)
Calculates the number of characters produced by decoding a sequence of bytes from the specified byte ...
unsafe override int GetByteCount(char[] chars, int index, int count)
Calculates the number of bytes produced by encoding a set of characters from the specified character ...
ASCIIEncoding()
Initializes a new instance of the T:System.Text.ASCIIEncoding class.