-
Notifications
You must be signed in to change notification settings - Fork 3
/
RTSTransformer.js
91 lines (78 loc) · 2.77 KB
/
RTSTransformer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// $Id: RTSTransformer.js,v 1.2 2005/09/25 14:52:28 vnagarjuna Exp $ -->
// Copyright 2005 Nagarjuna Venna <[email protected]>
// See http://lekhini.org/scripts/padma-license.txt
// Changes Copyright 2006 Veeven <veeven at gmail dot com>
// See http://lekhini.org/license.txt
//RTS Modes
RTSTransformer.rtsEnglish = 0;
RTSTransformer.rtsTelugu = 1;
function RTSTransformer(input, output) {
this.input = input;
this.output = output;
this.rtsMode = RTSTransformer.rtsEnglish;
}
function RTSTransformer_setRTSMode(mode) {
if (mode != RTSTransformer.rtsEnglish && mode != RTSTransformer.rtsTelugu)
return false;
this.rtsMode = mode;
return true;
}
function RTSTransformer_parse(text) {
var parser = new RTSParser(text);
var output = "";
while (parser.more())
output += this.toOutputFormat(parser.next());
return output;
}
function RTSTransformer_convert(text) {
if (this.rtsMode != RTSTransformer.rtsEnglish && this.rtsMode != RTSTransformer.rtsTelugu) {
alert("Invalid RTS mode " + this.rtsMode);
this.rtsMode = 0;
}
var output = "";
var next = 0;
do {
var hash = text.indexOf('#', next);
if (hash == next) {
hash = text.indexOf('#', hash + 1);
if (hash != -1) {
//Mode remains unchanged because we process text between hashes here
if (this.rtsMode == RTSTransformer.rtsEnglish)
output += this.parse(text.substring(next + 1, hash));
else output += text.substring(next + 1, hash);
}
else {
//mode changes because there is no terminating hash
if (this.rtsMode == RTSTransformer.rtsEnglish) {
this.rtsMode = RTSTransformer.rtsTelugu;
output += this.parse(text.substring(next + 1));
}
else {
this.rtsMode = RTSTransformer.rtsEnglish;
output += text.substring(next + 1);
}
}
next = hash + 1;
}
//don't change the mode yet because it will be done when it is matched the next time around
else if (hash != -1) {
if (this.rtsMode == RTSTransformer.rtsEnglish)
output += text.substring(next, hash);
else output += this.parse(text.substring(next, hash));
next = hash;
}
//Mode reamins the same because there are no more hashes
else {
if (this.rtsMode == RTSTransformer.rtsEnglish)
output += text.substring(next);
else output += this.parse(text.substring(next));
}
} while (hash != -1 && hash < text.length);
//alert(output);
return output;
}
//This doesn't seem to work in extension mode, add any mods to relationships.js too
RTSTransformer.prototype = new Transformer(Transformer.method_RTS, Transformer.method_Unicode);
RTSTransformer.prototype.convert = RTSTransformer_convert;
RTSTransformer.prototype.setRTSMode = RTSTransformer_setRTSMode;
RTSTransformer.prototype.parse = RTSTransformer_parse;