/MicroFrameworkPK_v4_1/Framework/Subset_of_CorLib/System/String.cs

https://bitbucket.org/pmfsampaio/netmf-lpc · C# · 269 lines · 182 code · 64 blank · 23 comment · 18 complexity · a865ccc12b59658cf1a0b884b64b9839 MD5 · raw file

  1. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4. namespace System
  5. {
  6. using System;
  7. using System.Threading;
  8. using System.Collections;
  9. using System.Runtime.CompilerServices;
  10. /**
  11. * <p>The <code>String</code> class represents a static string of characters. Many of
  12. * the <code>String</code> methods perform some type of transformation on the current
  13. * instance and return the result as a new <code>String</code>. All comparison methods are
  14. * implemented as a part of <code>String</code>.</p> As with arrays, character positions
  15. * (indices) are zero-based.
  16. *
  17. * <p>When passing a null string into a constructor in VJ and VC, the null should be
  18. * explicitly type cast to a <code>String</code>.</p>
  19. * <p>For Example:<br>
  20. * <pre>String s = new String((String)null);
  21. * Text.Out.WriteLine(s);</pre></p>
  22. *
  23. * @author Jay Roxe (jroxe)
  24. * @version
  25. */
  26. [Serializable]
  27. public sealed class String
  28. {
  29. public static readonly String Empty = "";
  30. public override bool Equals(object obj)
  31. {
  32. String s = obj as String;
  33. if (s != null)
  34. {
  35. return String.Equals(this, s);
  36. }
  37. return false;
  38. }
  39. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  40. public extern static bool Equals(String a, String b);
  41. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  42. public extern static bool operator ==(String a, String b);
  43. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  44. public extern static bool operator !=(String a, String b);
  45. [System.Runtime.CompilerServices.IndexerName("Chars")]
  46. public extern char this[int index]
  47. {
  48. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  49. get;
  50. }
  51. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  52. public extern char[] ToCharArray();
  53. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  54. public extern char[] ToCharArray(int startIndex, int length);
  55. public extern int Length
  56. {
  57. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  58. get;
  59. }
  60. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  61. public extern String[] Split(params char[] separator);
  62. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  63. public extern String[] Split(char[] separator, int count);
  64. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  65. public extern String Substring(int startIndex);
  66. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  67. public extern String Substring(int startIndex, int length);
  68. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  69. public extern String Trim(params char[] trimChars);
  70. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  71. public extern String TrimStart(params char[] trimChars);
  72. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  73. public extern String TrimEnd(params char[] trimChars);
  74. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  75. public extern String(char[] value, int startIndex, int length);
  76. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  77. public extern String(char[] value);
  78. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  79. public extern String(char c, int count);
  80. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  81. public extern static int Compare(String strA, String strB);
  82. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  83. public extern int CompareTo(Object value);
  84. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  85. public extern int CompareTo(String strB);
  86. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  87. public extern int IndexOf(char value);
  88. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  89. public extern int IndexOf(char value, int startIndex);
  90. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  91. public extern int IndexOf(char value, int startIndex, int count);
  92. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  93. public extern int IndexOfAny(char[] anyOf);
  94. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  95. public extern int IndexOfAny(char[] anyOf, int startIndex);
  96. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  97. public extern int IndexOfAny(char[] anyOf, int startIndex, int count);
  98. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  99. public extern int IndexOf(String value);
  100. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  101. public extern int IndexOf(String value, int startIndex);
  102. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  103. public extern int IndexOf(String value, int startIndex, int count);
  104. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  105. public extern int LastIndexOf(char value);
  106. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  107. public extern int LastIndexOf(char value, int startIndex);
  108. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  109. public extern int LastIndexOf(char value, int startIndex, int count);
  110. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  111. public extern int LastIndexOfAny(char[] anyOf);
  112. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  113. public extern int LastIndexOfAny(char[] anyOf, int startIndex);
  114. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  115. public extern int LastIndexOfAny(char[] anyOf, int startIndex, int count);
  116. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  117. public extern int LastIndexOf(String value);
  118. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  119. public extern int LastIndexOf(String value, int startIndex);
  120. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  121. public extern int LastIndexOf(String value, int startIndex, int count);
  122. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  123. public extern String ToLower();
  124. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  125. public extern String ToUpper();
  126. public override String ToString()
  127. {
  128. return this;
  129. }
  130. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  131. public extern String Trim();
  132. ////// This method contains the same functionality as StringBuilder Replace. The only difference is that
  133. ////// a new String has to be allocated since Strings are immutable
  134. public static String Concat(Object arg0)
  135. {
  136. if (arg0 == null)
  137. {
  138. return String.Empty;
  139. }
  140. return arg0.ToString();
  141. }
  142. public static String Concat(Object arg0, Object arg1)
  143. {
  144. if (arg0 == null)
  145. {
  146. arg0 = String.Empty;
  147. }
  148. if (arg1 == null)
  149. {
  150. arg1 = String.Empty;
  151. }
  152. return Concat(arg0.ToString(), arg1.ToString());
  153. }
  154. public static String Concat(Object arg0, Object arg1, Object arg2)
  155. {
  156. if (arg0 == null)
  157. {
  158. arg0 = String.Empty;
  159. }
  160. if (arg1 == null)
  161. {
  162. arg1 = String.Empty;
  163. }
  164. if (arg2 == null)
  165. {
  166. arg2 = String.Empty;
  167. }
  168. return Concat(arg0.ToString(), arg1.ToString(), arg2.ToString());
  169. }
  170. public static String Concat(params Object[] args)
  171. {
  172. if (args == null)
  173. {
  174. throw new ArgumentNullException("args");
  175. }
  176. int length = args.Length;
  177. String[] sArgs = new String[length];
  178. int totalLength = 0;
  179. for (int i = 0; i < length; i++)
  180. {
  181. sArgs[i] = ((args[i] == null) ? (String.Empty) : (args[i].ToString()));
  182. totalLength += sArgs[i].Length;
  183. }
  184. return String.Concat(sArgs);
  185. }
  186. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  187. public extern static String Concat(String str0, String str1);
  188. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  189. public extern static String Concat(String str0, String str1, String str2);
  190. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  191. public extern static String Concat(String str0, String str1, String str2, String str3);
  192. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  193. public extern static String Concat(params String[] values);
  194. public static String Intern(String str)
  195. {
  196. // We don't support "interning" of strings. So simply return the string.
  197. return str;
  198. }
  199. public static String IsInterned(String str)
  200. {
  201. // We don't support "interning" of strings. So simply return the string.
  202. return str;
  203. }
  204. }
  205. }