public static String resolveFigurative ( final String value , final int length , final boolean quoteIsQuote ) { if ( value == null || value . length ( ) == 0 ) { return value ; } String ucValue = value . toUpperCase ( Locale . getDefault ( ) ) ; if ( ucValue . matches ( "^ZERO(S|ES)?$" ) ) { return "0" ; } /* We avoid filling with spaces because this is the most common * initial value for large strings*/ if ( ucValue . matches ( "^SPACES?$" ) ) { return " " ; } if ( ucValue . matches ( "^QUOTES?$" ) ) { return quoteIsQuote ? "\"" : "\'" ; } if ( ucValue . matches ( "^APOST$" ) ) { return "\'" ; } /* For binary content, we use pseudo hexadecimal representation * This is understood downstream by the COBOL binder. */ if ( ucValue . matches ( "^HIGH-VALUES?$" ) ) { return fill ( "0x" , "FF" , length ) ; } if ( ucValue . matches ( "^LOW-VALUES?$" ) ) { return fill ( "0x" , "00" , length ) ; } /* Nulls are treated like low-value. */ if ( ucValue . matches ( "^NULLS?$" ) ) { return fill ( "0x" , "00" , length ) ; } /* All is followed by a literal which can be a figurative constant. * If that figurative constant is binary, then the filling already * took place. Otherwise, if the total length is not a multiple * of the repeated character sequence, then we need to fill the * the remainder with a substring of the literal. */ if ( ucValue . startsWith ( "ALL " ) ) { String literal = value . substring ( "ALL " . length ( ) ) ; String resolvedLiteral = ValueUtil . resolveFigurative ( literal , length , quoteIsQuote ) ; if ( resolvedLiteral . length ( ) > 0 && resolvedLiteral . length ( ) < length ) { String filled = fill ( null , resolvedLiteral , length / resolvedLiteral . length ( ) ) ; if ( filled . length ( ) < length ) { return filled + resolvedLiteral . substring ( 0 , length - filled . length ( ) ) ; } else { return filled ; } } else { return resolvedLiteral ; } } /* This is not a figurative constant just strip delimiters */ return stripDelimiters ( value ) ; }
Translate individual figurative constants .