View Javadoc

1   package com.sharkysoft.printf;
2   
3   import com.sharkysoft.printf.engine.NumberFormatter;
4   import com.sharkysoft.util.UnreachableCodeException;
5   
6   class Formatter_x extends Formatter_Integer
7   {
8   
9     Formatter_x(final FormatSpecifier ipPfs)
10    {
11      super(ipPfs);
12      final NumberFormatter vpNf = (NumberFormatter) mpFormatter;
13      vpNf.setRadix(16);
14      switch (ipPfs.mcType)
15      {
16      case 'x' :
17        if (ipPfs.mcAlternate == FormatSpecifier.ALTERNATE_ON)
18        {
19          vpNf.setZeroPrefix("0x");
20          vpNf.setPosPrefix("0x");
21        }
22        vpNf.setUpperCase(false);
23        break;
24      case 'X' :
25        if (ipPfs.mcAlternate == FormatSpecifier.ALTERNATE_ON)
26        {
27          vpNf.setZeroPrefix("0X");
28          vpNf.setPosPrefix("0X");
29        }
30        vpNf.setUpperCase(true);
31        break;
32      default :
33        throw new UnreachableCodeException();
34      }
35    }
36  
37    void format(final PrintfState ipPs)
38    {
39      formatUnsignedInt(ipPs);
40    }
41    
42  }
43