replaceCharData(String fileName)
throws IOException, Exception
{
text = br.readLine();
sb = new StringBuffer();
int iRow = 0;
String strBefore,
strAfter;
int ind;
//pattern = Pattern.compile(searchPossibleMissedChars);
ConvertedRow convertedRow = null;
boolean bErrorFounded = false;
StringBuffer sbErrorRow = new StringBuffer();
StringBuffer sbErrorRowPosition = new StringBuffer();
int iRowLen, iRowLenPos;
while(text != null)
{
iRow++;
iRowLen = sbErrorRow.length();
bErrorFounded = false;
if (iRowLen > 0)
iRowLen = iRowLen -1;
sbErrorRow.delete(0, iRowLen);
// sbErrorRow = new StringBuffer();
iRowLenPos = sbErrorRowPosition.length();
if (iRowLenPos > 0)
iRowLenPos = iRowLenPos -1;
sbErrorRowPosition.delete(0, iRowLenPos);
// sbErrorRowPosition = new StringBuffer();
if (text.equals("")) // jos alkup. rivi sisältää pelkän CR:n
text = "\n"; // lisää se
else
{
String tmp = text;
if (tmp.length() == 0)
text = "\n"; // poista välilyonnit
else
{ // testaa onko trimmattu tmp vain white
char [] chars = tmp.toCharArray();
int max = chars.length;
boolean isWhiteSpace = true;
for(int i = 0; i < max; i++)
{
if (!Character.isWhitespace(chars[i]))
{
isWhiteSpace = false;
break;
}
}
if (isWhiteSpace)
text = "\n"; // poista välilyonnit
else
{
//text = DecoderCharacterSet.changeSpecialChars(text);
if (m_bMakeCharConverstion)
{
convertedRow = makeCharConvert(text);
if (convertedRow != null)
{
//String unModInputRow = convertedRow.getInputRow();
String strOutputRow = convertedRow.getOutputRow();
if (strOutputRow != null)
{
String strErrorRow = null;
byte [] arrByteUnModInputRow = convertedRow.getArrChangedCharFlags();
int maxU = strOutputRow.length();
char ch;
byte modified;
int maxE ;
CharArea ca;
int iCh;
boolean bCharError = false;
for(int i = 0 ; i < maxU; i++)
{
ch = strOutputRow.charAt(i);
maxE = arrExcludeAreas.length;
iCh = ch;
bCharError = false;
for(int k = 0 ; k < maxE; k++)
{
ca = arrExcludeAreas[k];
if (ca == null)
continue;
if (iCh >= ca.getChStartChar() && iCh <= ca.getChEndChar())
{
int indErrorPos = i;
bErrorFounded = true;
bCharError = true;
sbErrorRow.append("[");
sbErrorRow.append(ch);
sbErrorRow.append("]");
String strCh = "" +ch;
sbErrorRowPosition.append(
"\nrow: " + iRow +"\n");
sbErrorRowPosition.append("column: " + (i+1) +"\n");
sbErrorRowPosition.append("position: " + (i+1) +"\n");
sbErrorRowPosition.append("position end: " + (i+1) +"\n");
sbErrorRowPosition.append("'" + ch +"' => utf-8 char: " +iCh +" "
+"utf-8 in hex: "
+byteArrayToHexString(strCh.getBytes()) +"\n");
// strErrorRow = sbErrorRow.toString();
// int iChError = ch;
// giveErrorMessage(fileName,
/// strErrorRow, iRow, indErrorPos);
break;
}
}
if (!bCharError)
sbErrorRow.append(ch);
}
}
}
}
}
}
if (bErrorFounded)
{
giveErrorMessage(fileName,
sbErrorRow.toString() +"\n"
+ sbErrorRowPosition.toString() +"\n", iRow, -1);
}
sb.append(text +"\n");
text = br.readLine();