Skip to content

Commit d14222d

Browse files
Joy-lesstarekgh
andauthored
Fix test containing reflection erroring from dotnet#117168 (Add methods from dotnet#27912 (Flow System.Text.Rune through more APIs)) (dotnet#120145)
* Fix tests from dotnet#117168 * Add `SyncTextWriter` overloads as well * Add missing overloads to BroadcastingTextWriter * Reapply "Add methods from dotnet#27912 (Flow System.Text.Rune through more APIs) (#1…" (dotnet#120138) This reverts commit be80737. * Override the TextWrite Rune overloads in IndentedTextWriter --------- Co-authored-by: Tarek Mahmoud Sayed <tarekms@microsoft.com>
1 parent 1959692 commit d14222d

20 files changed

Lines changed: 1704 additions & 6 deletions

File tree

src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,7 @@
12171217
<Compile Include="$(MSBuildThisFileDirectory)System\Text\SpanRuneEnumerator.cs" />
12181218
<Compile Include="$(MSBuildThisFileDirectory)System\Text\StringBuilder.cs" />
12191219
<Compile Include="$(MSBuildThisFileDirectory)System\Text\StringBuilder.Debug.cs" Condition="'$(Configuration)' == 'Debug'" />
1220+
<Compile Include="$(MSBuildThisFileDirectory)System\Text\StringBuilderRuneEnumerator.cs" />
12201221
<Compile Include="$(MSBuildThisFileDirectory)System\Text\StringRuneEnumerator.cs" />
12211222
<Compile Include="$(MSBuildThisFileDirectory)System\Text\TranscodingStream.cs" />
12221223
<Compile Include="$(MSBuildThisFileDirectory)System\Text\TrimType.cs" />

src/libraries/System.Private.CoreLib/src/System/Char.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ public bool Equals(char obj)
129129
return m_value == obj;
130130
}
131131

132+
internal bool Equals(char right, StringComparison comparisonType)
133+
{
134+
switch (comparisonType)
135+
{
136+
case StringComparison.Ordinal:
137+
return Equals(right);
138+
default:
139+
ReadOnlySpan<char> leftCharsSlice = [this];
140+
ReadOnlySpan<char> rightCharsSlice = [right];
141+
return leftCharsSlice.Equals(rightCharsSlice, comparisonType);
142+
}
143+
}
144+
132145
// Compares this object to another object, returning an integer that
133146
// indicates the relationship.
134147
// Returns a value less than zero if this object

src/libraries/System.Private.CoreLib/src/System/CodeDom/Compiler/IndentedTextWriter.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ public override void Write(char value)
114114
_writer.Write(value);
115115
}
116116

117+
/// <summary>
118+
/// Writes out the specified <see cref="Rune"/>, inserting tabs at the start of every line.
119+
/// </summary>
120+
/// <param name="value">The <see cref="Rune"/> to write.</param>
121+
public override void Write(Rune value)
122+
{
123+
OutputTabs();
124+
_writer.Write(value);
125+
}
126+
117127
public override void Write(char[]? buffer)
118128
{
119129
OutputTabs();
@@ -197,6 +207,18 @@ public override async Task WriteAsync(char value)
197207
await _writer.WriteAsync(value).ConfigureAwait(false);
198208
}
199209

210+
/// <summary>
211+
/// Asynchronously writes the specified <see cref="Rune"/> to the underlying <see cref="TextWriter"/>, inserting
212+
/// tabs at the start of every line.
213+
/// </summary>
214+
/// <param name="value">The <see cref="Rune"/> to write.</param>
215+
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
216+
public override async Task WriteAsync(Rune value)
217+
{
218+
await OutputTabsAsync().ConfigureAwait(false);
219+
await _writer.WriteAsync(value).ConfigureAwait(false);
220+
}
221+
200222
/// <summary>
201223
/// Asynchronously writes the specified number of <see cref="char"/>s from the specified buffer
202224
/// to the underlying <see cref="TextWriter"/>, starting at the specified index, and outputting tabs at the
@@ -293,6 +315,17 @@ public override void WriteLine(char value)
293315
_tabsPending = true;
294316
}
295317

318+
/// <summary>
319+
/// Writes out the specified <see cref="Rune"/>, followed by a line terminator, inserting tabs at the start of every line.
320+
/// </summary>
321+
/// <param name="value">The <see cref="Rune"/> to write.</param>
322+
public override void WriteLine(Rune value)
323+
{
324+
OutputTabs();
325+
_writer.WriteLine(value);
326+
_tabsPending = true;
327+
}
328+
296329
public override void WriteLine(char[]? buffer)
297330
{
298331
OutputTabs();
@@ -404,6 +437,19 @@ public override async Task WriteLineAsync(char value)
404437
_tabsPending = true;
405438
}
406439

440+
/// <summary>
441+
/// Asynchronously writes the specified <see cref="Rune"/> to the underlying <see cref="TextWriter"/> followed by a line terminator, inserting tabs
442+
/// at the start of every line.
443+
/// </summary>
444+
/// <param name="value">The character to write.</param>
445+
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
446+
public override async Task WriteLineAsync(Rune value)
447+
{
448+
await OutputTabsAsync().ConfigureAwait(false);
449+
await _writer.WriteLineAsync(value).ConfigureAwait(false);
450+
_tabsPending = true;
451+
}
452+
407453
/// <summary>
408454
/// Asynchronously writes the specified number of characters from the specified buffer followed by a line terminator,
409455
/// to the underlying <see cref="TextWriter"/>, starting at the specified index within the buffer, inserting tabs at the start of every line.

