Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
d4632744
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d4632744
编写于
6月 09, 2019
作者:
I
Igor Matuszewski
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Translate CRLF -> LF in raw (byte) strings
上级
49d62e8d
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
18 addition
and
34 deletion
+18
-34
src/libsyntax/parse/lexer/mod.rs
src/libsyntax/parse/lexer/mod.rs
+2
-2
src/libsyntax/parse/literal.rs
src/libsyntax/parse/literal.rs
+2
-2
src/libsyntax/parse/unescape.rs
src/libsyntax/parse/unescape.rs
+14
-30
未找到文件。
src/libsyntax/parse/lexer/mod.rs
浏览文件 @
d4632744
...
...
@@ -1346,7 +1346,7 @@ fn validate_str_escape(&self, start_with_quote: BytePos) {
fn
validate_raw_str_escape
(
&
self
,
content_start
:
BytePos
,
content_end
:
BytePos
)
{
self
.with_str_from_to
(
content_start
,
content_end
,
|
lit
:
&
str
|
{
unescape
::
unescape_raw_str
(
lit
,
&
mut
|
range
,
c
|
{
unescape
::
unescape_raw_str
(
lit
,
unescape
::
Mode
::
Str
,
&
mut
|
range
,
c
|
{
if
let
Err
(
err
)
=
c
{
emit_unescape_error
(
&
self
.sess.span_diagnostic
,
...
...
@@ -1363,7 +1363,7 @@ fn validate_raw_str_escape(&self, content_start: BytePos, content_end: BytePos)
fn
validate_raw_byte_str_escape
(
&
self
,
content_start
:
BytePos
,
content_end
:
BytePos
)
{
self
.with_str_from_to
(
content_start
,
content_end
,
|
lit
:
&
str
|
{
unescape
::
unescape_raw_
byte_str
(
lit
,
&
mut
|
range
,
c
|
{
unescape
::
unescape_raw_
str
(
lit
,
unescape
::
Mode
::
ByteStr
,
&
mut
|
range
,
c
|
{
if
let
Err
(
err
)
=
c
{
emit_unescape_error
(
&
self
.sess.span_diagnostic
,
...
...
src/libsyntax/parse/literal.rs
浏览文件 @
d4632744
...
...
@@ -4,7 +4,7 @@
use
crate
::
parse
::
parser
::
Parser
;
use
crate
::
parse
::
PResult
;
use
crate
::
parse
::
token
::{
self
,
Token
,
TokenKind
};
use
crate
::
parse
::
unescape
::{
unescape_str
,
unescape_byte_str
,
unescape_raw_str
};
use
crate
::
parse
::
unescape
::{
self
,
unescape_str
,
unescape_byte_str
,
unescape_raw_str
};
use
crate
::
parse
::
unescape
::{
unescape_char
,
unescape_byte
};
use
crate
::
print
::
pprust
;
use
crate
::
symbol
::{
kw
,
sym
,
Symbol
};
...
...
@@ -144,7 +144,7 @@ fn from_lit_token(lit: token::Lit) -> Result<LitKind, LitError> {
let
symbol
=
if
s
.contains
(
'\r'
)
{
let
mut
buf
=
String
::
with_capacity
(
s
.len
());
let
mut
error
=
Ok
(());
unescape_raw_str
(
&
s
,
&
mut
|
_
,
unescaped_char
|
{
unescape_raw_str
(
&
s
,
unescape
::
Mode
::
Str
,
&
mut
|
_
,
unescaped_char
|
{
match
unescaped_char
{
Ok
(
c
)
=>
buf
.push
(
c
),
Err
(
_
)
=>
error
=
Err
(
LitError
::
LexerError
),
...
...
src/libsyntax/parse/unescape.rs
浏览文件 @
d4632744
...
...
@@ -71,7 +71,7 @@ pub(crate) fn unescape_byte_str<F>(literal_text: &str, callback: &mut F)
/// sequence of characters or errors.
/// NOTE: Raw strings do not perform any explicit character escaping, here we
/// only translate CRLF to LF and produce errors on bare CR.
pub
(
crate
)
fn
unescape_raw_str
<
F
>
(
literal_text
:
&
str
,
callback
:
&
mut
F
)
pub
(
crate
)
fn
unescape_raw_str
<
F
>
(
literal_text
:
&
str
,
mode
:
Mode
,
callback
:
&
mut
F
)
where
F
:
FnMut
(
Range
<
usize
>
,
Result
<
char
,
EscapeError
>
),
{
...
...
@@ -79,36 +79,20 @@ pub(crate) fn unescape_raw_str<F>(literal_text: &str, callback: &mut F)
let
mut
chars
=
literal_text
.chars
()
.peekable
();
while
let
Some
(
curr
)
=
chars
.next
()
{
let
result
=
match
(
curr
,
chars
.peek
())
{
(
'\r'
,
Some
(
'\n'
))
=>
Ok
(
curr
),
(
'\r'
,
_
)
=>
Err
(
EscapeError
::
BareCarriageReturn
),
_
=>
Ok
(
curr
),
};
callback
(
byte_offset
..
(
byte_offset
+
curr
.len_utf8
()),
result
);
byte_offset
+=
curr
.len_utf8
();
}
}
/// Takes a contents of a string literal (without quotes) and produces a
/// sequence of characters or errors.
/// NOTE: Raw strings do not perform any explicit character escaping, here we
/// only translate CRLF to LF and produce errors on bare CR.
pub
(
crate
)
fn
unescape_raw_byte_str
<
F
>
(
literal_text
:
&
str
,
callback
:
&
mut
F
)
where
F
:
FnMut
(
Range
<
usize
>
,
Result
<
char
,
EscapeError
>
),
{
let
mut
byte_offset
:
usize
=
0
;
let
mut
chars
=
literal_text
.chars
()
.peekable
();
while
let
Some
(
curr
)
=
chars
.next
()
{
let
result
=
match
(
curr
,
chars
.peek
())
{
(
'\r'
,
Some
(
'\n'
))
=>
Ok
(
curr
),
(
'\r'
,
_
)
=>
Err
(
EscapeError
::
BareCarriageReturn
),
(
c
,
_
)
if
c
>
'\x7F'
=>
Err
(
EscapeError
::
NonAsciiCharInByteString
),
_
=>
Ok
(
curr
),
let
(
result
,
scanned
)
=
match
(
curr
,
chars
.peek
())
{
(
'\r'
,
Some
(
'\n'
))
=>
{
chars
.next
();
(
Ok
(
'\n'
),
[
Some
(
'\r'
),
Some
(
'\n'
)])
},
(
'\r'
,
_
)
=>
(
Err
(
EscapeError
::
BareCarriageReturn
),
[
Some
(
'\r'
),
None
]),
(
c
,
_
)
if
mode
.is_bytes
()
&&
c
>
'\x7F'
=>
(
Err
(
EscapeError
::
NonAsciiCharInByteString
),
[
Some
(
c
),
None
]),
(
c
,
_
)
=>
(
Ok
(
c
),
[
Some
(
c
),
None
]),
};
callback
(
byte_offset
..
(
byte_offset
+
curr
.len_utf8
()),
result
);
byte_offset
+=
curr
.len_utf8
();
let
len_utf8
:
usize
=
scanned
.iter
()
.filter_map
(|
&
x
|
x
)
.map
(
char
::
len_utf8
)
.sum
();
callback
(
byte_offset
..
(
byte_offset
+
len_utf8
),
result
);
byte_offset
+=
len_utf8
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录