Changed behavior of SOS and EOS assertions depending on whether multiline mode is enabled or not
This commit is contained in:
		
							
								
								
									
										8
									
								
								nfa.go
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								nfa.go
									
									
									
									
									
								
							@@ -108,11 +108,15 @@ func (s State) checkAssertion(str []rune, idx int) bool {
 | 
			
		||||
		return true
 | 
			
		||||
	}
 | 
			
		||||
	if s.assert == SOS {
 | 
			
		||||
		return idx == 0
 | 
			
		||||
		// Single-line mode: Beginning of string
 | 
			
		||||
		// Multi-line mode: Previous character was newline
 | 
			
		||||
		return idx == 0 || (multilineMode && (idx > 0 && str[idx-1] == '\n'))
 | 
			
		||||
	}
 | 
			
		||||
	if s.assert == EOS {
 | 
			
		||||
		// Single-line mode: End of string
 | 
			
		||||
		// Multi-line mode: current character is newline
 | 
			
		||||
		// Index is at the end of the string, or it points to the last character which is a newline
 | 
			
		||||
		return idx == len(str) || (idx == len(str)-1 && str[len(str)-1] == '\n')
 | 
			
		||||
		return idx == len(str) || (multilineMode && str[idx] == '\n')
 | 
			
		||||
	}
 | 
			
		||||
	if s.assert == WBOUND {
 | 
			
		||||
		return isWordBoundary(str, idx)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user