@@ -196,6 +196,9 @@ private static void OnTextLanguageChanged(DependencyObject d, DependencyProperty
196
196
[ GeneratedRegex ( @"^(?:[^\P{P}'-]+|\s)$" ) ]
197
197
private static partial Regex WordSplitFullReg { get ; }
198
198
199
+ [ GeneratedRegex ( @"((?:[^\P{P}'-]+|\s|[\p{IsCJKUnifiedIdeographs}\p{IsCJKUnifiedIdeographsExtensionA}]))" ) ]
200
+ private static partial Regex ChineseWordSplitReg { get ; }
201
+
199
202
200
203
private static readonly Lazy < MeCabIpaDicTagger > MeCabTagger = new ( ( ) => MeCabIpaDicTagger . Create ( ) , true ) ;
201
204
@@ -228,31 +231,43 @@ private void SetText(string text)
228
231
// Use an OutlinedTextBlock for each word to display the border Text and enclose it in a WrapPanel
229
232
for ( int i = 0 ; i < lines . Length ; i ++ )
230
233
{
231
- List < string > words ;
234
+ IEnumerable < string > words ;
232
235
233
236
if ( TextLanguage != null && TextLanguage . ISO6391 == "ja" )
234
237
{
235
238
// word segmentation for Japanese
236
239
// TODO: L: Also do word segmentation in sidebar
237
240
var nodes = MeCabTagger . Value . Parse ( lines [ i ] ) ;
238
- words = new List < string > ( nodes . Length ) ;
241
+ List < string > wordsList = new ( nodes . Length ) ;
239
242
foreach ( var node in nodes )
240
243
{
241
244
// If there are space-separated characters, such as English, add them manually since they are not on the Surface
242
245
if ( char . IsWhiteSpace ( lines [ i ] [ node . BPos ] ) )
243
246
{
244
- words . Add ( " " ) ;
247
+ wordsList . Add ( " " ) ;
245
248
}
246
- words . Add ( node . Surface ) ;
249
+ wordsList . Add ( node . Surface ) ;
247
250
}
251
+
252
+ words = wordsList ;
253
+ }
254
+ else if ( TextLanguage != null && TextLanguage . ISO6391 == "zh" )
255
+ {
256
+ words = ChineseWordSplitReg . Split ( lines [ i ] ) ;
248
257
}
249
258
else
250
259
{
251
- words = WordSplitReg . Split ( lines [ i ] ) . Where ( w => w != "" ) . ToList ( ) ;
260
+ words = WordSplitReg . Split ( lines [ i ] ) ;
252
261
}
253
262
254
263
foreach ( string word in words )
255
264
{
265
+ // skip empty string because Split includes
266
+ if ( word . Length == 0 )
267
+ {
268
+ continue ;
269
+ }
270
+
256
271
if ( string . IsNullOrWhiteSpace ( word ) )
257
272
{
258
273
// Blanks are inserted with TextBlock.
0 commit comments