private static MutableString[] /*!*/ Convert( MutableString /*!*/ toEncoding, MutableString /*!*/ fromEncoding, MutableString[] /*!*/ strings) { Iconv conveter = Create(null, toEncoding, fromEncoding); MutableString[] convertedStrings = new MutableString[strings.Length]; for (int i = 0; i < strings.Length; i++) { convertedStrings[i] = iconv(conveter, strings[i], 0, -1); } MutableString closingString = conveter.Close(false); if (closingString.IsEmpty) { return(convertedStrings); } else { Array.Resize(ref convertedStrings, strings.Length + 1); convertedStrings[strings.Length] = closingString; } return(convertedStrings); }
public static MutableString Close(Iconv/*!*/ self) { if (!self._isClosed) { return self.Close(false); } else { return null; } }
public static MutableString /*!*/ Close(Iconv /*!*/ self) { if (!self._isClosed) { return(self.Close(false)); } else { return(null); } }
public static MutableString/*!*/ iconv(Iconv/*!*/ self, [DefaultProtocol]MutableString str, [DefaultProtocol, DefaultParameterValue(0)]int startIndex, [DefaultProtocol, NotNull, DefaultParameterValue(-1)]int length) { if (self._isClosed) { throw RubyExceptions.CreateArgumentError("closed stream"); } if (str == null) { return self.Close(true); } // TODO: int bytesUsed, charsUsed; bool completed; byte[] source = str.ConvertToBytes(); if (startIndex < 0) { startIndex = source.Length + startIndex; if (startIndex < 0) { //throw new IllegalSequence("start index is too large of a negative number"); startIndex = 0; length = 0; } } else if (startIndex > source.Length) { startIndex = 0; length = 0; } if ((length < 0) || (startIndex + length > source.Length)) { length = source.Length - startIndex; } char[] buffer = new char[self._fromEncoding.GetCharCount(source, startIndex, length)]; self._fromEncoding.Convert(source, startIndex, length, buffer, 0, buffer.Length, false, out bytesUsed, out charsUsed, out completed); Debug.Assert(charsUsed == buffer.Length && bytesUsed == length); byte[] result = new byte[self._toEncoding.GetByteCount(buffer, 0, buffer.Length, false)]; int bytesEncoded = self._toEncoding.GetBytes(buffer, 0, buffer.Length, result, 0, false); Debug.Assert(bytesEncoded == result.Length); if (self._emitBom && result.Length > 0) { byte[] resultWithBom = new byte[2 + result.Length]; resultWithBom[0] = 0xff; resultWithBom[1] = 0xfe; Array.Copy(result, 0, resultWithBom, 2, result.Length); result = resultWithBom; self._emitBom = false; } return MutableString.CreateBinary(result); }
public static MutableString /*!*/ iconv(Iconv /*!*/ self, [DefaultProtocol] MutableString str, [DefaultProtocol, DefaultParameterValue(0)] int startIndex, [DefaultProtocol, NotNull, DefaultParameterValue(-1)] int length) { if (self._isClosed) { throw RubyExceptions.CreateArgumentError("closed stream"); } if (str == null) { return(self.Close(true)); } // TODO: int bytesUsed, charsUsed; bool completed; byte[] source = str.ConvertToBytes(); if (startIndex < 0) { startIndex = source.Length + startIndex; if (startIndex < 0) { //throw new IllegalSequence("start index is too large of a negative number"); startIndex = 0; length = 0; } } else if (startIndex > source.Length) { startIndex = 0; length = 0; } if ((length < 0) || (startIndex + length > source.Length)) { length = source.Length - startIndex; } char[] buffer = new char[self._fromEncoding.GetCharCount(source, startIndex, length)]; self._fromEncoding.Convert(source, startIndex, length, buffer, 0, buffer.Length, false, out bytesUsed, out charsUsed, out completed); Debug.Assert(charsUsed == buffer.Length && bytesUsed == length); byte[] result = new byte[self._toEncoding.GetByteCount(buffer, 0, buffer.Length, false)]; int bytesEncoded = self._toEncoding.GetBytes(buffer, 0, buffer.Length, result, 0, false); Debug.Assert(bytesEncoded == result.Length); if (self._emitBom && result.Length > 0) { byte[] resultWithBom = new byte[2 + result.Length]; resultWithBom[0] = 0xff; resultWithBom[1] = 0xfe; Array.Copy(result, 0, resultWithBom, 2, result.Length); result = resultWithBom; self._emitBom = false; } return(MutableString.CreateBinary(result)); }