React to StringSegment header parsers

This commit is contained in:
Chris R 2017-05-19 12:55:55 -07:00
Родитель f061be8209
Коммит 8f970d3d48
3 изменённых файлов: 47 добавлений и 13 удалений

Просмотреть файл

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Extensions.Primitives;
namespace Microsoft.AspNetCore.Localization namespace Microsoft.AspNetCore.Localization
{ {
@ -15,8 +16,8 @@ namespace Microsoft.AspNetCore.Localization
/// <see cref="UICultures"/> properties set to the same culture value. /// <see cref="UICultures"/> properties set to the same culture value.
/// </summary> /// </summary>
/// <param name="culture">The name of the culture to be used for formatting, text, i.e. language.</param> /// <param name="culture">The name of the culture to be used for formatting, text, i.e. language.</param>
public ProviderCultureResult(string culture) public ProviderCultureResult(StringSegment culture)
: this(new List<string> { culture }, new List<string> { culture }) : this(new List<StringSegment> { culture }, new List<StringSegment> { culture })
{ {
} }
@ -26,8 +27,8 @@ namespace Microsoft.AspNetCore.Localization
/// </summary> /// </summary>
/// <param name="culture">The name of the culture to be used for formatting.</param> /// <param name="culture">The name of the culture to be used for formatting.</param>
/// <param name="uiCulture"> The name of the ui culture to be used for text, i.e. language.</param> /// <param name="uiCulture"> The name of the ui culture to be used for text, i.e. language.</param>
public ProviderCultureResult(string culture, string uiCulture) public ProviderCultureResult(StringSegment culture, StringSegment uiCulture)
: this(new List<string> { culture }, new List<string> { uiCulture }) : this(new List<StringSegment> { culture }, new List<StringSegment> { uiCulture })
{ {
} }
@ -36,7 +37,7 @@ namespace Microsoft.AspNetCore.Localization
/// <see cref="UICultures"/> properties set to the same culture value. /// <see cref="UICultures"/> properties set to the same culture value.
/// </summary> /// </summary>
/// <param name="cultures">The list of cultures to be used for formatting, text, i.e. language.</param> /// <param name="cultures">The list of cultures to be used for formatting, text, i.e. language.</param>
public ProviderCultureResult(IList<string> cultures) public ProviderCultureResult(IList<StringSegment> cultures)
: this(cultures, cultures) : this(cultures, cultures)
{ {
} }
@ -47,7 +48,7 @@ namespace Microsoft.AspNetCore.Localization
/// </summary> /// </summary>
/// <param name="cultures">The list of cultures to be used for formatting.</param> /// <param name="cultures">The list of cultures to be used for formatting.</param>
/// <param name="uiCultures">The list of ui cultures to be used for text, i.e. language.</param> /// <param name="uiCultures">The list of ui cultures to be used for text, i.e. language.</param>
public ProviderCultureResult(IList<string> cultures, IList<string> uiCultures) public ProviderCultureResult(IList<StringSegment> cultures, IList<StringSegment> uiCultures)
{ {
Cultures = cultures; Cultures = cultures;
UICultures = uiCultures; UICultures = uiCultures;
@ -56,11 +57,11 @@ namespace Microsoft.AspNetCore.Localization
/// <summary> /// <summary>
/// Gets the list of cultures to be used for formatting. /// Gets the list of cultures to be used for formatting.
/// </summary> /// </summary>
public IList<string> Cultures { get; } public IList<StringSegment> Cultures { get; }
/// <summary> /// <summary>
/// Gets the list of ui cultures to be used for text, i.e. language; /// Gets the list of ui cultures to be used for text, i.e. language;
/// </summary> /// </summary>
public IList<string> UICultures { get; } public IList<StringSegment> UICultures { get; }
} }
} }

Просмотреть файл

