Skip to content

Commit

Permalink
Fix passing locale to ubrk_open
Browse files Browse the repository at this point in the history
The locale string must be passed as UnmanagedType.LPStr, as opposed to the actual text, which must be passed as Unicode string.
Otherwise, only the first character of the locale string is used
  • Loading branch information
cbersch committed Apr 12, 2022
1 parent e277c98 commit 08cff0c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions source/icu.net.tests/BreakIteratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ public void GetBoundaries_Line()
Assert.That(parts.ToArray(), Is.EquivalentTo(expected));
}

[Test]
public void GetBoundaries_LocaleDependentBreakPoints_Line()
{
var text = "論‼";

var parts = BreakIterator.GetBoundaries(BreakIterator.UBreakIteratorType.LINE, new Locale("ja@lb=loose"), text);

// we only get 2 boundaries if the ja locale is passed correctly
Assert.That(parts.Count(), Is.EqualTo(2));
}

[Test]
public void GetBoundaries_Sentence()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private class BreakIteratorMethodsContainer
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
internal delegate IntPtr ubrk_openDelegate(BreakIterator.UBreakIteratorType type,
string locale, string text, int textLength, out ErrorCode errorCode);
[MarshalAs(UnmanagedType.LPStr)] string locale, string text, int textLength, out ErrorCode errorCode);

[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
internal delegate IntPtr ubrk_openRulesDelegate(string rules, int rulesLength,
Expand Down

0 comments on commit 08cff0c

Please sign in to comment.