@@ -3,9 +3,6 @@ use memchr::memchr;
3
3
use std:: borrow:: Cow ;
4
4
use std:: time:: Duration ;
5
5
6
- const SEPARATOR : u8 = 0x1E ;
7
- const ARG_TAG : u8 = 0x11 ;
8
-
9
6
#[ derive( Clone , Eq , PartialEq , Hash , Debug ) ]
10
7
pub struct Event < ' a > {
11
8
pub event_kind : Cow < ' a , str > ,
@@ -78,6 +75,8 @@ struct Parser<'a> {
78
75
pos : usize ,
79
76
}
80
77
78
+ const SEPARATOR_BYTE : u8 = measureme:: event_id:: SEPARATOR_BYTE . as_bytes ( ) [ 0 ] ;
79
+
81
80
impl < ' a > Parser < ' a > {
82
81
fn new ( full_text : Cow < ' a , [ u8 ] > ) -> Parser < ' a > {
83
82
Parser { full_text, pos : 0 }
@@ -95,7 +94,7 @@ impl<'a> Parser<'a> {
95
94
fn parse_separator_terminated_text ( & mut self ) -> Result < Cow < ' a , str > , String > {
96
95
let start = self . pos ;
97
96
98
- let end = memchr ( SEPARATOR , & self . full_text [ start..] )
97
+ let end = memchr ( SEPARATOR_BYTE , & self . full_text [ start..] )
99
98
. map ( |pos| pos + start)
100
99
. unwrap_or ( self . full_text . len ( ) ) ;
101
100
@@ -105,27 +104,23 @@ impl<'a> Parser<'a> {
105
104
106
105
self . pos = end;
107
106
107
+ if self . full_text [ start .. end] . iter ( ) . any ( u8:: is_ascii_control) {
108
+ return self . err ( "Found ASCII control character in <text>" ) ;
109
+ }
110
+
108
111
Ok ( self . substring ( start, end) )
109
112
}
110
113
111
114
fn parse_arg ( & mut self ) -> Result < Cow < ' a , str > , String > {
112
- if self . peek ( ) != SEPARATOR {
115
+ if self . peek ( ) != SEPARATOR_BYTE {
113
116
return self . err ( & format ! (
114
117
"Expected '\\ x{:x}' char at start of <argument>" ,
115
- SEPARATOR
118
+ SEPARATOR_BYTE
116
119
) ) ;
117
120
}
118
121
119
122
self . pos += 1 ;
120
- let tag = self . peek ( ) ;
121
-
122
- match tag {
123
- ARG_TAG => {
124
- self . pos += 1 ;
125
- self . parse_separator_terminated_text ( )
126
- }
127
- other => self . err ( & format ! ( "Unexpected argument tag '{:x}'" , other) ) ,
128
- }
123
+ self . parse_separator_terminated_text ( )
129
124
}
130
125
131
126
fn err < T > ( & self , message : & str ) -> Result < T , String > {
@@ -163,7 +158,7 @@ mod tests {
163
158
164
159
#[ test]
165
160
fn parse_event_id_one_arg ( ) {
166
- let ( label, args) = Event :: parse_event_id ( Cow :: from ( "foo\x1e \x11 my_arg " ) ) ;
161
+ let ( label, args) = Event :: parse_event_id ( Cow :: from ( "foo\x1e my_arg " ) ) ;
167
162
168
163
assert_eq ! ( label, "foo" ) ;
169
164
assert_eq ! ( args, vec![ Cow :: from( "my_arg" ) ] ) ;
@@ -172,7 +167,7 @@ mod tests {
172
167
#[ test]
173
168
fn parse_event_id_n_args ( ) {
174
169
let ( label, args) =
175
- Event :: parse_event_id ( Cow :: from ( "foo\x1e \x11 arg1 \x1e \x11 arg2 \x1e \x11 arg3 " ) ) ;
170
+ Event :: parse_event_id ( Cow :: from ( "foo\x1e arg1 \x1e arg2 \x1e arg3 " ) ) ;
176
171
177
172
assert_eq ! ( label, "foo" ) ;
178
173
assert_eq ! (
0 commit comments