001 package com.croftsoft.core.text.sml;
002
003 import com.croftsoft.core.lang.StringLib;
004
005 /*********************************************************************
006 * Static methods for encoding and decoding SML.
007 *
008 * <p>
009 * Java 1.1 compatible.
010 * </p>
011 *
012 * @version
013 * 2001-08-09
014 * @since
015 * 2001-05-14
016 * @author
017 * <a href="https://www.croftsoft.com/">David Wallace Croft</a>
018 *********************************************************************/
019
020 public final class SmlCoder
021 //////////////////////////////////////////////////////////////////////
022 //////////////////////////////////////////////////////////////////////
023 {
024
025 public static void main ( String [ ] args )
026 //////////////////////////////////////////////////////////////////////
027 {
028 System.out.println ( encode ( "<>" ) );
029
030 System.out.println ( decode ( "<>" ) );
031 }
032
033 //////////////////////////////////////////////////////////////////////
034 //////////////////////////////////////////////////////////////////////
035
036 /*********************************************************************
037 * Encodes a String for SML transport.
038 *
039 * <p>
040 * Replaces angle brackets.
041 * </p>
042 *********************************************************************/
043 public static String encode ( String s )
044 //////////////////////////////////////////////////////////////////////
045 {
046 if ( s == null )
047 {
048 return null;
049 }
050
051 s = StringLib.replace ( s, "<", "<" );
052
053 s = StringLib.replace ( s, ">", ">" );
054
055 return s;
056 }
057
058 /*********************************************************************
059 * Decodes an SML String back into a regular String.
060 *
061 * <p>
062 * Substitutes angle brackets.
063 * </p>
064 *********************************************************************/
065 public static String decode ( String s )
066 //////////////////////////////////////////////////////////////////////
067 {
068 if ( s == null )
069 {
070 return null;
071 }
072
073 s = StringLib.replace ( s, "<", "<" );
074
075 s = StringLib.replace ( s, ">", ">" );
076
077 return s;
078 }
079
080 //////////////////////////////////////////////////////////////////////
081 //////////////////////////////////////////////////////////////////////
082
083 private SmlCoder ( ) { }
084
085 //////////////////////////////////////////////////////////////////////
086 //////////////////////////////////////////////////////////////////////
087 }