// isJSONPointer tells whether given string is a valid JSON Pointer.
//
// Note: It returns false for JSON Pointer URI fragments.
436595
func isJSONPointer(v interface{}) bool {
	s, ok := v.(string)
	if !ok {
		return false
	}
	if s != "" && !strings.HasPrefix(s, "/") {
		return false
	}
	for _, item := range strings.Split(s, "/") {
		for i := 0; i < len(item); i++ {
			if item[i] == '~' {
				if i == len(item)-1 {
					return false
				}
				switch item[i+1] {
				case '~', '0', '1':
					// valid
				default:
					return false
				}
			}
		}
	}
	return true
}
738842
func validHeaderAcceptJSON(header http.Header) bool {
	if v, found := header["Accept"]; found {
		for _, v := range v {
			if v == "application/json" || v == "*/*" || v == "*/json" || v == "application/*" {
				return true
			}
		}
		return false
	}
	return true
}
1250489
func IsStrInArray(arr []string, str string) bool {
	for _, s := range arr {
		if str == s {
			return true
		}
	}
	return false
}
910191
func isSlice(t reflect.Type) bool {
	if t.Kind() == reflect.Ptr {
		t = t.Elem()
	}
	return t.Kind() == reflect.Slice
}
480955
func isValidEntrypoint(fs fs.FileSystem, path string) bool {
	stat, err := fs.Stat(path)
	if err != nil {
		return false
	}
	found := false
	for _, pattern := range validEntrypoints {
		if pattern.MatchString(stat.Name()) {
			found = true
			break
		}
	}
	if !found {
		return false
	}
	mode := stat.Mode()
	return mode&0111 != 0
}
630071
func (c *Context) JSONParser() (*simplejson.Json, error) {
	res := c.Response()
	defer res.Body.Close()
	return simplejson.NewFromReader(res.Body)
}
1238854
func (p *JsonPointer) implementation(i *implStruct) {

	kind := reflect.Invalid

	// Full document when empty
	if len(p.referenceTokens) == 0 {
		i.getOutNode = i.inDocument
		i.outError = nil
		i.getOutKind = kind
		i.outError = nil
		return
	}

	node := i.inDocument

	previousNodes := make([]interface{}, len(p.referenceTokens))
	previousTokens := make([]string, len(p.referenceTokens))

	for ti, token := range p.referenceTokens {

		isLastToken := ti == len(p.referenceTokens)-1
		previousNodes[ti] = node
		previousTokens[ti] = token

		switch v := node.(type) {

		case map[string]interface{}:
			decodedToken := decodeReferenceToken(token)
			if _, ok := v[decodedToken]; ok {
				node = v[decodedToken]
				if isLastToken && i.mode == "SET" {
					v[decodedToken] = i.setInValue
				} else if isLastToken && i.mode =="DEL" {
					delete(v,decodedToken)
				}
			} else if (isLastToken && i.mode == "SET") {
				v[decodedToken] = i.setInValue
			} else {
				i.outError = fmt.Errorf("Object has no key '%s'", decodedToken)
				i.getOutKind = reflect.Map
				i.getOutNode = nil
				return
			}

		case []interface{}:
			tokenIndex, err := strconv.Atoi(token)
			if err != nil {
				i.outError = fmt.Errorf("Invalid array index '%s'", token)
				i.getOutKind = reflect.Slice
				i.getOutNode = nil
				return
			}
			if tokenIndex < 0 || tokenIndex >= len(v) {
				i.outError = fmt.Errorf("Out of bound array[0,%d] index '%d'", len(v), tokenIndex)
				i.getOutKind = reflect.Slice
				i.getOutNode = nil
				return
			}

			node = v[tokenIndex]
			if isLastToken && i.mode == "SET" {
				v[tokenIndex] = i.setInValue
			}  else if isLastToken && i.mode =="DEL" {
				v[tokenIndex] = v[len(v)-1]
				v[len(v)-1] = nil
				v = v[:len(v)-1]
				previousNodes[ti-1].(map[string]interface{})[previousTokens[ti-1]] = v
			}

		default:
			i.outError = fmt.Errorf("Invalid token reference '%s'", token)
			i.getOutKind = reflect.ValueOf(node).Kind()
			i.getOutNode = nil
			return
		}

	}

	i.getOutNode = node
	i.getOutKind = reflect.ValueOf(node).Kind()
	i.outError = nil
}
757714
func isValidStructPointer(v reflect.Value) bool {
	return v.Type().Kind() == reflect.Ptr && v.Elem().IsValid() && v.Elem().Type().Kind() == reflect.Struct
}
1349059
func (v JSONDatapointV2) MarshalJSON() ([]byte, error) {
	w := jwriter.Writer{}
	easyjson3b0ebf6aEncodeGithubComSignalfxGatewayProtocolSignalfxFormat1(&w, v)
	return w.Buffer.BuildBytes(), w.Error
}
458096
func IsJSONString(s string) bool {
	s = strings.TrimSpace(s)
	return strings.HasPrefix(s, "{") && strings.HasSuffix(s, "}")
}
1042599
func IsMap(val Value) bool {
	r := reflect.Indirect(reflect.ValueOf(val))
	return r.Kind() == reflect.Map
}
1070411
func IsURL(u string) bool {
	var parsedURL *url.URL
	var err error

	parsedURL, err = url.ParseRequestURI(u)
	if err == nil {
		if parsedURL != nil && parsedURL.Host != "" {
			return true
		}
	}
	return false
}
69301
func encodeDBPointer(buf *bytes.Buffer, path, name string,
	val DBPointer) error {

	if len(val.ObjectId) != 12 {
		return fmt.Errorf("%v, DBPointer must be 12 bytes.", path)
	}

	// type
	if err := buf.WriteByte(_DBPOINTER); err != nil {
		return err
	}

	// name
	if err := writeCstring(buf, name); err != nil {
		return err
	}

	// Name
	if err := writeString(buf, val.Name); err != nil {
		return err
	}

	// ObjectId
	if _, err := buf.Write(val.ObjectId); err != nil {
		return err
	}

	return nil
}
857922
func IsKanji(s string) bool {
	return isChar(s, []*unicode.RangeTable{unicode.Ideographic})
}
1067050
func IsExactlyDoublePointer(target interface{}) bool {
	typ := reflect.ValueOf(target).Type()
	kind := typ.Kind()
	if kind != reflect.Ptr {
		return false
	}
	typ2 := typ.Elem()
	kind2 := typ2.Kind()
	if kind2 != reflect.Ptr {
		return false
	}
	if typ2.Elem().Kind() == reflect.Ptr {
		return false // triple level pointer, not double.
	}
	return true
}
907606
func CheckForJSON(r *http.Request) error {
	ct := r.Header.Get("Content-Type")

	// No Content-Type header is ok as long as there's no Body
	if ct == "" {
		if r.Body == nil || r.ContentLength == 0 {
			return nil
		}
	}

	// Otherwise it better be json
	if matchesContentType(ct, "application/json") {
		return nil
	}
	return errdefs.InvalidParameter(errors.Errorf("Content-Type specified (%s) must be 'application/json'", ct))
}
954124
func (p *Params) BindJSON(dest interface{}) error {
	value := reflect.ValueOf(dest)
	if value.Kind() != reflect.Ptr {
		paramsLogger.Warn("BindJSON: Not a pointer")
		return errors.New("BindJSON not a pointer")
	}
	if err := json.Unmarshal(p.JSON, dest); err != nil {
		paramsLogger.Warn("BindJSON: Unable to unmarshal request:", "error", err)
		return err
	}
	return nil
}