attr: impl valid without Parser
only State fsm is needed try to use Parser only when attributes need to be stored
This commit is contained in:
		
					parent
					
						
							
								242a64e3b4
							
						
					
				
			
			
				commit
				
					
						34e74ddc43
					
				
			
		
					 1 changed files with 10 additions and 8 deletions
				
			
		
							
								
								
									
										18
									
								
								src/attr.rs
									
										
									
									
									
								
							
							
						
						
									
										18
									
								
								src/attr.rs
									
										
									
									
									
								
							| 
						 | 
					@ -12,18 +12,20 @@ pub fn valid<I: Iterator<Item = char>>(chars: I) -> (usize, bool) {
 | 
				
			||||||
    use State::*;
 | 
					    use State::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let mut has_attr = false;
 | 
					    let mut has_attr = false;
 | 
				
			||||||
    let mut p = Parser::new();
 | 
					    let mut n = 0;
 | 
				
			||||||
 | 
					    let mut state = Start;
 | 
				
			||||||
    for c in chars {
 | 
					    for c in chars {
 | 
				
			||||||
        if p.step(c).is_some() {
 | 
					        n += 1;
 | 
				
			||||||
            has_attr = true;
 | 
					        state = state.step(c);
 | 
				
			||||||
        }
 | 
					        match state {
 | 
				
			||||||
        if matches!(p.state, Done | Invalid) {
 | 
					            Class | Identifier | Value | ValueQuoted => has_attr = true,
 | 
				
			||||||
            break;
 | 
					            Done | Invalid => break,
 | 
				
			||||||
 | 
					            _ => {}
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if matches!(p.state, Done) {
 | 
					    if matches!(state, Done) {
 | 
				
			||||||
        (p.pos, has_attr)
 | 
					        (n, has_attr)
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        (0, false)
 | 
					        (0, false)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue