* 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
Родитель 645f25356a
Коммит 64b633f069
2 изменённых файлов: 32 добавлений и 12 удалений

Просмотреть файл

@ -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> Thu Sep 4 23:05:54 2008 Yuki Sonoda (Yugui) <yugui@yugui.jp>
* lib/prime.rb (Prime::OldCompatibility#each): added compatibility to * lib/prime.rb (Prime::OldCompatibility#each): added compatibility to

Просмотреть файл

@ -21,14 +21,22 @@
<%= transcode_generated_code %> <%= transcode_generated_code %>
#define STATE (sp[0])
#define NORMAL 0 #define NORMAL 0
#define JUST_AFTER_CR 1 #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 static int
universal_newline_init(void *statep) universal_newline_init(void *statep)
{ {
unsigned char *sp = statep; unsigned char *sp = statep;
*sp = NORMAL; STATE = NORMAL;
NEWLINES_MET = 0;
return 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; unsigned char *sp = statep;
int len; int len;
if (s[0] == '\n') { if (s[0] == '\n') {
if (*sp == NORMAL) { if (STATE == NORMAL) {
NEWLINES_MET |= MET_LF;
o[0] = '\n'; o[0] = '\n';
len = 1; len = 1;
} }
else { /* JUST_AFTER_CR */ else { /* JUST_AFTER_CR */
NEWLINES_MET |= MET_CRLF;
len = 0; len = 0;
} }
*sp = NORMAL; STATE = NORMAL;
}
else if (s[0] == '\r') {
o[0] = '\n';
len = 1;
*sp = JUST_AFTER_CR;
} }
else { else {
o[0] = s[0]; if (STATE == JUST_AFTER_CR)
len = 1; NEWLINES_MET |= MET_CR;
*sp = NORMAL; if (s[0] == '\r') {
o[0] = '\n';
len = 1;
STATE = JUST_AFTER_CR;
}
else {
o[0] = s[0];
len = 1;
STATE = NORMAL;
}
} }
return len; return len;
} }
@ -68,7 +83,7 @@ rb_universal_newline = {
1, /* max_input */ 1, /* max_input */
1, /* max_output */ 1, /* max_output */
stateful_decoder, /* stateful_type */ 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 NULL, NULL, NULL, fun_so_universal_newline
}; };