@ -10,6 +10,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;
namespace Microsoft.AspNetCore.Localization namespace Microsoft.AspNetCore.Localization
{ {
@ -131,7 +132,7 @@ namespace Microsoft.AspNetCore.Localization
} }
private static CultureInfo GetCultureInfo( private static CultureInfo GetCultureInfo(
IList<string> cultureNames, IList<StringSegment> cultureNames,
IList<CultureInfo> supportedCultures, IList<CultureInfo> supportedCultures,
bool fallbackToParentCultures) bool fallbackToParentCultures)
{ {
@ -152,7 +153,7 @@ namespace Microsoft.AspNetCore.Localization
return null; return null;
} }
private static CultureInfo GetCultureInfo(string name, IList<CultureInfo> supportedCultures) private static CultureInfo GetCultureInfo(StringSegment name, IList<CultureInfo> supportedCultures)
{ {
// Allow only known culture names as this API is called with input from users (HTTP requests) and // Allow only known culture names as this API is called with input from users (HTTP requests) and
// creating CultureInfo objects is expensive and we don't want it to throw either. // creating CultureInfo objects is expensive and we don't want it to throw either.
@ -161,7 +162,7 @@ namespace Microsoft.AspNetCore.Localization
return null; return null;
} }
var culture = supportedCultures.FirstOrDefault( var culture = supportedCultures.FirstOrDefault(
supportedCulture => string.Equals(supportedCulture.Name, name, StringComparison.OrdinalIgnoreCase)); supportedCulture => StringSegment.Equals(supportedCulture.Name, name, StringComparison.OrdinalIgnoreCase));
if (culture == null) if (culture == null)
{ {
@ -172,7 +173,7 @@ namespace Microsoft.AspNetCore.Localization
} }
private static CultureInfo GetCultureInfo( private static CultureInfo GetCultureInfo(
string cultureName, StringSegment cultureName,
IList<CultureInfo> supportedCultures, IList<CultureInfo> supportedCultures,
bool fallbackToParentCultures, bool fallbackToParentCultures,
int currentDepth) int currentDepth)
@ -186,7 +187,7 @@ namespace Microsoft.AspNetCore.Localization
if (lastIndexOfHyphen > 0) if (lastIndexOfHyphen > 0)
{ {
// Trim the trailing section from the culture name, e.g. "fr-FR" becomes "fr" // Trim the trailing section from the culture name, e.g. "fr-FR" becomes "fr"
var parentCultureName = cultureName.Substring(0, lastIndexOfHyphen); var parentCultureName = cultureName.Subsegment(0, lastIndexOfHyphen);
culture = GetCultureInfo(parentCultureName, supportedCultures, fallbackToParentCultures, currentDepth + 1); culture = GetCultureInfo(parentCultureName, supportedCultures, fallbackToParentCultures, currentDepth + 1);
} }

Просмотреть файл

@ -0,0 +1,32 @@
[
{
"TypeId": "public class Microsoft.AspNetCore.Localization.ProviderCultureResult",
"MemberId": "public .ctor(System.Collections.Generic.IList<System.String> cultures)",
"Kind": "Removal"
},
{
"TypeId": "public class Microsoft.AspNetCore.Localization.ProviderCultureResult",
"MemberId": "public .ctor(System.Collections.Generic.IList<System.String> cultures, System.Collections.Generic.IList<System.String> uiCultures)",
"Kind": "Removal"
},
{
"TypeId": "public class Microsoft.AspNetCore.Localization.ProviderCultureResult",
"MemberId": "public .ctor(System.String culture)",
"Kind": "Removal"
},
{
"TypeId": "public class Microsoft.AspNetCore.Localization.ProviderCultureResult",
"MemberId": "public .ctor(System.String culture, System.String uiCulture)",
"Kind": "Removal"
},
{
"TypeId": "public class Microsoft.AspNetCore.Localization.ProviderCultureResult",
"MemberId": "public System.Collections.Generic.IList<System.String> get_Cultures()",
"Kind": "Removal"
},
{
"TypeId": "public class Microsoft.AspNetCore.Localization.ProviderCultureResult",
"MemberId": "public System.Collections.Generic.IList<System.String> get_UICultures()",
"Kind": "Removal"
}
]