Exemplo n.º 1
0
 /// <summary>
 /// Returns the number of Unicode code points in the specified text
 /// range of this <see cref="StringBuilder"/>. The text range begins at the specified
 /// <paramref name="beginIndex"/> and extends to the <see cref="char"/> at
 /// index <c>endIndex - 1</c>. Thus the length (in
 /// <see cref="char"/>s) of the text range is
 /// <c>endIndex-beginIndex</c>. Unpaired surrogates within
 /// this sequence count as one code point each.
 /// </summary>
 /// <param name="text">this <see cref="StringBuilder"/></param>
 /// <param name="beginIndex">the index to the first <see cref="char"/> of the text range.</param>
 /// <param name="endIndex">the index after the last <see cref="char"/> of the text range.</param>
 /// <returns>the number of Unicode code points in the specified text range.</returns>
 /// <exception cref="IndexOutOfRangeException">
 /// if the <paramref name="beginIndex"/> is negative, or <paramref name="endIndex"/>
 /// is larger than the length of this sequence, or
 /// <paramref name="beginIndex"/> is larger than <paramref name="endIndex"/>.
 /// </exception>
 public static int CodePointCount(this StringBuilder text, int beginIndex, int endIndex)
 {
     if (beginIndex < 0 || endIndex > text.Length || beginIndex > endIndex)
     {
         throw new IndexOutOfRangeException();
     }
     return(Character.CodePointCountImpl(text.GetChars(), beginIndex, endIndex - beginIndex));
 }
Exemplo n.º 2
0
 /// <summary>
 /// Returns the number of Unicode code points in the specified text
 /// range of this <see cref="string"/>. The text range begins at the
 /// specified <paramref name="beginIndex"/> and extends to the
 /// <see cref="char"/> at index <c>endIndex - 1</c>. Thus the
 /// length (in <see cref="char"/>s) of the text range is
 /// <c>endIndex-beginIndex</c>. Unpaired surrogates within
 /// the text range count as one code point each.
 /// </summary>
 /// <param name="str"></param>
 /// <param name="beginIndex">the index to the first <see cref="char"/> of the text range.</param>
 /// <param name="endIndex">the index after the last <see cref="char"/> of the text range.</param>
 /// <returns>the number of Unicode code points in the specified text range</returns>
 /// <exception cref="IndexOutOfRangeException">if the <paramref name="beginIndex"/> is negative, or
 /// <paramref name="endIndex"/> is larger than the length of this <see cref="string"/>, or
 /// <paramref name="beginIndex"/> is larger than <paramref name="endIndex"/>.</exception>
 public static int CodePointCount(this string str, int beginIndex, int endIndex)
 {
     if (beginIndex < 0 || endIndex > str.Length || beginIndex > endIndex)
     {
         throw new IndexOutOfRangeException();
     }
     return(Character.CodePointCountImpl(str.ToCharArray(), beginIndex, endIndex - beginIndex));
 }