Skip to content

Commit

Permalink
TimeFormat: icu: use no-break spaces while formatting, and support pa…
Browse files Browse the repository at this point in the history
…rsing them.
  • Loading branch information
tmds committed Mar 28, 2023
1 parent 2d5a916 commit b321f3b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
char current = icuFormatString[i];
current = icuFormatString[i];
result[resultPos++] = current;
if (current == '\'')
{
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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",
Expand Down

0 comments on commit b321f3b

Please sign in to comment.