Updated unicode to wylie converter to only convert chars in the tibetan range and ignore other chars.

This commit is contained in:
amontano 2008-12-15 06:08:19 +00:00
parent 36e222fccc
commit ffb32b3207

View file

@ -46,6 +46,7 @@ public class BasicTibetanTranscriptionConverter implements FontConverterConstant
private static final int WYLIE_TO_ACIP=2; private static final int WYLIE_TO_ACIP=2;
private static final int UNICODE_TO_WYLIE=3; private static final int UNICODE_TO_WYLIE=3;
private static final int WYLIE_TO_UNICODE=4; private static final int WYLIE_TO_UNICODE=4;
private static final int TIBETAN_UNICODE_RANGE[] = {3840, 4095};
/** Converts from the Acip transliteration scheme to EWTS.*/ /** Converts from the Acip transliteration scheme to EWTS.*/
public static String acipToWylie(String acip) public static String acipToWylie(String acip)
@ -253,14 +254,36 @@ public class BasicTibetanTranscriptionConverter implements FontConverterConstant
return nuevaPalabra;*/ return nuevaPalabra;*/
} }
private static int getTibetanUnicodeStart(String unicode, int pos)
{
for(; pos < unicode.length(); pos++ ) if(unicode.codePointAt(pos)>=TIBETAN_UNICODE_RANGE[0] && unicode.codePointAt(pos)<=TIBETAN_UNICODE_RANGE[1]) return pos;
return -1;
}
private static int getTibetanUnicodeEnd(String unicode, int pos)
{
for(; pos < unicode.length(); pos++ ) if(unicode.codePointAt(pos)<TIBETAN_UNICODE_RANGE[0] || unicode.codePointAt(pos)>TIBETAN_UNICODE_RANGE[1]) return pos;
return pos;
}
/** Converts Tibetan Unicode to EWTS. */ /** Converts Tibetan Unicode to EWTS. */
public static String unicodeToWylie(String unicode) public static String unicodeToWylie(String unicode)
{ {
String machineWylie;
TibetanDocument tibDoc = new TibetanDocument();
StringBuffer errors = new StringBuffer();
machineWylie = Converter.convertToEwtsForComputers(unicode, errors); String machineWylie, startString, tibetanString, endString;
TibetanDocument tibDoc;
StringBuffer errors;
int posStart=0, posEnd;
while((posStart = getTibetanUnicodeStart(unicode, posStart))>=0)
{
posEnd = getTibetanUnicodeEnd(unicode, posStart+1);
startString = unicode.substring(0, posStart);
tibetanString = unicode.substring(posStart, posEnd);
endString = unicode.substring(posEnd);
tibDoc = new TibetanDocument();
errors = new StringBuffer();
machineWylie = Converter.convertToEwtsForComputers(tibetanString, errors);
try try
{ {
TibTextUtils.insertTibetanMachineWebForTranslit(true, machineWylie, tibDoc, 0, false); TibTextUtils.insertTibetanMachineWebForTranslit(true, machineWylie, tibDoc, 0, false);
@ -269,7 +292,9 @@ public class BasicTibetanTranscriptionConverter implements FontConverterConstant
{ {
return null; return null;
} }
return tibDoc.getWylie(new boolean[] { false }); unicode = startString + tibDoc.getWylie(new boolean[] { false }) + endString;
}
return unicode;
} }
/** Converts EWTS to Tibetan Unicode. */ /** Converts EWTS to Tibetan Unicode. */
@ -424,10 +449,13 @@ public class BasicTibetanTranscriptionConverter implements FontConverterConstant
break; break;
default: result = linea; default: result = linea;
} }
if (result!=null) out.println(result); if (result!=null)
} {
out.println(result);
out.flush(); out.flush();
} }
}
}
public static BufferedReader getBufferedReader(String s, String format) throws Exception public static BufferedReader getBufferedReader(String s, String format) throws Exception
{ {