PageRenderTime 60ms CodeModel.GetById 12ms 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
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
  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. using System;
  16. using System.Collections.Generic;
  17. using Microsoft.Scripting.Utils;
  18. using System.Text;
  19. using IronRuby.Runtime;
  20. using System.Diagnostics;
  21. using System.IO;
  22. namespace IronRuby.Builtins {
  23. public partial class MutableString {
  24. // TODO: Add range checks to APIs or change the implementation to be out-of-range tolerant (see GetSlice).
  25. // 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.
  26. [Serializable]
  27. private abstract class Content {
  28. protected MutableString _owner;
  29. #region Utils
  30. internal void SetOwner(MutableString/*!*/ owner) {
  31. Assert.NotNull(owner);
  32. Debug.Assert(_owner == null || _owner.Encoding == owner.Encoding);
  33. _owner = owner;
  34. }
  35. protected Content(MutableString owner) {
  36. _owner = owner;
  37. }
  38. protected BinaryContent/*!*/ WrapContent(byte[]/*!*/ bytes, int count) {
  39. BinaryContent result = new BinaryContent(bytes, count, _owner);
  40. _owner.SetContent(result);
  41. return result;
  42. }
  43. protected CharArrayContent/*!*/ WrapContent(char[]/*!*/ chars, int count) {
  44. var result = new CharArrayContent(chars, count, _owner);
  45. _owner.SetContent(result);
  46. return result;
  47. }
  48. #endregion
  49. public abstract string/*!*/ ConvertToString();
  50. public abstract byte[]/*!*/ ConvertToBytes();
  51. public abstract Content/*!*/ SwitchToBinaryContent();
  52. public abstract Content/*!*/ SwitchToStringContent();
  53. public abstract Content/*!*/ SwitchToMutableContent();
  54. public abstract void CheckEncoding();
  55. public abstract bool ContainsInvalidCharacters();
  56. public abstract byte[]/*!*/ ToByteArray();
  57. internal abstract byte[]/*!*/ GetByteArray(out int count);
  58. // returns self if there are no characters to be escaped:
  59. public abstract Content/*!*/ EscapeRegularExpression();
  60. // read:
  61. public abstract bool IsBinary { get; }
  62. public abstract bool IsEmpty { get; }
  63. public abstract int Count { get; set; }
  64. public abstract int GetBinaryHashCode(out int binarySum);
  65. public abstract int GetHashCode(out int binarySum);
  66. public abstract int GetCharCount();
  67. public abstract int GetByteCount();
  68. public abstract void TrimExcess();
  69. public abstract int GetCapacity();
  70. public abstract void SetCapacity(int capacity);
  71. public abstract Content/*!*/ Clone();
  72. public abstract char GetChar(int index);
  73. public abstract byte GetByte(int index);
  74. public abstract CharacterEnumerator/*!*/ GetCharacters();
  75. public abstract IEnumerable<byte>/*!*/ GetBytes();
  76. public abstract int OrdinalCompareTo(string/*!*/ str);
  77. public abstract int OrdinalCompareTo(Content/*!*/ content);
  78. public abstract int ReverseOrdinalCompareTo(BinaryContent/*!*/ content);
  79. public abstract int ReverseOrdinalCompareTo(CharArrayContent/*!*/ content);
  80. public abstract int ReverseOrdinalCompareTo(StringContent/*!*/ content);
  81. /// <summary>
  82. /// 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.
  83. /// Returns an empty content if start is greater than the size of the content.
  84. /// The owner of the result is the current owner.
  85. /// </summary>
  86. public abstract Content/*!*/ GetSlice(int start, int count);
  87. public abstract string/*!*/ GetStringSlice(int start, int count);
  88. public abstract byte[]/*!*/ GetBinarySlice(int start, int count);
  89. public abstract bool StartsWith(char c);
  90. public abstract int IndexOf(char c, int start, int count);
  91. public abstract int IndexOf(byte b, int start, int count);
  92. public abstract int IndexOf(string/*!*/ str, int start, int count);
  93. public abstract int IndexOf(byte[]/*!*/ bytes, int start, int count);
  94. public abstract int IndexIn(Content/*!*/ str, int start, int count);
  95. public abstract int LastIndexOf(char c, int start, int count);
  96. public abstract int LastIndexOf(byte b, int start, int count);
  97. public abstract int LastIndexOf(string/*!*/ str, int start, int count);
  98. public abstract int LastIndexOf(byte[]/*!*/ bytes, int start, int count);
  99. public abstract int LastIndexIn(Content/*!*/ str, int start, int count);
  100. public abstract Content/*!*/ Concat(Content/*!*/ content);
  101. public abstract Content/*!*/ ConcatTo(BinaryContent/*!*/ content);
  102. public abstract Content/*!*/ ConcatTo(CharArrayContent/*!*/ content);
  103. public abstract Content/*!*/ ConcatTo(StringContent/*!*/ content);
  104. // write:
  105. public abstract void Append(char c, int repeatCount);
  106. public abstract void Append(byte b, int repeatCount);
  107. public abstract void Append(string/*!*/ str, int start, int count);
  108. public abstract void Append(char[]/*!*/ chars, int start, int count);
  109. public abstract void Append(byte[]/*!*/ bytes, int start, int count);
  110. public abstract void Append(Stream/*!*/ stream, int count);
  111. public abstract void Append(Content/*!*/ content, int start, int count);
  112. public abstract void AppendTo(BinaryContent/*!*/ content, int start, int count);
  113. public abstract void AppendTo(CharArrayContent/*!*/ content, int start, int count);
  114. public abstract void AppendTo(StringContent/*!*/ content, int start, int count);
  115. public abstract void AppendFormat(IFormatProvider provider, string/*!*/ format, object[]/*!*/ args);
  116. public abstract void Insert(int index, char c);
  117. public abstract void Insert(int index, byte b);
  118. public abstract void Insert(int index, string/*!*/ str, int start, int count);
  119. public abstract void Insert(int index, char[]/*!*/ chars, int start, int count);
  120. public abstract void Insert(int index, byte[]/*!*/ bytes, int start, int count);
  121. public abstract void InsertTo(Content/*!*/ str, int index, int start, int count);
  122. public abstract void SetByte(int index, byte b);
  123. public abstract void SetChar(int index, char c);
  124. public abstract void Remove(int start, int count);
  125. public abstract void Write(int offset, byte[]/*!*/ value, int start, int count);
  126. public abstract void Write(int offset, byte value, int repeatCount);
  127. }
  128. }
  129. }