@@ -133,6 +133,14 @@ private Settings(XElement xml)
133133 . Select ( term => new KeyValuePair < string , string > ( term . Attribute ( "Avoid" ) . Value , term . Attribute ( "Prefer" ) . Value ) )
134134 . ToDictionary ( pair => pair . Key , pair => pair . Value ) ;
135135 }
136+
137+ XElement digitSeparators = xml . Element ( "DigitSeparators" ) ;
138+ if ( digitSeparators != null )
139+ {
140+ this . DecimalSeparators = GetDigitSeparatorFormat ( digitSeparators . Element ( "Decimal" ) , this . DecimalSeparators ) ;
141+ this . HexadecimalSeparators = GetDigitSeparatorFormat ( digitSeparators . Element ( "Hexadecimal" ) , this . HexadecimalSeparators ) ;
142+ this . BinarySeparators = GetDigitSeparatorFormat ( digitSeparators . Element ( "Binary" ) , this . BinarySeparators ) ;
143+ }
136144 }
137145
138146 #endregion
@@ -181,6 +189,16 @@ private Settings(XElement xml)
181189
182190 #endregion
183191
192+ #region Private Properties
193+
194+ private ( byte MinSize , byte GroupSize ) DecimalSeparators { get ; } = ( 5 , 3 ) ; // Group Per-Thousand
195+
196+ private ( byte MinSize , byte GroupSize ) HexadecimalSeparators { get ; } = ( 5 , 2 ) ; // Group Per-Byte
197+
198+ private ( byte MinSize , byte GroupSize ) BinarySeparators { get ; } = ( 6 , 4 ) ; // Group Per-Nibble
199+
200+ #endregion
201+
184202 #region Public Methods
185203
186204 public static Settings Cache ( AnalysisContext context , AnalyzerOptions options , CancellationToken cancellationToken )
@@ -302,6 +320,18 @@ public bool UsePreferredTerm(string term, out string preferredTerm)
302320 return result ;
303321 }
304322
323+ public ( byte MinSize , byte GroupSize ) GetDigitSeparatorFormat ( NumericLiteral literal )
324+ {
325+ ( byte MinSize , byte GroupSize ) result = literal . Base switch
326+ {
327+ NumericBase . Hexadecimal => this . HexadecimalSeparators ,
328+ NumericBase . Binary => this . BinarySeparators ,
329+ _ => this . DecimalSeparators ,
330+ } ;
331+
332+ return result ;
333+ }
334+
305335 #endregion
306336
307337 #region Private Methods
@@ -409,6 +439,31 @@ private static (string Scrubbed, NumericBase Base) SplitNumericLiteral(string te
409439 return ( text , numericBase ) ;
410440 }
411441
442+ private ( byte MinSize , byte GroupSize ) GetDigitSeparatorFormat ( XElement ? baseElement , ( byte MinSize , byte GroupSize ) defaultSeparators )
443+ {
444+ ( byte MinSize , byte GroupSize ) result = defaultSeparators ;
445+
446+ if ( baseElement != null )
447+ {
448+ byte minSize = GetByte ( baseElement , "MinSize" , defaultSeparators . MinSize ) ;
449+ byte groupSize = GetByte ( baseElement , "GroupSize" , defaultSeparators . GroupSize ) ;
450+ result = ( minSize , groupSize ) ;
451+ }
452+
453+ static byte GetByte ( XElement element , string attributeName , byte defaultValue )
454+ {
455+ string ? value = element . Attribute ( attributeName ) ? . Value ;
456+ if ( ! byte . TryParse ( value , out byte result ) )
457+ {
458+ result = defaultValue ;
459+ }
460+
461+ return result ;
462+ }
463+
464+ return result ;
465+ }
466+
412467 #endregion
413468
414469 #region Private Delegates
0 commit comments