File tree Expand file tree Collapse file tree 5 files changed +15
-6
lines changed Expand file tree Collapse file tree 5 files changed +15
-6
lines changed Original file line number Diff line number Diff line change 1515///|  
1616priv  struct  ParseContext  {
1717  mut  offset  : Int 
18-   input  : String 
18+   input  : StringView 
1919  end_offset  : Int 
2020}
2121
2222///|  
23- fn  ParseContext ::make (input  : String ) ->  ParseContext  {
23+ fn  ParseContext ::make (input  : StringView ) ->  ParseContext  {
2424  { offset : 0 , input , end_offset : input .length () }
2525}
2626
Original file line number Diff line number Diff line change @@ -149,7 +149,12 @@ fn ParseContext::lex_number_end(
149149  start  : Int ,
150150  end  : Int ,
151151) ->  (Double , String? ) {
152-   let  s  =  ctx .input.unsafe_substring (start ~, end ~)
152+   let  s  =  ctx .input
153+     .data ()
154+     .unsafe_substring (
155+       start = ctx .input.start_offset () +  start ,
156+       end = ctx .input.start_offset () +  end ,
157+     )
153158  if  !s .contains ("." ) &&  !s .contains ("e" ) &&  !s .contains ("E" ) {
154159    // If the string does not contain a decimal point or exponent, it is likely an integer 
155160    // We can try to parse it as an integer first 
Original file line number Diff line number Diff line change @@ -18,7 +18,11 @@ fn ParseContext::lex_string(ctx : ParseContext) -> String raise ParseError {
1818  let  mut  start  =  ctx .offset
1919  fn  flush (end  : Int ) {
2020    if  start  >  0  &&  end  >  start  {
21-       buf .write_substring (ctx .input, start , end  -  start )
21+       buf .write_substring (
22+         ctx .input.data (),
23+         ctx .input.start_offset () +  start ,
24+         end  -  start ,
25+       )
2226    }
2327  }
2428
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ pub fn valid(input : String) -> Bool {
2323}
2424
2525///|  
26- pub  fn  parse (input  : String ) ->  Json  raise  ParseError  {
26+ pub  fn  parse (input  : StringView ) ->  Json  raise  ParseError  {
2727  let  ctx  =  ParseContext ::make (input )
2828  let  val  =  ctx .parse_value ()
2929  ctx .lex_skip_whitespace ()
Original file line number Diff line number Diff line change 1313// limitations under the License. 
1414
1515///|  
16- fn  offset_to_position (input  : String , offset  : Int ) ->  Position  {
16+ fn  offset_to_position (input  : StringView , offset  : Int ) ->  Position  {
1717  let  mut  line  =  1 
1818  let  mut  column  =  0 
1919  for  i  in  0 ..< offset  {
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments