Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
runtime
提交
b54d6ef1
R
runtime
项目概览
dotNET Platform
/
runtime
11 个月 前同步成功
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
runtime
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
b54d6ef1
编写于
4月 04, 2023
作者:
T
Tom Deseyn
提交者:
GitHub
4月 04, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ConvertIcuTimeFormatString: convert narrow no-break spaces to spaces too. (#83589)
上级
e9357808
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
63 addition
and
11 deletion
+63
-11
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs
...ivate.CoreLib/src/System/Globalization/CultureData.Icu.cs
+6
-8
src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs
...Private.CoreLib/src/System/Globalization/DateTimeParse.cs
+6
-3
src/libraries/System.Runtime/tests/System/DateTimeTests.cs
src/libraries/System.Runtime/tests/System/DateTimeTests.cs
+51
-0
未找到文件。
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs
浏览文件 @
b54d6ef1
...
...
@@ -232,13 +232,14 @@ private static string ConvertIcuTimeFormatString(ReadOnlySpan<char> icuFormatStr
for
(
int
i
=
0
;
i
<
icuFormatString
.
Length
;
i
++)
{
switch
(
icuFormatString
[
i
])
char
current
=
icuFormatString
[
i
];
switch
(
current
)
{
case
'\''
:
result
[
resultPos
++]
=
icuFormatString
[
i
++];
while
(
i
<
icuFormatString
.
Length
)
{
c
har
c
urrent
=
icuFormatString
[
i
];
current
=
icuFormatString
[
i
];
result
[
resultPos
++]
=
current
;
if
(
current
==
'\''
)
{
...
...
@@ -254,13 +255,10 @@ private static string ConvertIcuTimeFormatString(ReadOnlySpan<char> icuFormatStr
case
'h'
:
case
'm'
:
case
's'
:
result
[
resultPos
++]
=
icuFormatString
[
i
];
break
;
case
' '
:
case
'\
u00A0
'
:
// Convert nonbreaking spaces into regular spaces
result
[
resultPos
++]
=
' '
;
case
'\
u00A0
'
:
// no-break space
case
'\
u202F
'
:
// narrow no-break space
result
[
resultPos
++]
=
current
;
break
;
case
'a'
:
// AM/PM
...
...
src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs
浏览文件 @
b54d6ef1
...
...
@@ -5571,7 +5571,7 @@ internal bool MatchSpecifiedWords(string target, bool checkWordBoundary, scoped
// Check word by word
int
targetPosition
=
0
;
// Where we are in the target string
int
thisPosition
=
Index
;
// Where we are in this string
int
wsIndex
=
target
.
AsSpan
(
targetPosition
).
IndexOfAny
(
' '
,
'\
u00A0
'
);
int
wsIndex
=
target
.
AsSpan
(
targetPosition
).
IndexOfAny
(
"\u0020\u00A0\u202F"
);
if
(
wsIndex
<
0
)
{
return
false
;
...
...
@@ -5615,7 +5615,7 @@ internal bool MatchSpecifiedWords(string target, bool checkWordBoundary, scoped
matchLength
++;
}
wsIndex
=
target
.
AsSpan
(
targetPosition
).
IndexOfAny
(
' '
,
'\
u00A0
'
);
wsIndex
=
target
.
AsSpan
(
targetPosition
).
IndexOfAny
(
"\u0020\u00A0\u202F"
);
if
(
wsIndex
<
0
)
{
break
;
...
...
@@ -5678,7 +5678,8 @@ internal bool Match(char ch)
{
return
false
;
}
if
(
Value
[
Index
]
==
ch
)
if
((
Value
[
Index
]
==
ch
)
||
(
ch
==
' '
&&
IsSpaceReplacingChar
(
Value
[
Index
])))
{
m_current
=
ch
;
return
true
;
...
...
@@ -5687,6 +5688,8 @@ internal bool Match(char ch)
return
false
;
}
private
static
bool
IsSpaceReplacingChar
(
char
c
)
=>
c
==
'\
u00a0
'
||
c
==
'\
u202f
'
;
//
// Actions: From the current position, try matching the longest word in the specified string array.
// E.g. words[] = {"AB", "ABC", "ABCD"}, if the current position points to a substring like "ABC DEF",
...
...
src/libraries/System.Runtime/tests/System/DateTimeTests.cs
浏览文件 @
b54d6ef1
...
...
@@ -2008,6 +2008,57 @@ public static void Parse_ValidInput_Succeeds(string input, CultureInfo culture,
Assert
.
Equal
(
expected
,
DateTime
.
Parse
(
input
,
culture
));
}
public
static
IEnumerable
<
object
[
]>
FormatAndParse_DifferentUnicodeSpaces_Succeeds_MemberData
()
{
char
[]
spaceTypes
=
new
[]
{
' '
,
// space
'\
u00A0
'
,
// no-break space
'\
u202F
'
,
// narrow no-break space
};
return
spaceTypes
.
SelectMany
(
formatSpaceChar
=>
spaceTypes
.
Select
(
parseSpaceChar
=>
new
object
[]
{
formatSpaceChar
,
parseSpaceChar
}));
}
[
Theory
]
[
MemberData
(
nameof
(
FormatAndParse_DifferentUnicodeSpaces_Succeeds_MemberData
))]
public
void
FormatAndParse_DifferentUnicodeSpaces_Succeeds
(
char
formatSpaceChar
,
char
parseSpaceChar
)
{
var
dateTime
=
new
DateTime
(
2020
,
5
,
7
,
9
,
37
,
40
,
DateTimeKind
.
Local
);
DateTimeFormatInfo
formatDtfi
=
CreateDateTimeFormatInfo
(
formatSpaceChar
);
string
formatted
=
dateTime
.
ToString
(
formatDtfi
);
Assert
.
Contains
(
formatSpaceChar
,
formatted
);
DateTimeFormatInfo
parseDtfi
=
CreateDateTimeFormatInfo
(
parseSpaceChar
);
Assert
.
Equal
(
dateTime
,
DateTime
.
Parse
(
formatted
,
parseDtfi
));
static
DateTimeFormatInfo
CreateDateTimeFormatInfo
(
char
spaceChar
)
{
return
new
DateTimeFormatInfo
()
{
Calendar
=
DateTimeFormatInfo
.
InvariantInfo
.
Calendar
,
CalendarWeekRule
=
DateTimeFormatInfo
.
InvariantInfo
.
CalendarWeekRule
,
FirstDayOfWeek
=
DayOfWeek
.
Monday
,
AMDesignator
=
"AM"
,
DateSeparator
=
"/"
,
FullDateTimePattern
=
$"dddd,
{
spaceChar
}
MMMM
{
spaceChar
}
d,
{
spaceChar
}
yyyy
{
spaceChar
}
h:mm:ss
{
spaceChar
}
tt"
,
LongDatePattern
=
$"dddd,
{
spaceChar
}
MMMM
{
spaceChar
}
d,
{
spaceChar
}
yyyy"
,
LongTimePattern
=
$"h:mm:ss
{
spaceChar
}
tt"
,
MonthDayPattern
=
"MMMM d"
,
PMDesignator
=
"PM"
,
ShortDatePattern
=
"M/d/yyyy"
,
ShortTimePattern
=
$"h:mm
{
spaceChar
}
tt"
,
TimeSeparator
=
":"
,
YearMonthPattern
=
$"MMMM
{
spaceChar
}
yyyy"
,
AbbreviatedDayNames
=
new
[]
{
"Sun"
,
"Mon"
,
"Tue"
,
"Wed"
,
"Thu"
,
"Fri"
,
"Sat"
},
ShortestDayNames
=
new
[]
{
"Su"
,
"Mo"
,
"Tu"
,
"We"
,
"Th"
,
"Fr"
,
"Sa"
},
DayNames
=
new
[]
{
"Sunday"
,
"Monday"
,
"Tuesday"
,
"Wednesday"
,
"Thursday"
,
"Friday"
,
"Saturday"
},
AbbreviatedMonthNames
=
new
[]
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
,
""
},
MonthNames
=
new
[]
{
"January"
,
"February"
,
"March"
,
"April"
,
"May"
,
"June"
,
"July"
,
"August"
,
"September"
,
"October"
,
"November"
,
"December"
,
""
},
AbbreviatedMonthGenitiveNames
=
new
[]
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
,
""
},
MonthGenitiveNames
=
new
[]
{
"January"
,
"February"
,
"March"
,
"April"
,
"May"
,
"June"
,
"July"
,
"August"
,
"September"
,
"October"
,
"November"
,
"December"
,
""
}
};
}
}
public
static
IEnumerable
<
object
[
]>
ParseExact_ValidInput_Succeeds_MemberData
()
{
foreach
(
DateTimeStyles
style
in
new
[]
{
DateTimeStyles
.
None
,
DateTimeStyles
.
AllowWhiteSpaces
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录