You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduce new this[int,object] to allow to differentiate from this[int,int] to mean 'Until the last value of the string', which was previously overloaded on the value zero for 'end'
@@ -19,7 +19,7 @@ It starts with a new string type that is focused on Unicode code-points as oppos
19
19
<ReleaseVersion>0.3</ReleaseVersion>
20
20
<PackageReleaseNotes>* Renamed some methods to match the equivalent methods in Char.
21
21
* Introduced Substring (int start)
22
-
* Typo fix</PackageReleaseNotes>
22
+
* Introduced difference between this [int start, int end] and this [int start, object end] the latter used to mean "until the end", replacing '0' as the previous value for "until the end".</PackageReleaseNotes>
Copy file name to clipboardExpand all lines: NStack/strings/ustring.cs
+68-14Lines changed: 68 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -850,20 +850,21 @@ public static ustring Make (byte [] buffer, int start, int count)
850
850
/// Returns a slice of the ustring delimited by the [start, end) range. If the range is invalid, the return is the Empty string.
851
851
/// </summary>
852
852
/// <param name="start">Start index, this value is inclusive. If the value is negative, the value is added to the length, allowing this parameter to count to count from the end of the string.</param>
853
-
/// <param name="end">End index, this value is exclusive. If the value is negative, the value is added to the length, plus one, allowing this parameter to count from the end of the string. If the value is zero, the end is computed as the last index of the string.</param>
853
+
/// <param name="iend">End index, this value is exclusive. If the value is negative, the value is added to the length, plus one, allowing this parameter to count from the end of the string.</param>
854
854
/// <remarks>
855
855
/// <para>
856
856
/// Some examples given the string "1234567890":
857
857
/// </para>
858
858
/// <para>The range [0, 4] produces "1234"</para>
859
859
/// <para>The range [8, 10] produces "90"</para>
860
-
/// <para>The range [8, 0] produces "90"</para>
861
-
/// <para>The range [-2, 0] produces "90"</para>
860
+
/// <para>The range [8, null] produces "90"</para>
861
+
/// <para>The range [-2, null] produces "90"</para>
862
862
/// <para>The range [8, 9] produces "9"</para>
863
863
/// <para>The range [-4, -1] produces "789"</para>
864
-
/// <para>The range [-4, 0] produces "7890"</para>
865
-
/// <para>The range [-4, 0] produces "7890"</para>
864
+
/// <para>The range [-4, null] produces "7890"</para>
865
+
/// <para>The range [-4, null] produces "7890"</para>
866
866
/// <para>The range [-9, -3] produces "234567"</para>
867
+
/// <para>The range [0, 0] produces the empty string</para>
867
868
/// <para>
868
869
/// This indexer does not raise exceptions for invalid indexes, instead the value
869
870
/// returned is the ustring.Empty value:
@@ -874,16 +875,18 @@ public static ustring Make (byte [] buffer, int start, int count)
874
875
/// <para>
875
876
/// The range [-100, 0] produces ustring.Empty
876
877
/// </para>
878
+
/// <para>
879
+
/// To simulate the optional end boundary, use the indexer that takes the
880
+
/// object parameter and pass a null to it. For example, to fetch all
881
+
/// elements from the position five until the end, use [5, null]
882
+
/// </para>
877
883
/// </remarks>
878
884
public ustringthis[intstart,intend]{
879
885
get{
880
886
intsize= Length;
881
-
if(end<0){
882
-
if(end==0)
883
-
end=size;
884
-
else
885
-
end=size+end;
886
-
}
887
+
if(end<0)
888
+
end= size + end;
889
+
887
890
if(start <0)
888
891
start= size + start;
889
892
@@ -895,6 +898,57 @@ public static ustring Make (byte [] buffer, int start, int count)
895
898
}
896
899
}
897
900
901
+
/// <summary>
902
+
/// Returns a slice of the ustring delimited by the [start, last-element-of-the-string range. If the range is invalid, the return is the Empty string.
903
+
/// </summary>
904
+
/// <param name="start">Start index, this value is inclusive. If the value is negative, the value is added to the length, allowing this parameter to count to count from the end of the string.</param>
905
+
/// <param name="end">This value is expected to be null to indicate that it should be the last element of the string.</param>
906
+
/// <remarks>
907
+
/// <para>
908
+
/// This is a companion indexer to the indexer that takes two integers, it only exists
909
+
/// to provide the optional end argument to mean "until the end", and to make the code
910
+
/// that uses indexer look familiar, without having to resort to another API.
911
+
///
912
+
/// Some examples given the string "1234567890":
913
+
/// </para>
914
+
/// <para>The range [8, null] produces "90"</para>
915
+
/// <para>The range [-2, null] produces "90"</para>
916
+
/// <para>The range [8, 9] produces "9"</para>
917
+
/// <para>The range [-4, -1] produces "789"</para>
918
+
/// <para>The range [-4, null] produces "7890"</para>
919
+
/// <para>The range [-4, null] produces "7890"</para>
920
+
/// <para>The range [-9, -3] produces "234567"</para>
921
+
/// <para>
922
+
/// This indexer does not raise exceptions for invalid indexes, instead the value
923
+
/// returned is the ustring.Empty value:
924
+
/// </para>
925
+
/// <para>
926
+
/// The range [100, 200] produces the ustring.Empty
927
+
/// </para>
928
+
/// <para>
929
+
/// The range [-100, 0] produces ustring.Empty
930
+
/// </para>
931
+
/// <para>
932
+
/// To simulate the optional end boundary, use the indexer that takes the
933
+
/// object parameter and pass a null to it. For example, to fetch all
934
+
/// elements from the position five until the end, use [5, null]
935
+
/// </para>
936
+
/// </remarks>
937
+
public ustringthis[int start,object end]{
938
+
get{
939
+
intsize= Length;
940
+
int iend = size;
941
+
if(start<0)
942
+
start= size + start;
943
+
944
+
if(start <0||start>=size||start>=iend)
945
+
return Empty;
946
+
if(iend<0||iend>size)
947
+
return Empty;
948
+
returnGetRange(start,iend);
949
+
}
950
+
}
951
+
898
952
/// <summary>
899
953
/// Returns the substring starting at the given position.
900
954
/// </summary>
@@ -1476,7 +1530,7 @@ ustring [] GenSplit (ustring sep, int sepSave, int n = -1)
1476
1530
offset= m + sepLen;
1477
1531
i++;
1478
1532
}
1479
-
result [i]=this[offset,0];
1533
+
result [i]=this[offset,null];
1480
1534
returnresult;
1481
1535
}
1482
1536
@@ -1857,7 +1911,7 @@ public ustring TrimStart (RunePredicate predicate)
1857
1911
var i = FlexIndexOf (predicate,false);
1858
1912
if(i==-1)
1859
1913
return this;
1860
-
returnthis[i,0];
1914
+
returnthis[i,null];
1861
1915
}
1862
1916
1863
1917
RunePredicate MakeCutSet (ustringcutset)
@@ -1913,7 +1967,7 @@ public ustring TrimEnd (RunePredicate predicate)
0 commit comments