still going

This commit is contained in:
benfry
2004-01-17 19:40:05 +00:00
parent d58f6c455b
commit 4164f86233
4 changed files with 61 additions and 220 deletions

View File

@@ -80,6 +80,40 @@ public class PdePreprocessor {
this.programReader = new StringReader(program);
this.buildPath = buildPath;
if (PdePreferences.getBoolean("compiler.convert_unicode")) {
// check for non-ascii chars (these will be/must be in unicode format)
char p[] = program.toCharArray();
int unicodeCount = 0;
for (int i = 0; i < p.length; i++) {
if (p[i] > 127) unicodeCount++;
}
// if non-ascii chars are in there, convert to unicode escapes
if (unicodeCount != 0) {
// add unicodeCount * 5.. replacing each unicode char
// with six digit \uXXXX sequence (xxxx is in hex)
// (except for nbsp chars which will be a replaced with a space)
int index = 0;
char p2[] = new char[p.length + unicodeCount*5];
for (int i = 0; i < p.length; i++) {
if (p[i] < 128) {
p2[index++] = p[i];
} else if (p[i] == 160) { // unicode for non-breaking space
p2[index++] = ' ';
} else {
int c = p[i];
p2[index++] = '\\';
p2[index++] = 'u';
char str[] = Integer.toHexString(c).toCharArray();
// add leading zeros, so that the length is 4
for (int i = 0; i < 4 - str.length; i++) p2[index++] = '0';
System.arraycopy(str, 0, p2, index, str.length);
}
}
}
}
// create a lexer with the stream reader, and tell it to handle
// hidden tokens (eg whitespace, comments) since we want to pass these
// through so that the line numbers when the compiler reports errors