本文整理汇总了C#中System.Text.EncoderFallback类的典型用法代码示例。如果您正苦于以下问题:C# EncoderFallback类的具体用法?C# EncoderFallback怎么用?C# EncoderFallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EncoderFallback类属于System.Text命名空间,在下文中一共展示了EncoderFallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CodePageEncoding
protected CodePageEncoding(int codePage, string name, string webName, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
: base(codePage, encoderFallback, decoderFallback)
{
codePage_ = codePage;
encodingName_ = name;
webName_ = webName;
}
示例2: InternalGetByteCount
// Internal version of "GetByteCount" which can handle a rolling
// state between multiple calls to this method.
private static int InternalGetByteCount (char[] chars, int index, int count, EncoderFallback fallback, ref char leftOver, bool flush)
{
// Validate the parameters.
if (chars == null) {
throw new ArgumentNullException ("chars");
}
if (index < 0 || index > chars.Length) {
throw new ArgumentOutOfRangeException ("index", _("ArgRange_Array"));
}
if (count < 0 || count > (chars.Length - index)) {
throw new ArgumentOutOfRangeException ("count", _("ArgRange_Array"));
}
if (index == chars.Length) {
if (flush && leftOver != '\0') {
// Flush the left-over surrogate pair start.
leftOver = '\0';
return 3;
}
return 0;
}
unsafe {
fixed (char* cptr = chars) {
return InternalGetByteCount (cptr + index, count, fallback, ref leftOver, flush);
}
}
}
示例3: CodePageEncoding
// Constructor called by serialization.
internal CodePageEncoding(SerializationInfo info, StreamingContext context)
{
// Any info?
if (info==null) throw new ArgumentNullException(nameof(info));
Contract.EndContractBlock();
// All versions have a code page
this.m_codePage = (int)info.GetValue("m_codePage", typeof(int));
// See if we have a code page
try
{
//
// Try Whidbey V2.0 Fields
//
this.m_isReadOnly = (bool)info.GetValue("m_isReadOnly", typeof(bool));
this.encoderFallback = (EncoderFallback)info.GetValue("encoderFallback", typeof(EncoderFallback));
this.decoderFallback = (DecoderFallback)info.GetValue("decoderFallback", typeof(DecoderFallback));
}
catch (SerializationException)
{
//
// Didn't have Whidbey things, must be Everett
//
this.m_deserializedFromEverett = true;
// May as well be read only
this.m_isReadOnly = true;
}
}
示例4: BaseCodePageEncoding
internal BaseCodePageEncoding(int codepage, int dataCodePage, EncoderFallback enc, DecoderFallback dec)
: base(codepage, enc, dec)
{
// Remember number of code pages that we'll be using the table for.
dataTableCodePage = dataCodePage;
LoadCodePageTables();
}
示例5: EncoderNLSSurrogate
internal EncoderNLSSurrogate(SerializationInfo info, StreamingContext context)
{
if (info == null)
{
throw new ArgumentNullException(nameof(info));
}
_encoding = (Encoding)info.GetValue(EncodingKey, typeof(Encoding));
_fallback = (EncoderFallback)info.GetValue(DecoderFallbackKey, typeof(EncoderFallback));
_charLeftOver = (char)info.GetValue(CharLeftOverKey, typeof(char));
}
示例6: GetEncoding
public virtual Encoding GetEncoding(int codepage, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
{
Encoding enc = GetEncoding(codepage);
if (enc != null)
{
enc = (Encoding)GetEncoding(codepage).Clone();
enc.EncoderFallback = encoderFallback;
enc.DecoderFallback = decoderFallback;
}
return enc;
}
示例7: MLangCodePageEncoding
internal MLangCodePageEncoding(SerializationInfo info, StreamingContext context)
{
if (info == null)
{
throw new ArgumentNullException("info");
}
this.m_codePage = (int) info.GetValue("m_codePage", typeof(int));
try
{
this.m_isReadOnly = (bool) info.GetValue("m_isReadOnly", typeof(bool));
this.encoderFallback = (EncoderFallback) info.GetValue("encoderFallback", typeof(EncoderFallback));
this.decoderFallback = (DecoderFallback) info.GetValue("decoderFallback", typeof(DecoderFallback));
}
catch (SerializationException)
{
this.m_deserializedFromEverett = true;
this.m_isReadOnly = true;
}
}
示例8: MLangCodePageEncoding
// Constructor called by serialization.
internal MLangCodePageEncoding(SerializationInfo info, StreamingContext context)
{
// Any info?
if (info==null) throw new ArgumentNullException("info");
// All versions have a code page
this.m_codePage = (int)info.GetValue("m_codePage", typeof(int));
// See if we have a code page
try
{
this.m_isReadOnly = (bool)info.GetValue("m_isReadOnly", typeof(bool));
this.encoderFallback = (EncoderFallback)info.GetValue("encoderFallback", typeof(EncoderFallback));
this.decoderFallback = (DecoderFallback)info.GetValue("decoderFallback", typeof(DecoderFallback));
}
catch (SerializationException)
{
this.m_deserializedFromEverett = true;
// May as well be read only
this.m_isReadOnly = true;
}
}
示例9: DeserializeEncoding
// the following two methods are used for the inherited classes which implemented ISerializable
// Deserialization Helper
internal void DeserializeEncoding(SerializationInfo info, StreamingContext context)
{
// Any info?
if (info==null) throw new ArgumentNullException("info");
Contract.EndContractBlock();
// All versions have a code page
this.m_codePage = (int)info.GetValue("m_codePage", typeof(int));
// We can get dataItem on the fly if needed, and the index is different between versions
// so ignore whatever dataItem data we get from Everett.
this.dataItem = null;
// See if we have a code page
try
{
//
// Try Whidbey V2.0 Fields
//
this.m_isReadOnly = (bool)info.GetValue("m_isReadOnly", typeof(bool));
this.encoderFallback = (EncoderFallback)info.GetValue("encoderFallback", typeof(EncoderFallback));
this.decoderFallback = (DecoderFallback)info.GetValue("decoderFallback", typeof(DecoderFallback));
}
catch (SerializationException)
{
//
// Didn't have Whidbey things, must be Everett
//
this.m_deserializedFromEverett = true;
// May as well be read only
this.m_isReadOnly = true;
SetDefaultFallbacks();
}
}
示例10: GetEncoding
public static Encoding GetEncoding (string name,
EncoderFallback encoderFallback, DecoderFallback decoderFallback)
{
if (encoderFallback == null)
throw new ArgumentNullException ("encoderFallback");
if (decoderFallback == null)
throw new ArgumentNullException ("decoderFallback");
Encoding e = GetEncoding (name).Clone () as Encoding;
e.is_readonly = false;
e.encoder_fallback = encoderFallback;
e.decoder_fallback = decoderFallback;
return e;
}
示例11: SetFallbackInternal
internal void SetFallbackInternal (EncoderFallback e, DecoderFallback d)
{
if (e != null)
encoder_fallback = e;
if (d != null)
decoder_fallback = d;
}
示例12: GetEncoding
public static Encoding GetEncoding(int codepage,
EncoderFallback encoderFallback, DecoderFallback decoderFallback)
{
// Get the default encoding (which is cached and read only)
Encoding baseEncoding = GetEncoding(codepage);
// Clone it and set the fallback
Encoding fallbackEncoding = (Encoding)baseEncoding.Clone();
fallbackEncoding.EncoderFallback = encoderFallback;
fallbackEncoding.DecoderFallback = decoderFallback;
return fallbackEncoding;
}
示例13: InternalGetBytes
private unsafe static int InternalGetBytes (char* chars, int count, byte* bytes, int bcount, EncoderFallback fallback, ref EncoderFallbackBuffer buffer, ref char leftOver, bool flush)
{
char* end = chars + count;
char* start = chars;
byte* start_bytes = bytes;
byte* end_bytes = bytes + bcount;
while (chars < end) {
if (leftOver == 0) {
for (; chars < end; chars++) {
int ch = *chars;
if (ch < '\x80') {
if (bytes >= end_bytes)
goto fail_no_space;
*bytes++ = (byte)ch;
} else if (ch < '\x800') {
if (bytes + 1 >= end_bytes)
goto fail_no_space;
bytes [0] = (byte) (0xC0 | (ch >> 6));
bytes [1] = (byte) (0x80 | (ch & 0x3F));
bytes += 2;
} else if (ch < '\uD800' || ch > '\uDFFF') {
if (bytes + 2 >= end_bytes)
goto fail_no_space;
bytes [0] = (byte) (0xE0 | (ch >> 12));
bytes [1] = (byte) (0x80 | ((ch >> 6) & 0x3F));
bytes [2] = (byte) (0x80 | (ch & 0x3F));
bytes += 3;
} else if (ch <= '\uDBFF') {
// This is a surrogate char, exit the inner loop.
leftOver = *chars;
chars++;
break;
} else {
// We have a surrogate tail without
// leading surrogate. In NET_2_0 it
// uses fallback. In NET_1_1 we output
// wrong surrogate.
char [] fallback_chars = GetFallbackChars (chars, start, fallback, ref buffer);
char dummy = '\0';
if (bytes + InternalGetByteCount (fallback_chars, 0, fallback_chars.Length, fallback, ref dummy, true) > end_bytes)
goto fail_no_space;
fixed (char *fb_chars = fallback_chars) {
bytes += InternalGetBytes (fb_chars, fallback_chars.Length, bytes, bcount - (int) (bytes - start_bytes), fallback, ref buffer, ref dummy, true);
}
leftOver = '\0';
}
}
} else {
if (*chars >= '\uDC00' && *chars <= '\uDFFF') {
// We have a correct surrogate pair.
int ch = 0x10000 + (int) *chars - 0xDC00 + (((int) leftOver - 0xD800) << 10);
if (bytes + 3 >= end_bytes)
goto fail_no_space;
bytes [0] = (byte) (0xF0 | (ch >> 18));
bytes [1] = (byte) (0x80 | ((ch >> 12) & 0x3F));
bytes [2] = (byte) (0x80 | ((ch >> 6) & 0x3F));
bytes [3] = (byte) (0x80 | (ch & 0x3F));
bytes += 4;
chars++;
} else {
// We have a surrogate start followed by a
// regular character. Technically, this is
// invalid, but we have to do something.
// We write out the surrogate start and then
// re-visit the current character again.
char [] fallback_chars = GetFallbackChars (chars, start, fallback, ref buffer);
char dummy = '\0';
if (bytes + InternalGetByteCount (fallback_chars, 0, fallback_chars.Length, fallback, ref dummy, true) > end_bytes)
goto fail_no_space;
fixed (char *fb_chars = fallback_chars) {
InternalGetBytes (fb_chars, fallback_chars.Length, bytes, bcount - (int) (bytes - start_bytes), fallback, ref buffer, ref dummy, true);
}
leftOver = '\0';
}
leftOver = '\0';
}
}
if (flush) {
// Flush the left-over surrogate pair start.
if (leftOver != '\0') {
int ch = leftOver;
if (bytes + 2 < end_bytes) {
bytes [0] = (byte) (0xE0 | (ch >> 12));
bytes [1] = (byte) (0x80 | ((ch >> 6) & 0x3F));
bytes [2] = (byte) (0x80 | (ch & 0x3F));
bytes += 3;
} else {
goto fail_no_space;
}
leftOver = '\0';
}
}
return (int)(bytes - (end_bytes - bcount));
fail_no_space:
throw new ArgumentException ("Insufficient Space", "bytes");
}
示例14: SetEncoderFallback
public void SetEncoderFallback(EncoderFallback fallback) {
throw new NotImplementedException();
}
示例15: GetEncoding
public static Encoding GetEncoding(int codepage,
EncoderFallback encoderFallback, DecoderFallback decoderFallback)
{
Encoding baseEncoding = EncodingProvider.GetEncodingFromProvider(codepage, encoderFallback, decoderFallback);
if (baseEncoding != null)
return baseEncoding;
// Get the default encoding (which is cached and read only)
baseEncoding = GetEncoding(codepage);
// Clone it and set the fallback
Encoding fallbackEncoding = (Encoding)baseEncoding.Clone();
fallbackEncoding.EncoderFallback = encoderFallback;
fallbackEncoding.DecoderFallback = decoderFallback;
return fallbackEncoding;
}