Skip to content

Commit

Permalink
Convert whole escaped char sequence to string
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc committed Apr 29, 2019
1 parent 9722aa4 commit 06737b1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 51 deletions.
13 changes: 0 additions & 13 deletions MSGViewer/src/main/java/net/sourceforge/MSGViewer/HtmlFromRtf.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package net.sourceforge.MSGViewer;

import net.sourceforge.MSGViewer.rtfparser.ParseException;
import net.sourceforge.MSGViewer.rtfparser.RTFParser;
import java.io.StringReader;
import org.apache.log4j.Logger;

/**
*
* @author martin
*/
public class HtmlFromRtf
{
private static final Logger logger = Logger.getLogger(HtmlFromRtf.class.getName());
private static final String HTML_START = "{\\*\\htmltag";

final String htmlText;

public HtmlFromRtf(String bodyText) throws ParseException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package net.sourceforge.MSGViewer.rtfparser;

import at.redeye.FrameWork.utilities.StringUtils;
import java.io.UnsupportedEncodingException;
import org.apache.log4j.Logger;

/**
*
* @author martin
*/
public class ConvertCharset
{
private static final Logger logger = Logger.getLogger(ConvertCharset.class.getName());
Expand All @@ -22,18 +13,21 @@ static String convertCharacter( String characterSet, String text )
if( characterSet.isEmpty() )
return text;

byte[] bytes = new byte[1];
String hexa = text.replace("\\'", "");

byte[] bytes = new byte[hexa.length() / 2];

try {
bytes[0] = (byte) Integer.parseInt(text,16);
for (int i = 0; i < bytes.length; ++i) {
bytes[i] = (byte) Integer.parseInt(hexa.substring(2 * i, 2 * i + 2), 16);
}
} catch( NumberFormatException ex ) {
logger.error("character set: " + characterSet + " hey string '" + text + "'");
logger.error(StringUtils.exceptionToString(ex));
}

try {
String res = new String(bytes, "CP" + characterSet);
return res;
return new String(bytes, "CP" + characterSet);
} catch (UnsupportedEncodingException ex) {
logger.error("character set: " + characterSet + " hey string '" + text + "'");
logger.error(StringUtils.exceptionToString(ex));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package net.sourceforge.MSGViewer.rtfparser;

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;

/**
*
* @author martin
*/
public class RTFGroup
{
{
private StringBuilder text_content;
private List<String> commands = new ArrayList();
private final List<String> commands = new ArrayList<>();
private String last_command = "";

public RTFGroup()
{

}

void addCommand( String command )
{

if( command.equals("\\par") )
addTextContent("\n");
else if( command.equals("\\tab"))
Expand All @@ -37,6 +24,11 @@ else if( command.equals("\\tab"))
}
}

public void addEscapedChar( String characterSet, String hexa )
{
addTextContent(ConvertCharset.convertCharacter(characterSet, hexa));
}

public void addTextContent( String text )
{
if( text_content == null )
Expand Down Expand Up @@ -69,10 +61,7 @@ public List<String> getCommands()

boolean isEmptyText() {

if( text_content == null )
return true;

return text_content.length() == 0;
return StringUtils.isEmpty(text_content);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ SKIP : { " " | "\n" | "\r" | "\r\n" }
| < C_GROUP_START : "{" >
| < C_GROUP_END : "}" >
| < C_BACKSLASH : "\\\\" >
| < C_ESC_CHAR : "\\" "'" ( ["A"-"Z","a"-"z","0"-"9"] ){2} >
| < C_ESC_STRING : ("\\" "'" ( ["A"-"Z","a"-"z","0"-"9"] ){2})+ >
| < C_CODEPAGE : "\\ansicpg" ( [ "0"-"9"] ) + >
| < C_COMMAND : "\\" ( ["A"-"Z","a"-"z","0"-"9"] )+ >
| < C_SKIP_NEXT : "\\" "*" >
Expand Down Expand Up @@ -100,12 +100,12 @@ void group() : {}

void esc_special_char() :
{
Token esc_char = null;
Token esc_str = null;
}
{
esc_char = <C_ESC_CHAR>
esc_str = <C_ESC_STRING>
{
current_group.addTextContent( ConvertCharset.convertCharacter(characterSet, esc_char.image.substring(2)) );
current_group.addEscapedChar( characterSet, esc_str.image );
}
}

Expand Down

0 comments on commit 06737b1

Please # to comment.