github.com/altipla-consulting/ravendb-go-client@v0.1.3/query_field_util.go (about)

     1  package ravendb
     2  
     3  func queryFieldUtilEscapeIfNecessary(name string) string {
     4  	if stringIsEmpty(name) ||
     5  		IndexingFieldNameDocumentID == name ||
     6  		IndexingFieldNameReduceKeyHash == name ||
     7  		IndexingFieldNameReduceKeyValue == name ||
     8  		IndexingFieldsNameSpatialShare == name {
     9  		return name
    10  	}
    11  
    12  	escape := false
    13  	insideEscaped := false
    14  
    15  	for i, c := range name {
    16  
    17  		if c == '\'' || c == '"' {
    18  			insideEscaped = !insideEscaped
    19  			continue
    20  		}
    21  
    22  		if i == 0 {
    23  			if !isLetter(c) && c != '_' && c != '@' && !insideEscaped {
    24  				escape = true
    25  				break
    26  			}
    27  		} else {
    28  			if !isLetterOrDigit(c) && c != '_' && c != '-' && c != '@' && c != '.' && c != '[' && c != ']' && !insideEscaped {
    29  				escape = true
    30  				break
    31  			}
    32  		}
    33  	}
    34  
    35  	if escape || insideEscaped {
    36  		return "'" + name + "'"
    37  	}
    38  
    39  	return name
    40  }