Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/SIL.Machine/PunctuationAnalysis/TextSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ public class SurrogatePairString
public SurrogatePairString(string stringValue)
{
_stringValue = stringValue;
IEnumerable<(int SurrogatePairIndex, int StringIndex)> indexPairs = _stringValue
.Select((c, i) => (c, i))
IEnumerable<(int StringIndex, int SurrogatePairIndex)> indexPairs = _stringValue
.Select((c, stringIndex) => (c, stringIndex))
.Where(tup => !char.IsLowSurrogate(tup.c))
.Select((tup, i) => (tup.i, i));
.Select((tup, surrogatePairIndex) => (tup.stringIndex, surrogatePairIndex));
_surrogatePairIndexByStringIndex = new Dictionary<int, int>();
_stringIndexBySurrogatePairIndex = new Dictionary<int, int>();
foreach ((int surrogatePairIndex, int stringIndex) in indexPairs)
foreach ((int stringIndex, int surrogatePairIndex) in indexPairs)
{
_surrogatePairIndexByStringIndex[stringIndex] = surrogatePairIndex;
_stringIndexBySurrogatePairIndex[surrogatePairIndex] = stringIndex;
Expand Down Expand Up @@ -251,11 +251,11 @@ public string Substring(int startSurrogatePairIndex, int length)

public int GetStringIndexForSurrogatePairIndex(int surrogatePairIndex)
{
if (surrogatePairIndex == _surrogatePairIndexByStringIndex.Count)
if (surrogatePairIndex == _stringIndexBySurrogatePairIndex.Count)
{
return _stringValue.Length;
}
return _surrogatePairIndexByStringIndex[surrogatePairIndex];
return _stringIndexBySurrogatePairIndex[surrogatePairIndex];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,32 @@ public void ThatItUsesTheQuoteConventionSet()
)
);
}

[Test]
public void SupportsMultibyteUnicodeCharacters()
{
var quotationMarkFinder = new QuotationMarkFinder(QuoteConventions.Standard);

// [grinning face], [left double quotation mark][grinning face with big eyes][right double quotation mark]
Assert.That(
quotationMarkFinder
.FindAllPotentialQuotationMarksInTextSegment(
new TextSegment.Builder().SetText("\U0001f600, \u201c\U0001f603\u201d").Build()
)
.SequenceEqual(
[
new QuotationMarkStringMatch(
new TextSegment.Builder().SetText("\U0001f600, \u201c\U0001f603\u201d").Build(),
3,
4
),
new QuotationMarkStringMatch(
new TextSegment.Builder().SetText("\U0001f600, \u201c\U0001f603\u201d").Build(),
5,
6
),
]
)
);
}
}
Loading