git.lukeshu.com/go/lowmemjson@v0.3.9-0.20230723050957-72f6d13f6fb2/internal/jsonstruct/borrowed_misc.go (about)

     1  // Copyright 2010 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  //
     5  // SPDX-License-Identifier: BSD-3-Clause
     6  
     7  package jsonstruct
     8  
     9  import (
    10  	"strings"
    11  	"unicode"
    12  )
    13  
    14  // isValidTag is borrowed from encode.go.
    15  func isValidTag(s string) bool {
    16  	if s == "" {
    17  		return false
    18  	}
    19  	for _, c := range s {
    20  		switch {
    21  		case strings.ContainsRune("!#$%&()*+-./:;<=>?@[]^_{|}~ ", c):
    22  			// Backslash and quote chars are reserved, but
    23  			// otherwise any punctuation chars are allowed
    24  			// in a tag name.
    25  		case !unicode.IsLetter(c) && !unicode.IsDigit(c):
    26  			return false
    27  		}
    28  	}
    29  	return true
    30  }