Go greedy
This commit is contained in:
		
							parent
							
								
									e33501d6a5
								
							
						
					
					
						commit
						0d2df2c6e5
					
				@ -12,9 +12,10 @@ type (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Context building block
 | 
						// Context building block
 | 
				
			||||||
	expectation struct {
 | 
						expectation struct {
 | 
				
			||||||
		typ   expectationType
 | 
							typ    expectationType
 | 
				
			||||||
		key   string // Object key
 | 
							greedy bool
 | 
				
			||||||
		index int64  // Array index
 | 
							key    string // Object key
 | 
				
			||||||
 | 
							index  int64  // Array index
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Type of expectation: object or array
 | 
						// Type of expectation: object or array
 | 
				
			||||||
@ -37,9 +38,12 @@ func (c *context) compare(c2 *context) bool {
 | 
				
			|||||||
		if exp.typ != exp2.typ {
 | 
							if exp.typ != exp2.typ {
 | 
				
			||||||
			return false
 | 
								return false
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							if exp.greedy || exp2.greedy {
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		switch exp.typ {
 | 
							switch exp.typ {
 | 
				
			||||||
		case array:
 | 
							case array:
 | 
				
			||||||
			if exp.index != -1 && exp2.index != -1 && exp.index != exp2.index {
 | 
								if exp.index != exp2.index {
 | 
				
			||||||
				return false
 | 
									return false
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		case object:
 | 
							case object:
 | 
				
			||||||
@ -92,7 +96,7 @@ func parseSelector(sel string) []expectation {
 | 
				
			|||||||
			c.typ = array
 | 
								c.typ = array
 | 
				
			||||||
			part = part[1 : len(part)-1]
 | 
								part = part[1 : len(part)-1]
 | 
				
			||||||
			if part == "*" {
 | 
								if part == "*" {
 | 
				
			||||||
				c.index = -1
 | 
									c.greedy = true
 | 
				
			||||||
			} else if i, err := strconv.ParseInt(part, 10, 64); err == nil {
 | 
								} else if i, err := strconv.ParseInt(part, 10, 64); err == nil {
 | 
				
			||||||
				c.index = i
 | 
									c.index = i
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
@ -100,7 +104,11 @@ func parseSelector(sel string) []expectation {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			c.typ = object
 | 
								c.typ = object
 | 
				
			||||||
			c.key = part
 | 
								if part == "*" {
 | 
				
			||||||
 | 
									c.greedy = true
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									c.key = part
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		exps = append(exps, c)
 | 
							exps = append(exps, c)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user