/* * [ToHex.java] * * Summary: Converts String to Lower case. * * Copyright: (c) 2002-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2002-06-19 */ package com.mindprod.quoter; import com.mindprod.common18.ST; /** * Converts String to Lower case. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2002-06-19 * @since 2002-06-19 */ final class ToHex extends TextProcessor { /** * Chops off leading and trailing spaces from each line. * * @param raw text to be chopped * * @return String representing the cooked output */ String process( String raw ) { if ( raw == null ) { return null; } final int length = raw.length(); StringBuilder sb = new StringBuilder( length * 7 ); // Note off does not count characters; // it tracks the offset in the String. // Note no off++ ! for ( int off = 0; off < length; ) { final int codePoint = raw.codePointAt( off ); final int width = Character.charCount( codePoint ); sb.append( Character.toChars( codePoint ) ); sb.append( "-" ); final String hex; if ( codePoint <= 0xff ) { hex = ST.toLZHexString( codePoint, 2 ); } else if ( codePoint <= 0xffff ) { hex = ST.toLZHexString( codePoint, 4 ); } else { hex = ST.toLZHexString( codePoint, 5 ); } sb.append( hex ); sb.append( " " ); // hop to next character, normally 1 slot further along. // This incrementer code can't go in the for since codepoint is undefined there. off += width; } return sb.toString(); } }