1 package com.sharkysoft.printf; 2 3 import com.sharkysoft.printf.engine.IntegerFormatter; 4 import com.sharkysoft.printf.engine.NumberFormatter; 5 import com.sharkysoft.util.UnreachableCodeException; 6 7 class Formatter_p extends Formatter_Integer 8 { 9 10 Formatter_p(final FormatSpecifier ipPfs) 11 { 12 super(ipPfs); 13 NumberFormatter nf = (NumberFormatter) mpFormatter; 14 nf.setRadix(16); 15 switch (ipPfs.mcType) 16 { 17 case 'p' : 18 nf.setUpperCase(false); 19 if (ipPfs.mcAlternate == FormatSpecifier.ALTERNATE_ON) 20 { 21 nf.setZeroPrefix("0x"); 22 nf.setPosPrefix("0x"); 23 } 24 break; 25 case 'P' : 26 nf.setUpperCase(true); 27 if (ipPfs.mcAlternate == FormatSpecifier.ALTERNATE_ON) 28 { 29 nf.setZeroPrefix("0X"); 30 nf.setPosPrefix("0X"); 31 } 32 break; 33 default : 34 throw new UnreachableCodeException(); 35 } 36 } 37 38 void format(final PrintfState ipPs) 39 { 40 adjustWidthAndPrecision(ipPs); 41 ipPs.mpOutput.append 42 ( ((IntegerFormatter) mpFormatter).formatUnsigned 43 ( System.identityHashCode(ipPs.mapArgs[ipPs.mnArgIndex++]) 44 ) 45 ); 46 } 47 48 } 49