src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,17 @@ public string ToLower(string str)
180180
return ChangeCaseCommon<ToLowerConversion>(str);
181181
}
182182

183+
internal void ToLower(ReadOnlySpan<char> source, Span<char> destination)
184+
{
185+
if (GlobalizationMode.Invariant)
186+
{
187+
InvariantModeCasing.ToLower(source, destination);
188+
return;
189+
}
190+
191+
ChangeCaseCommon<ToLowerConversion>(source, destination);
192+
}
193+
183194
private unsafe char ChangeCase(char c, bool toUpper)
184195
{
185196
Debug.Assert(!GlobalizationMode.Invariant);
@@ -451,6 +462,17 @@ public string ToUpper(string str)
451462
return ChangeCaseCommon<ToUpperConversion>(str);
452463
}
453464

465+
internal void ToUpper(ReadOnlySpan<char> source, Span<char> destination)
466+
{
467+
if (GlobalizationMode.Invariant)
468+
{
469+
InvariantModeCasing.ToUpper(source, destination);
470+
return;
471+
}
472+
473+
ChangeCaseCommon<ToUpperConversion>(source, destination);
474+
}
475+
454476
[MethodImpl(MethodImplOptions.AggressiveInlining)]
455477
internal static char ToUpperAsciiInvariant(char c)
456478
{
@@ -461,6 +483,50 @@ internal static char ToUpperAsciiInvariant(char c)
461483
return c;
462484
}
463485

486+
/// <summary>
487+
/// Converts the specified rune to lowercase.
488+
/// </summary>
489+
/// <param name="value">The rune to convert to lowercase.</param>
490+
/// <returns>The specified rune converted to lowercase.</returns>
491+
public Rune ToLower(Rune value)
492+
{
493+
// Convert rune to span
494+
ReadOnlySpan<char> valueChars = value.AsSpan(stackalloc char[Rune.MaxUtf16CharsPerRune]);
495+
496+
// Change span to lower and convert to rune
497+
if (valueChars.Length == 2)
498+
{
499+
Span<char> lowerChars = stackalloc char[2];
500+
ToLower(valueChars, lowerChars);
501+
return new Rune(lowerChars[0], lowerChars[1]);
502+
}
503+
504+
char lowerChar = ToLower(valueChars[0]);
505+
return new Rune(lowerChar);
506+
}
507+
508+
/// <summary>
509+
/// Converts the specified rune to uppercase.
510+
/// </summary>
511+
/// <param name="value">The rune to convert to uppercase.</param>
512+
/// <returns>The specified rune converted to uppercase.</returns>
513+
public Rune ToUpper(Rune value)
514+
{
515+
// Convert rune to span
516+
ReadOnlySpan<char> valueChars = value.AsSpan(stackalloc char[Rune.MaxUtf16CharsPerRune]);
517+
518+
// Change span to upper and convert to rune
519+
if (valueChars.Length == 2)
520+
{
521+
Span<char> upperChars = stackalloc char[2];
522+
ToUpper(valueChars, upperChars);
523+
return new Rune(upperChars[0], upperChars[1]);
524+
}
525+
526+
char upperChar = ToUpper(valueChars[0]);
527+
return new Rune(upperChar);
528+
}
529+
464530
private bool IsAsciiCasingSameAsInvariant
465531
{
466532
[MethodImpl(MethodImplOptions.AggressiveInlining)]

src/libraries/System.Private.CoreLib/src/System/IO/TextWriter.CreateBroadcasting.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ public override void Write(char value)
132132
}
133133
}
134134

135+
public override void Write(Rune value)
136+
{
137+
foreach (TextWriter writer in _writers)
138+
{
139+
writer.Write(value);
140+
}
141+
}
142+
135143
public override void Write(char[] buffer, int index, int count)
136144
{
137145
foreach (TextWriter writer in _writers)
@@ -292,6 +300,14 @@ public override void WriteLine(char value)
292300
}
293301
}
294302

303+
public override void WriteLine(Rune value)
304+
{
305+
foreach (TextWriter writer in _writers)
306+
{
307+
writer.WriteLine(value);
308+
}
309+
}
310+
295311
public override void WriteLine(char[]? buffer)
296312
{
297313
foreach (TextWriter writer in _writers)
@@ -452,6 +468,14 @@ public override async Task WriteAsync(char value)
452468
}
453469
}
454470

471+
public override async Task WriteAsync(Rune value)
472+
{
473+
foreach (TextWriter writer in _writers)
474+
{
475+
await writer.WriteAsync(value).ConfigureAwait(false);
476+
}
477+
}
478+
455479
public override async Task WriteAsync(string? value)
456480
{
457481
foreach (TextWriter writer in _writers)
@@ -492,6 +516,14 @@ public override async Task WriteLineAsync(char value)
492516
}
493517
}
494518

519+
public override async Task WriteLineAsync(Rune value)
520+
{
521+
foreach (TextWriter writer in _writers)
522+
{
523+
await writer.WriteLineAsync(value).ConfigureAwait(false);
524+
}
525+
}
526+
495527
public override async Task WriteLineAsync(string? value)
496528
{
497529
foreach (TextWriter writer in _writers)

0 commit comments

Comments
 (0)