1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* enc/trans/newline.trans: record newline types met in universal

newline decoder.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19136 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-09-04 14:20:14 +00:00
parent 645f25356a
commit 64b633f069
2 changed files with 32 additions and 12 deletions

View file

@ -1,3 +1,8 @@
Thu Sep 4 23:18:55 2008 Tanaka Akira <akr@fsij.org>
* enc/trans/newline.trans: record newline types met in universal
newline decoder.
Thu Sep 4 23:05:54 2008 Yuki Sonoda (Yugui) <yugui@yugui.jp>
* lib/prime.rb (Prime::OldCompatibility#each): added compatibility to

View file

@ -21,14 +21,22 @@
<%= transcode_generated_code %>
#define STATE (sp[0])
#define NORMAL 0
#define JUST_AFTER_CR 1
/* no way to access this information, yet. */
#define NEWLINES_MET (sp[1])
#define MET_LF 0x01
#define MET_CRLF 0x02
#define MET_CR 0x04
static int
universal_newline_init(void *statep)
{
unsigned char *sp = statep;
*sp = NORMAL;
STATE = NORMAL;
NEWLINES_MET = 0;
return 0;
}
@ -38,25 +46,32 @@ fun_so_universal_newline(void *statep, const unsigned char* s, size_t l, unsigne
unsigned char *sp = statep;
int len;
if (s[0] == '\n') {
if (*sp == NORMAL) {
if (STATE == NORMAL) {
NEWLINES_MET |= MET_LF;
o[0] = '\n';
len = 1;
}
else { /* JUST_AFTER_CR */
NEWLINES_MET |= MET_CRLF;
len = 0;
}
*sp = NORMAL;
STATE = NORMAL;
}
else if (s[0] == '\r') {
else {
if (STATE == JUST_AFTER_CR)
NEWLINES_MET |= MET_CR;
if (s[0] == '\r') {
o[0] = '\n';
len = 1;
*sp = JUST_AFTER_CR;
STATE = JUST_AFTER_CR;
}
else {
o[0] = s[0];
len = 1;
*sp = NORMAL;
STATE = NORMAL;
}
}
return len;
}
@ -68,7 +83,7 @@ rb_universal_newline = {
1, /* max_input */
1, /* max_output */
stateful_decoder, /* stateful_type */
1, universal_newline_init, universal_newline_init, /* state_size, state_init, state_fini */
2, universal_newline_init, universal_newline_init, /* state_size, state_init, state_fini */
NULL, NULL, NULL, fun_so_universal_newline
};