summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-04 14:20:14 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-04 14:20:14 +0000
commit64b633f069e9d86bd4cc6f1786558fe900df9d1a (patch)
tree9e85fad2d57167c006b51bbf33062727af00fb41
parent645f25356a4455ccac6aea19b9c7e73bdee9d960 (diff)
* 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
-rw-r--r--ChangeLog5
-rw-r--r--enc/trans/newline.trans39
2 files changed, 32 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 80d92720e6..24788d0f2c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/enc/trans/newline.trans b/enc/trans/newline.trans
index 7b10d368b1..90fb26eeb9 100644
--- a/enc/trans/newline.trans
+++ b/enc/trans/newline.trans
@@ -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;
- }
- else if (s[0] == '\r') {
- o[0] = '\n';
- len = 1;
- *sp = JUST_AFTER_CR;
+ STATE = NORMAL;
}
else {
- o[0] = s[0];
- len = 1;
- *sp = NORMAL;
+ if (STATE == JUST_AFTER_CR)
+ NEWLINES_MET |= MET_CR;
+ if (s[0] == '\r') {
+ o[0] = '\n';
+ len = 1;
+ STATE = JUST_AFTER_CR;
+ }
+ else {
+ o[0] = s[0];
+ len = 1;
+ 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
};