@@ -170,6 +170,11 @@ private static void OnLanguageChanged(DependencyObject d, DependencyPropertyChan
170
170
}
171
171
}
172
172
173
+ // SelectableTextBox uses char.IsPunctuation(), so use a regular expression for it.
174
+ // TODO: L: Sharing the code with TextBox
175
+ private static readonly Regex WordSplitReg = new ( @"((?:[^\P{P}'-]+|\s))" , RegexOptions . Compiled ) ;
176
+ private static readonly Regex WordSplitFullReg = new ( @"^(?:[^\P{P}'-]+|\s)$" , RegexOptions . Compiled ) ;
177
+
173
178
private static readonly Lazy < MeCabIpaDicTagger > MeCabTagger = new ( ( ) => MeCabIpaDicTagger . Create ( ) , true ) ;
174
179
175
180
private void SetText ( string text )
@@ -200,10 +205,6 @@ private void SetText(string text)
200
205
201
206
var wordOffset = 0 ;
202
207
203
- // SelectableTextBox uses char.IsPunctuation(), so use a regular expression for it.
204
- // TODO: L: Sharing the code with TextBox
205
- string splitPattern = @"((?:[^\P{P}'-]+|\s))" ;
206
-
207
208
// Use an OutlinedTextBlock for each word to display the border Text and enclose it in a WrapPanel
208
209
for ( int i = 0 ; i < lines . Length ; i ++ )
209
210
{
@@ -228,8 +229,7 @@ private void SetText(string text)
228
229
}
229
230
else
230
231
{
231
- words = Regex . Split ( lines [ i ] , splitPattern )
232
- . Where ( w => w != "" ) . ToList ( ) ;
232
+ words = WordSplitReg . Split ( lines [ i ] ) . Where ( w => w != "" ) . ToList ( ) ;
233
233
}
234
234
235
235
foreach ( string word in words )
@@ -252,7 +252,7 @@ private void SetText(string text)
252
252
continue ;
253
253
}
254
254
255
- bool isSplitChar = Regex . IsMatch ( word , splitPattern ) ;
255
+ bool isSplitChar = WordSplitFullReg . IsMatch ( word ) ;
256
256
257
257
OutlinedTextBlock textBlock = new ( )
258
258
{
0 commit comments