PageRenderTime 31ms CodeModel.GetById 13ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/IronPython_Main/Languages/Ruby/Ruby/Builtins/MutableString.Content.cs

#
C# | 157 lines | 105 code | 28 blank | 24 comment | 3 complexity | 63d33c3470740da65bc046e6d29339c9 MD5 | raw file
  1/* ****************************************************************************
  2 *
  3 * Copyright (c) Microsoft Corporation. 
  4 *
  5 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A 
  6 * copy of the license can be found in the License.html file at the root of this distribution. If 
  7 * you cannot locate the  Apache License, Version 2.0, please send an email to 
  8 * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
  9 * by the terms of the Apache License, Version 2.0.
 10 *
 11 * You must not remove this notice, or any other, from this software.
 12 *
 13 *
 14 * ***************************************************************************/
 15
 16using System;
 17using System.Collections.Generic;
 18using Microsoft.Scripting.Utils;
 19using System.Text;
 20using IronRuby.Runtime;
 21using System.Diagnostics;
 22using System.IO;
 23
 24namespace IronRuby.Builtins {
 25    public partial class MutableString {
 26        // TODO: Add range checks to APIs or change the implementation to be out-of-range tolerant (see GetSlice).
 27        // Tha latter is preferred if the semantics is reasonable since it reduces the amounts of content size dependent checks that the user needs to do.
 28        [Serializable]
 29        private abstract class Content {
 30            protected MutableString _owner;
 31
 32            #region Utils
 33
 34            internal void SetOwner(MutableString/*!*/ owner) {
 35                Assert.NotNull(owner);
 36                Debug.Assert(_owner == null || _owner.Encoding == owner.Encoding);
 37                _owner = owner;
 38            }
 39
 40            protected Content(MutableString owner) {
 41                _owner = owner;
 42            }
 43
 44            protected BinaryContent/*!*/ WrapContent(byte[]/*!*/ bytes, int count) {
 45                BinaryContent result = new BinaryContent(bytes, count, _owner);
 46                _owner.SetContent(result);
 47                return result;
 48            }
 49            
 50            protected CharArrayContent/*!*/ WrapContent(char[]/*!*/ chars, int count) {
 51                var result = new CharArrayContent(chars, count, _owner);
 52                _owner.SetContent(result);
 53                return result;
 54            }
 55
 56            #endregion
 57
 58            public abstract string/*!*/ ConvertToString();
 59            public abstract byte[]/*!*/ ConvertToBytes();
 60            public abstract Content/*!*/ SwitchToBinaryContent();
 61            public abstract Content/*!*/ SwitchToStringContent();
 62            public abstract Content/*!*/ SwitchToMutableContent();
 63            public abstract void CheckEncoding();
 64            public abstract bool ContainsInvalidCharacters();
 65
 66            public abstract byte[]/*!*/ ToByteArray();
 67            internal abstract byte[]/*!*/ GetByteArray(out int count);
 68
 69            // returns self if there are no characters to be escaped:
 70            public abstract Content/*!*/ EscapeRegularExpression();
 71
 72            // read:
 73            public abstract bool IsBinary { get; }
 74            public abstract bool IsEmpty { get; }
 75            public abstract int Count { get; set; }
 76            public abstract int GetBinaryHashCode(out int binarySum);
 77            public abstract int GetHashCode(out int binarySum);
 78            public abstract int GetCharCount();
 79            public abstract int GetByteCount();
 80            public abstract void TrimExcess();
 81            public abstract int GetCapacity();
 82            public abstract void SetCapacity(int capacity);
 83            public abstract Content/*!*/ Clone();
 84
 85            public abstract char GetChar(int index);
 86            public abstract byte GetByte(int index);
 87
 88            public abstract CharacterEnumerator/*!*/ GetCharacters();
 89            public abstract IEnumerable<byte>/*!*/ GetBytes();
 90
 91            public abstract int OrdinalCompareTo(string/*!*/ str);
 92
 93            public abstract int OrdinalCompareTo(Content/*!*/ content);
 94            public abstract int ReverseOrdinalCompareTo(BinaryContent/*!*/ content);
 95            public abstract int ReverseOrdinalCompareTo(CharArrayContent/*!*/ content);
 96            public abstract int ReverseOrdinalCompareTo(StringContent/*!*/ content);
 97            
 98            /// <summary>
 99            /// Returns a slice of the content. The size of the slice could be less than the requested count if there is not enough data in the content.
100            /// Returns an empty content if start is greater than the size of the content.
101            /// The owner of the result is the current owner.
102            /// </summary>
103            public abstract Content/*!*/ GetSlice(int start, int count);
104            public abstract string/*!*/ GetStringSlice(int start, int count);
105            public abstract byte[]/*!*/ GetBinarySlice(int start, int count);
106
107            public abstract bool StartsWith(char c);
108
109            public abstract int IndexOf(char c, int start, int count);
110            public abstract int IndexOf(byte b, int start, int count);
111            public abstract int IndexOf(string/*!*/ str, int start, int count);
112            public abstract int IndexOf(byte[]/*!*/ bytes, int start, int count);
113            public abstract int IndexIn(Content/*!*/ str, int start, int count);
114
115            public abstract int LastIndexOf(char c, int start, int count);
116            public abstract int LastIndexOf(byte b, int start, int count);
117            public abstract int LastIndexOf(string/*!*/ str, int start, int count);
118            public abstract int LastIndexOf(byte[]/*!*/ bytes, int start, int count);
119            public abstract int LastIndexIn(Content/*!*/ str, int start, int count);
120
121            public abstract Content/*!*/ Concat(Content/*!*/ content);
122            public abstract Content/*!*/ ConcatTo(BinaryContent/*!*/ content);
123            public abstract Content/*!*/ ConcatTo(CharArrayContent/*!*/ content);
124            public abstract Content/*!*/ ConcatTo(StringContent/*!*/ content);
125
126            // write:
127            public abstract void Append(char c, int repeatCount);
128            public abstract void Append(byte b, int repeatCount);
129            public abstract void Append(string/*!*/ str, int start, int count);
130            public abstract void Append(char[]/*!*/ chars, int start, int count);
131            public abstract void Append(byte[]/*!*/ bytes, int start, int count);
132            public abstract void Append(Stream/*!*/ stream, int count);
133
134            public abstract void Append(Content/*!*/ content, int start, int count);
135            public abstract void AppendTo(BinaryContent/*!*/ content, int start, int count);
136            public abstract void AppendTo(CharArrayContent/*!*/ content, int start, int count);
137            public abstract void AppendTo(StringContent/*!*/ content, int start, int count);
138
139            public abstract void AppendFormat(IFormatProvider provider, string/*!*/ format, object[]/*!*/ args);
140            
141            public abstract void Insert(int index, char c);
142            public abstract void Insert(int index, byte b);
143            public abstract void Insert(int index, string/*!*/ str, int start, int count);
144            public abstract void Insert(int index, char[]/*!*/ chars, int start, int count);
145            public abstract void Insert(int index, byte[]/*!*/ bytes, int start, int count);
146            public abstract void InsertTo(Content/*!*/ str, int index, int start, int count);
147
148            public abstract void SetByte(int index, byte b);
149            public abstract void SetChar(int index, char c);
150
151            public abstract void Remove(int start, int count);
152
153            public abstract void Write(int offset, byte[]/*!*/ value, int start, int count);
154            public abstract void Write(int offset, byte value, int repeatCount);
155        }
156    }
157}