Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: src/lexer/even-more-experimental-scanner.cc

Issue 80503002: Experimental lexer generator: Fix byte order mark detection. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/lexer/lexer_py.re » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 const byte* ReadFile(const char* name, Isolate* isolate, 62 const byte* ReadFile(const char* name, Isolate* isolate,
63 int* size, int repeat) { 63 int* size, int repeat) {
64 FILE* file = fopen(name, "rb"); 64 FILE* file = fopen(name, "rb");
65 *size = 0; 65 *size = 0;
66 if (file == NULL) return NULL; 66 if (file == NULL) return NULL;
67 67
68 fseek(file, 0, SEEK_END); 68 fseek(file, 0, SEEK_END);
69 int file_size = ftell(file); 69 int file_size = ftell(file);
70 rewind(file); 70 rewind(file);
71 71
72 byte* file_contents = new byte[file_size]; 72 *size = file_size * repeat;
73
74 byte* chars = new byte[*size];
73 for (int i = 0; i < file_size;) { 75 for (int i = 0; i < file_size;) {
74 int read = 76 int read = static_cast<int>(fread(&chars[i], 1, file_size - i, file));
75 static_cast<int>(fread(&file_contents[i], 1, file_size - i, file));
76 i += read; 77 i += read;
77 } 78 }
78 fclose(file); 79 fclose(file);
79 80
80 // If the file contains the UTF16 little endian magic bytes, skip them. 81 for (int i = file_size; i < *size; i++) {
81 // FIXME: what if we see big endian magic bytes? Do we do the right thing for 82 chars[i] = chars[i - file_size];
82 // big endian anyway?
83 byte* start = file_contents;
84 if (*start == 0xff && *(start + 1) == 0xfe) {
85 start += 2;
86 file_size -= 2;
87 } 83 }
88 84
89 *size = file_size * repeat;
90 byte* chars = new byte[*size];
91
92 for (int i = 0; i < *size; i++) {
93 chars[i] = start[i % file_size];
94 }
95
96 delete file_contents;
97
98 return chars; 85 return chars;
99 } 86 }
100 87
101 88
102 89
103 } 90 }
104 } 91 }
OLDNEW
« no previous file with comments | « no previous file | src/lexer/lexer_py.re » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698