X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FI18N%2FRare%2FCP1026.cs;h=a9a90feb6d757c78323f513a7ac0a38d9f042230;hb=1ed1fcdde699607e36a6484e1e62017faec73816;hp=997411d660019cf407d19741929f92d566262d6f;hpb=0ca4c0c5ef6ba0bf13fd721deb36e7b501ec5829;p=mono.git diff --git a/mcs/class/I18N/Rare/CP1026.cs b/mcs/class/I18N/Rare/CP1026.cs index 997411d6600..a9a90feb6d7 100644 --- a/mcs/class/I18N/Rare/CP1026.cs +++ b/mcs/class/I18N/Rare/CP1026.cs @@ -24,6 +24,9 @@ // Generated from "ibm-1026.ucm". +// WARNING: Modifying this file directly might be a bad idea. +// You should edit the code generator tools/ucm2cp.c instead for your changes +// to appear in all relevant classes. namespace I18N.Rare { @@ -86,8 +89,53 @@ public class CP1026 : ByteEncoding '\u0022', '\u00D9', '\u00DA', '\u009F', }; + // Get the number of bytes needed to encode a character buffer. + public unsafe override int GetByteCountImpl (char* chars, int count) + { + if (this.EncoderFallback != null) { + //Calculate byte count by actually doing encoding and discarding the data. + return GetBytesImpl(chars, count, null, 0); + } + else + + { + return count; + } + } + + // Get the number of bytes needed to encode a character buffer. + public override int GetByteCount (String s) + { + if (this.EncoderFallback != null) + { + //Calculate byte count by actually doing encoding and discarding the data. + unsafe + { + fixed (char *s_ptr = s) + { + return GetBytesImpl(s_ptr, s.Length, null, 0); + } + } + } + else + { + //byte count equals character count because no EncoderFallback set + return s.Length; + } + } + + //ToBytes is just an alias for GetBytesImpl, but doesn't return byte count protected unsafe override void ToBytes(char* chars, int charCount, byte* bytes, int byteCount) + { + //Calling ToBytes with null destination buffer doesn't make any sense + if (bytes == null) + throw new ArgumentNullException("bytes"); + GetBytesImpl(chars, charCount, bytes, byteCount); + } + + public unsafe override int GetBytesImpl (char* chars, int charCount, + byte* bytes, int byteCount) { int ch; int charIndex = 0; @@ -95,9 +143,11 @@ public class CP1026 : ByteEncoding #if NET_2_0 EncoderFallbackBuffer buffer = null; #endif - while(charCount > 0) + while (charCount > 0) { - ch = (int)(chars[charIndex++]); + ch = (int)(chars[charIndex]); + charIndex++; + charCount--; if(ch >= 4) switch(ch) { case 0x000B: @@ -485,17 +535,16 @@ public class CP1026 : ByteEncoding case 0xFF5D: ch = 0x8C; break; case 0xFF5E: ch = 0xCC; break; default: -#if NET_2_0 HandleFallback (ref buffer, chars, ref charIndex, ref charCount, bytes, ref byteIndex, ref byteCount); -#else - ch = 0x3F; -#endif - break; + continue; } - bytes[byteIndex++] = (byte)ch; - --charCount; - --byteCount; + //Write encoded byte to buffer, if buffer is defined and fallback was not used + if (bytes != null) + bytes[byteIndex] = (byte)ch; + byteIndex++; + byteCount--; } + return byteIndex; } /*