|
20 | 20 | using System.Text; |
21 | 21 | using System.Runtime.InteropServices; |
22 | 22 | using System.Collections; |
| 23 | +using System.Linq; |
23 | 24 |
|
24 | 25 | namespace NStack { |
25 | 26 |
|
@@ -470,6 +471,16 @@ public static ustring Make (IList<Rune> runes) |
470 | 471 | return Make (encoded); |
471 | 472 | } |
472 | 473 |
|
| 474 | + /// <summary> |
| 475 | + /// Initializes a new instance of the <see cref="T:NStack.ustring"/> class from an IEnumerable of runes |
| 476 | + /// </summary> |
| 477 | + /// <returns>The make.</returns> |
| 478 | + /// <param name="runes">Runes.</param> |
| 479 | + public static ustring Make (IEnumerable<Rune> runes) |
| 480 | + { |
| 481 | + return Make (runes.ToList ()); |
| 482 | + } |
| 483 | + |
473 | 484 | /// <summary> |
474 | 485 | /// Initializes a new instance of the <see cref="T:NStack.ustring"/> class from a block of memory and a size. |
475 | 486 | /// </summary> |
@@ -1110,6 +1121,21 @@ public uint [] ToRunes (int limit = -1) |
1110 | 1121 | return result; |
1111 | 1122 | } |
1112 | 1123 |
|
| 1124 | + /// <summary> |
| 1125 | + /// Converts a ustring into a List of runes. |
| 1126 | + /// </summary> |
| 1127 | + /// <returns>A list containing the runes for the string, it is not bound by any limits.</returns> |
| 1128 | + public List<Rune> ToRuneList () |
| 1129 | + { |
| 1130 | + var result = new List<Rune> (); |
| 1131 | + for (int offset = 0; offset < Length; ) { |
| 1132 | + (var rune, var size) = Utf8.DecodeRune (this, offset); |
| 1133 | + result.Add (rune); |
| 1134 | + offset += size; |
| 1135 | + } |
| 1136 | + return result; |
| 1137 | + } |
| 1138 | + |
1113 | 1139 | // primeRK is the prime base used in Rabin-Karp algorithm. |
1114 | 1140 | const uint primeRK = 16777619; |
1115 | 1141 |
|
@@ -1763,6 +1789,16 @@ public static bool Contains (ref AsciiSet aset, byte b) |
1763 | 1789 | yield break; |
1764 | 1790 | } |
1765 | 1791 |
|
| 1792 | + /// <summary> |
| 1793 | + /// Returns the Rune encoded at the specified byte <paramref name="index"/>. |
| 1794 | + /// </summary> |
| 1795 | + /// <returns>The <see cref="T:System.Rune"/> which might be Rune.Error if the value at the specified index is not UTF8 compliant, for example because it is not a valid UTF8 encoding, or the buffer is too short.</returns> |
| 1796 | + /// <param name="index">Index.</param> |
| 1797 | + public Rune RuneAt (int index) |
| 1798 | + { |
| 1799 | + return Utf8.DecodeRune (this, index).Rune; |
| 1800 | + } |
| 1801 | + |
1766 | 1802 | // Map returns a copy of the string s with all its characters modified |
1767 | 1803 | // according to the mapping function. If mapping returns a negative value, the character is |
1768 | 1804 | // dropped from the string with no replacement. |
|
0 commit comments