return SplitInternal(pSeparators, /*separatorsLength*/ 1, count, options);
}
- [ComVisible(false)]
[System.Security.SecuritySafeCritical]
- internal String[] SplitInternal(char[] separator, int count, StringSplitOptions options)
+ private unsafe String[] SplitInternal(char[] separator, int count, StringSplitOptions options)
{
- unsafe
+ fixed (char* pSeparators = separator)
{
- fixed (char* pSeparators = separator)
- {
- int separatorsLength = separator == null ? 0 : separator.Length;
- return SplitInternal(pSeparators, separatorsLength, count, options);
- }
+ int separatorsLength = separator == null ? 0 : separator.Length;
+ return SplitInternal(pSeparators, separatorsLength, count, options);
}
}
if(omitEmptyEntries)
{
- return InternalSplitOmitEmptyEntries(sepList, null, 1, numReplaces, count);
+ return SplitOmitEmptyEntries(sepList, null, 1, numReplaces, count);
}
else
{
- return InternalSplitKeepEmptyEntries(sepList, null, 1, numReplaces, count);
+ return SplitKeepEmptyEntries(sepList, null, 1, numReplaces, count);
}
}
#endif
}
- if (count == 1) {
+ if (count == 1 || (singleSeparator && separator.Length == 0)) {
return new String[] { this };
}
- if (singleSeparator && separator.Length == 0) {
- return new[] { this };
- }
-
int[] sepList = new int[Length];
int[] lengthList;
int defaultLength;
}
if (omitEmptyEntries) {
- return InternalSplitOmitEmptyEntries(sepList, lengthList, defaultLength, numReplaces, count);
+ return SplitOmitEmptyEntries(sepList, lengthList, defaultLength, numReplaces, count);
}
else {
- return InternalSplitKeepEmptyEntries(sepList, lengthList, defaultLength, numReplaces, count);
+ return SplitKeepEmptyEntries(sepList, lengthList, defaultLength, numReplaces, count);
}
}
// the original string will be returned regardless of the count.
//
- private String[] InternalSplitKeepEmptyEntries(Int32[] sepList, Int32[] lengthList, Int32 defaultLength, Int32 numReplaces, int count) {
+ private String[] SplitKeepEmptyEntries(Int32[] sepList, Int32[] lengthList, Int32 defaultLength, Int32 numReplaces, int count) {
Contract.Requires(numReplaces >= 0);
Contract.Requires(count >= 2);
Contract.Ensures(Contract.Result<String[]>() != null);
// This function will not keep the Empty String
- private String[] InternalSplitOmitEmptyEntries(Int32[] sepList, Int32[] lengthList, Int32 defaultLength, Int32 numReplaces, int count) {
+ private String[] SplitOmitEmptyEntries(Int32[] sepList, Int32[] lengthList, Int32 defaultLength, Int32 numReplaces, int count) {
Contract.Requires(numReplaces >= 0);
Contract.Requires(count >= 2);
Contract.Ensures(Contract.Result<String[]>() != null);