pibfi
.
This is not efficient. An efficient implementation would compile the candidates into a finite-state machine first. This doesn't do that.
Exported Functions | |
---|---|
flush/1 | Causes the xlat server to flush all its characters to the output, even ones in the process of matching candidate strings. |
notify/2 | Notifies the other end of the connection. |
send/2 | Sends a character or characters to an xlat server for translation. |
server/2 | Spawned by start/2 , should not be called
directly by user code. |
start/2 | Starts an xlat server. |
test/0 |
flush(xlat()) -> ok
Causes the xlat server to flush all its characters to the output, even ones in the process of matching candidate strings. Typically this is called before the output is closed.
notify(xlat(), term()) -> ok
Notifies the other end of the connection.
They will receive a {Xlat::pid(), Notifier::pid(), message, term()}
message.
send(xlat(), char() | string()) -> ok
Sends a character or characters to an xlat server for translation.
server(candidates(), Dest::pid()) -> never_returns()
Spawned by start/2
, should not be called
directly by user code.
start(candidates(), Dest::pid()) -> xlat()
Starts an xlat server. Candidates is a list of pairs of strings.
Characters are sent to the xlat server with the send/2
function. When they match the left
string of a candidate, the right string is sent to Dest instead.
If they do not match any candidates, they are sent through unaltered.
Characters are sent to Dest in the form
{xlat(), xlat_char, char()}
.
Note that if two candidates have the same left string, the result of
the translation is undefined. Also note that if one candidate has
a left string that is a prefix of another candidate's left string,
that second candidate will never match (the shorter one will always
be matched first.)
test() -> term()