X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FI18N%2FWest%2FCP1252.cs;h=72908a46fd5b998990e407e9b269fab356b9e3c0;hb=9afab4092501a7e7e240a2dd9ed0892d1e0821de;hp=b0885181980f8de3a3772924a554d0a77d9ec600;hpb=ddf7bb1b79845462a44dd4e980654d8f7b1d0177;p=mono.git diff --git a/mcs/class/I18N/West/CP1252.cs b/mcs/class/I18N/West/CP1252.cs index b0885181980..72908a46fd5 100644 --- a/mcs/class/I18N/West/CP1252.cs +++ b/mcs/class/I18N/West/CP1252.cs @@ -24,6 +24,9 @@ // Generated from "ibm-5348.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.West { @@ -86,19 +89,63 @@ public class CP1252 : ByteEncoding '\u00FC', '\u00FD', '\u00FE', '\u00FF', }; + // 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; int byteIndex = 0; -#if NET_2_0 EncoderFallbackBuffer buffer = null; -#endif - while(charCount > 0) + while (charCount > 0) { - ch = (int)(chars[charIndex++]); - --charCount; + ch = (int)(chars[charIndex]); + charIndex++; + charCount--; if(ch >= 128) switch(ch) { case 0x0081: @@ -233,21 +280,24 @@ public class CP1252 : ByteEncoding default: { if(ch >= 0xFF01 && ch <= 0xFF5E) + { ch -= 0xFEE0; - else { -#if NET_2_0 + } + else + { HandleFallback (ref buffer, chars, ref charIndex, ref charCount, bytes, ref byteIndex, ref byteCount); continue; -#else - ch = 0x3F; -#endif } } break; } - bytes[byteIndex++] = (byte)ch; - --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; } /* @@ -392,9 +442,13 @@ public class CP1252 : ByteEncoding default: { if(ch >= 0xFF01 && ch <= 0xFF5E) + { ch -= 0xFEE0; + } else + { ch = 0x3F; + } } break; }