Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
42d63847
Commit
42d63847
authored
Dec 06, 2009
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rewrite translate_newlines for clarity
parent
4f38317d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
12 deletions
+11
-12
Parser/tokenizer.c
Parser/tokenizer.c
+11
-12
No files found.
Parser/tokenizer.c
View file @
42d63847
...
...
@@ -591,20 +591,20 @@ translate_into_utf8(const char* str, const char* enc) {
static
char
*
translate_newlines
(
const
char
*
s
,
int
exec_input
,
struct
tok_state
*
tok
)
{
int
skip_next_lf
=
0
,
length
=
strlen
(
s
)
,
final_length
;
int
skip_next_lf
=
0
,
needed_length
=
strlen
(
s
)
+
2
,
final_length
;
char
*
buf
,
*
current
;
char
c
;
buf
=
PyMem_MALLOC
(
length
+
2
);
char
c
=
'\0'
;
buf
=
PyMem_MALLOC
(
needed_length
);
if
(
buf
==
NULL
)
{
tok
->
done
=
E_NOMEM
;
return
NULL
;
}
for
(
current
=
buf
;
(
c
=
*
s
++
);)
{
for
(
current
=
buf
;
*
s
;
s
++
,
current
++
)
{
c
=
*
s
;
if
(
skip_next_lf
)
{
skip_next_lf
=
0
;
if
(
c
==
'\n'
)
{
c
=
*
s
;
s
++
;
c
=
*++
s
;
if
(
!
c
)
break
;
}
...
...
@@ -614,19 +614,18 @@ translate_newlines(const char *s, int exec_input, struct tok_state *tok) {
c
=
'\n'
;
}
*
current
=
c
;
current
++
;
}
/* If this is exec input, add a newline to the end of the
file
if
/* If this is exec input, add a newline to the end of the
string
if
there isn't one already. */
if
(
exec_input
&&
*
current
!=
'\n'
)
{
if
(
exec_input
&&
c
!=
'\n'
)
{
*
current
=
'\n'
;
current
++
;
}
*
current
=
'\0'
;
final_length
=
current
-
buf
;
if
(
final_length
<
length
&&
final_length
)
final_length
=
current
-
buf
+
1
;
if
(
final_length
<
needed_
length
&&
final_length
)
/* should never fail */
buf
=
PyMem_REALLOC
(
buf
,
final_length
+
1
);
buf
=
PyMem_REALLOC
(
buf
,
final_length
);
return
buf
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment