MCPcopy Create free account
hub / github.com/github/gh-aw / findFirstAdditionalProperty

Function findFirstAdditionalProperty

pkg/parser/json_path_locator.go:268–299  ·  view source on GitHub ↗

findFirstAdditionalProperty finds the first occurrence of any of the given property names in YAML

(yamlContent string, propertyNames []string)

Source from the content-addressed store, hash-verified

266
267// findFirstAdditionalProperty finds the first occurrence of any of the given property names in YAML
268func findFirstAdditionalProperty(yamlContent string, propertyNames []string) JSONPathLocation {
269 lines := strings.Split(yamlContent, "\n")
270
271 for lineNum, line := range lines {
272 trimmedLine := strings.TrimSpace(line)
273
274 // Skip empty lines and comments
275 if trimmedLine == "" || strings.HasPrefix(trimmedLine, "#") {
276 continue
277 }
278
279 // Check if this line contains any of the additional properties
280 for _, propName := range propertyNames {
281 // Look for "propName:" pattern at the start of the trimmed line
282 keyPattern := regexp.MustCompile(`^` + regexp.QuoteMeta(propName) + `\s*:`)
283 if keyPattern.MatchString(trimmedLine) {
284 // Found the property - return position of the property name
285 propIndex := strings.Index(line, propName)
286 if propIndex != -1 {
287 return JSONPathLocation{
288 Line: lineNum + 1, // 1-based line numbers
289 Column: propIndex + 1, // 1-based column numbers
290 Found: true,
291 }
292 }
293 }
294 }
295 }
296
297 // If we can't find any of the properties, return the default location
298 return JSONPathLocation{Line: 1, Column: 1, Found: false}
299}
300
301// findAdditionalPropertyInNestedContext finds additional properties within a specific nested JSON path context
302// It extracts the sub-YAML content for the JSON path and searches within it for better efficiency

Calls 1

MustCompileMethod · 0.80

Tested by 1