@@ -1544,6 +1544,9 @@ void CMUSHclientDoc:: SavePrefsP13 (CPrefsP13 &page13)
1544
1544
void CMUSHclientDoc:: SavePrefsP14 (CPrefsP14 &page14)
1545
1545
{
1546
1546
DelayDebugMsg (" Saving" , 14 );
1547
+
1548
+ bool utf8Changed = m_bUTF_8 != page14.m_bUTF_8 ;
1549
+
1547
1550
m_font_height = page14.m_font_height ;
1548
1551
m_font_name = page14.m_font_name ;
1549
1552
m_font_weight = page14.m_font_weight ;
@@ -1618,6 +1621,25 @@ void CMUSHclientDoc:: SavePrefsP14 (CPrefsP14 &page14)
1618
1621
1619
1622
FixInputWrap ();
1620
1623
1624
+ // changing to or from UTF-8 will alter the way trigger and alias regular expressions
1625
+ // need to be compiled so we recompile all of them
1626
+ if (utf8Changed)
1627
+ {
1628
+ m_CurrentPlugin = NULL ;
1629
+ RecompileRegularExpressions (); // do main world
1630
+
1631
+ // do plugins
1632
+ for (PluginListIterator pit = m_PluginList.begin ();
1633
+ pit != m_PluginList.end ();
1634
+ ++pit)
1635
+ {
1636
+ m_CurrentPlugin = *pit;
1637
+ RecompileRegularExpressions (); // do this plugin
1638
+ } // end of doing each plugin
1639
+
1640
+ m_CurrentPlugin = NULL ; // not in a plugin any more
1641
+ } // end of utf8Changed
1642
+
1621
1643
} // end of CMUSHclientDoc::SavePrefsP14
1622
1644
1623
1645
void CMUSHclientDoc:: SavePrefsP15 (CPrefsP15 &page15)
@@ -2351,10 +2373,103 @@ Frame.DelayDebugStatus ("World config - loading pages");
2351
2373
Frame.SetStatusNormal ();
2352
2374
2353
2375
return true ; // did it OK
2354
- }
2376
+ } // end of CMUSHclientDoc::GamePreferences
2355
2377
2356
2378
2357
2379
void CMUSHclientDoc::OnGamePreferences ()
2358
2380
{
2359
2381
GamePreferences (-1 ); // use last page, whatever it was
2360
- }
2382
+ } // end of CMUSHclientDoc::OnGamePreferences
2383
+
2384
+ void CMUSHclientDoc::RecompileRegularExpressions ()
2385
+ {
2386
+ int iTriggerErrors = 0 ;
2387
+ #if ALIASES_USE_UTF8
2388
+ int iAliasErrors = 0 ;
2389
+ #endif // ALIASES_USE_UTF8
2390
+
2391
+ POSITION pos;
2392
+ CString strName;
2393
+ CString strRegexp;
2394
+
2395
+ for (pos = GetTriggerMap ().GetStartPosition (); pos;)
2396
+ {
2397
+ CTrigger * pTrigger;
2398
+ GetTriggerMap ().GetNextAssoc (pos, strName, pTrigger);
2399
+
2400
+ if (pTrigger->regexp )
2401
+ {
2402
+ delete pTrigger->regexp ; // get rid of old one
2403
+ if (pTrigger->bRegexp )
2404
+ strRegexp = pTrigger->trigger ;
2405
+ else
2406
+ strRegexp = ConvertToRegularExpression (pTrigger->trigger );
2407
+ }
2408
+
2409
+ // compile regular expression
2410
+ try
2411
+ {
2412
+ pTrigger->regexp = regcomp (strRegexp, (pTrigger->ignore_case ? PCRE_CASELESS : 0 ) |
2413
+ (pTrigger->bMultiLine ? PCRE_MULTILINE : 0 ) |
2414
+ (m_bUTF_8 ? PCRE_UTF8 : 0 )
2415
+ );
2416
+ } // end of try
2417
+ catch (CException* e)
2418
+ {
2419
+ e->Delete ();
2420
+ iTriggerErrors++;
2421
+ pTrigger->regexp = NULL ;
2422
+ } // end of catch
2423
+ } // end of for each trigger
2424
+
2425
+ #if ALIASES_USE_UTF8
2426
+
2427
+ for (pos = GetAliasMap ().GetStartPosition (); pos;)
2428
+ {
2429
+ CAlias * pAlias;
2430
+ GetAliasMap ().GetNextAssoc (pos, strName, pAlias);
2431
+
2432
+ if (pAlias->regexp )
2433
+ {
2434
+ delete pAlias->regexp ; // get rid of old one
2435
+ if (pAlias->bRegexp )
2436
+ strRegexp = pAlias->name ;
2437
+ else
2438
+ strRegexp = ConvertToRegularExpression (pAlias->name );
2439
+ }
2440
+
2441
+ // compile regular expression
2442
+ try
2443
+ {
2444
+ pAlias->regexp = regcomp (strRegexp, (pAlias->bIgnoreCase ? PCRE_CASELESS : 0 ) |
2445
+ (m_bUTF_8 ? PCRE_UTF8 : 0 )
2446
+ );
2447
+ } // end of try
2448
+ catch (CException* e)
2449
+ {
2450
+ e->Delete ();
2451
+ iAliasErrors++;
2452
+ pAlias->regexp = NULL ;
2453
+ } // end of catch
2454
+ } // end of for each alias
2455
+
2456
+ #endif // ALIASES_USE_UTF8
2457
+
2458
+ const char * sPluginName = " (Main world)" ;
2459
+
2460
+ if (m_CurrentPlugin)
2461
+ sPluginName = m_CurrentPlugin->m_strName ;
2462
+
2463
+ if (iTriggerErrors)
2464
+ ColourNote (" white" , " red" ,
2465
+ TFormat (" In plugin %s, %i trigger(s) could not be recompiled." ,
2466
+ sPluginName , iTriggerErrors));
2467
+
2468
+ #if ALIASES_USE_UTF8
2469
+ if (iAliasErrors)
2470
+ ColourNote (" white" , " red" ,
2471
+ TFormat (" In plugin %s, %i alias(es) could not be recompiled." ,
2472
+ sPluginName , iAliasErrors));
2473
+ #endif // ALIASES_USE_UTF8
2474
+
2475
+ } // end of CMUSHclientDoc::RecompileRegularExpressions
0 commit comments