1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 namespace System.Globalization
6 {
7     public partial class TextInfo
8     {
FinishInitialization()9         private unsafe void FinishInitialization()
10         {
11         }
12 
ChangeCase(string s, bool toUpper)13         private unsafe string ChangeCase(string s, bool toUpper)
14         {
15             if (s.Length == 0)
16             {
17                 return s;
18             }
19 
20             char[] buffer = new char[s.Length];
21 
22             if (toUpper)
23             {
24                 for (int i = 0; i < s.Length; i++)
25                 {
26                     buffer[i] = ('a' <= s[i] && s[i] <= 'z') ? (char)(s[i] - 0x20) : s[i];
27                 }
28             }
29             else
30             {
31                 for (int i = 0; i < s.Length; i++)
32                 {
33                     buffer[i] = ('A' <= s[i] && s[i] <= 'Z') ? (char)(s[i] | 0x20) : s[i];
34                 }
35             }
36 
37             return new string(buffer, 0, buffer.Length);
38         }
39 
ChangeCase(char c, bool toUpper)40         private unsafe char ChangeCase(char c, bool toUpper)
41         {
42             if (toUpper)
43             {
44                 return ('a' <= c && c <= 'z') ? (char)(c - 0x20) : c;
45             }
46 
47             return ('A' <= c && c <= 'Z') ? (char)(c | 0x20) : c;
48         }
49     }
50 }
51