Skip to content
This repository was archived by the owner on Nov 29, 2018. It is now read-only.

Commit 8f970d3

Browse files
committed
React to StringSegment header parsers
1 parent f061be8 commit 8f970d3

3 files changed

Lines changed: 47 additions & 13 deletions

File tree

src/Microsoft.AspNetCore.Localization/ProviderCultureResult.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Collections.Generic;
5+
using Microsoft.Extensions.Primitives;
56

67
namespace Microsoft.AspNetCore.Localization
78
{
@@ -15,8 +16,8 @@ public class ProviderCultureResult
1516
/// <see cref="UICultures"/> properties set to the same culture value.
1617
/// </summary>
1718
/// <param name="culture">The name of the culture to be used for formatting, text, i.e. language.</param>
18-
public ProviderCultureResult(string culture)
19-
: this(new List<string> { culture }, new List<string> { culture })
19+
public ProviderCultureResult(StringSegment culture)
20+
: this(new List<StringSegment> { culture }, new List<StringSegment> { culture })
2021
{
2122
}
2223

@@ -26,8 +27,8 @@ public ProviderCultureResult(string culture)
2627
/// </summary>
2728
/// <param name="culture">The name of the culture to be used for formatting.</param>
2829
/// <param name="uiCulture"> The name of the ui culture to be used for text, i.e. language.</param>
29-
public ProviderCultureResult(string culture, string uiCulture)
30-
: this(new List<string> { culture }, new List<string> { uiCulture })
30+
public ProviderCultureResult(StringSegment culture, StringSegment uiCulture)
31+
: this(new List<StringSegment> { culture }, new List<StringSegment> { uiCulture })
3132
{
3233
}
3334

@@ -36,7 +37,7 @@ public ProviderCultureResult(string culture, string uiCulture)
3637
/// <see cref="UICultures"/> properties set to the same culture value.
3738
/// </summary>
3839
/// <param name="cultures">The list of cultures to be used for formatting, text, i.e. language.</param>
39-
public ProviderCultureResult(IList<string> cultures)
40+
public ProviderCultureResult(IList<StringSegment> cultures)
4041
: this(cultures, cultures)
4142
{
4243
}
@@ -47,7 +48,7 @@ public ProviderCultureResult(IList<string> cultures)
4748
/// </summary>
4849
/// <param name="cultures">The list of cultures to be used for formatting.</param>
4950
/// <param name="uiCultures">The list of ui cultures to be used for text, i.e. language.</param>
50-
public ProviderCultureResult(IList<string> cultures, IList<string> uiCultures)
51+
public ProviderCultureResult(IList<StringSegment> cultures, IList<StringSegment> uiCultures)
5152
{
5253
Cultures = cultures;
5354
UICultures = uiCultures;
@@ -56,11 +57,11 @@ public ProviderCultureResult(IList<string> cultures, IList<string> uiCultures)
5657
/// <summary>
5758
/// Gets the list of cultures to be used for formatting.
5859
/// </summary>
59-
public IList<string> Cultures { get; }
60+
public IList<StringSegment> Cultures { get; }
6061

6162
/// <summary>
6263
/// Gets the list of ui cultures to be used for text, i.e. language;
6364
/// </summary>
64-
public IList<string> UICultures { get; }
65+
public IList<StringSegment> UICultures { get; }
6566
}
6667
}

src/Microsoft.AspNetCore.Localization/RequestLocalizationMiddleware.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Microsoft.AspNetCore.Builder;
1111
using Microsoft.AspNetCore.Http;
1212
using Microsoft.Extensions.Options;
13+
using Microsoft.Extensions.Primitives;
1314

1415
namespace Microsoft.AspNetCore.Localization
1516
{
@@ -131,7 +132,7 @@ private static void SetCurrentThreadCulture(RequestCulture requestCulture)
131132
}
132133

133134
private static CultureInfo GetCultureInfo(
134-
IList<string> cultureNames,
135+
IList<StringSegment> cultureNames,
135136
IList<CultureInfo> supportedCultures,
136137
bool fallbackToParentCultures)
137138
{
@@ -152,7 +153,7 @@ private static CultureInfo GetCultureInfo(
152153
return null;
153154
}
154155

155-
private static CultureInfo GetCultureInfo(string name, IList<CultureInfo> supportedCultures)
156+
private static CultureInfo GetCultureInfo(StringSegment name, IList<CultureInfo> supportedCultures)
156157
{
157158
// Allow only known culture names as this API is called with input from users (HTTP requests) and
158159
// creating CultureInfo objects is expensive and we don't want it to throw either.
@@ -161,7 +162,7 @@ private static CultureInfo GetCultureInfo(string name, IList<CultureInfo> suppor
161162
return null;
162163
}
163164
var culture = supportedCultures.FirstOrDefault(
164-
supportedCulture => string.Equals(supportedCulture.Name, name, StringComparison.OrdinalIgnoreCase));
165+
supportedCulture => StringSegment.Equals(supportedCulture.Name, name, StringComparison.OrdinalIgnoreCase));
165166

166167
if (culture == null)
167168
{
@@ -172,7 +173,7 @@ private static CultureInfo GetCultureInfo(string name, IList<CultureInfo> suppor
172173
}
173174

174175
private static CultureInfo GetCultureInfo(
175-
string cultureName,
176+
StringSegment cultureName,
176177
IList<CultureInfo> supportedCultures,
177178
bool fallbackToParentCultures,
178179
int currentDepth)
@@ -186,7 +187,7 @@ private static CultureInfo GetCultureInfo(
186187
if (lastIndexOfHyphen > 0)
187188
{
188189
// Trim the trailing section from the culture name, e.g. "fr-FR" becomes "fr"
189-
var parentCultureName = cultureName.Substring(0, lastIndexOfHyphen);
190+
var parentCultureName = cultureName.Subsegment(0, lastIndexOfHyphen);
190191

191192
culture = GetCultureInfo(parentCultureName, supportedCultures, fallbackToParentCultures, currentDepth + 1);
192193
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[
2+
{
3+
"TypeId": "public class Microsoft.AspNetCore.Localization.ProviderCultureResult",
4+
"MemberId": "public .ctor(System.Collections.Generic.IList<System.String> cultures)",
5+
"Kind": "Removal"
6+
},
7+
{
8+
"TypeId": "public class Microsoft.AspNetCore.Localization.ProviderCultureResult",
9+
"MemberId": "public .ctor(System.Collections.Generic.IList<System.String> cultures, System.Collections.Generic.IList<System.String> uiCultures)",
10+
"Kind": "Removal"
11+
},
12+
{
13+
"TypeId": "public class Microsoft.AspNetCore.Localization.ProviderCultureResult",
14+
"MemberId": "public .ctor(System.String culture)",
15+
"Kind": "Removal"
16+
},
17+
{
18+
"TypeId": "public class Microsoft.AspNetCore.Localization.ProviderCultureResult",
19+
"MemberId": "public .ctor(System.String culture, System.String uiCulture)",
20+
"Kind": "Removal"
21+
},
22+
{
23+
"TypeId": "public class Microsoft.AspNetCore.Localization.ProviderCultureResult",
24+
"MemberId": "public System.Collections.Generic.IList<System.String> get_Cultures()",
25+
"Kind": "Removal"
26+
},
27+
{
28+
"TypeId": "public class Microsoft.AspNetCore.Localization.ProviderCultureResult",
29+
"MemberId": "public System.Collections.Generic.IList<System.String> get_UICultures()",
30+
"Kind": "Removal"
31+
}
32+
]

0 commit comments

Comments
 (0)