Damien Neil | 8012b44 | 2019-01-18 09:32:24 -0800 | [diff] [blame] | 1 | // Copyright 2018 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 | // +build purego appengine |
| 6 | |
| 7 | package fileinit |
| 8 | |
Damien Neil | e89e624 | 2019-05-13 23:55:40 -0700 | [diff] [blame] | 9 | import pref "google.golang.org/protobuf/reflect/protoreflect" |
Damien Neil | 8012b44 | 2019-01-18 09:32:24 -0800 | [diff] [blame] | 10 | |
| 11 | func getNameBuilder() *nameBuilder { return nil } |
| 12 | func putNameBuilder(*nameBuilder) {} |
| 13 | |
| 14 | type nameBuilder struct{} |
| 15 | |
| 16 | // AppendFullName is equivalent to protoreflect.FullName.Append. |
| 17 | func (*nameBuilder) AppendFullName(prefix pref.FullName, name []byte) fullName { |
| 18 | return fullName{ |
| 19 | shortLen: len(name), |
| 20 | fullName: prefix.Append(pref.Name(name)), |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | // MakeString is equivalent to string(b), but optimized for large batches |
| 25 | // with a shared lifetime. |
| 26 | func (*nameBuilder) MakeString(b []byte) string { |
| 27 | return string(b) |
| 28 | } |
| 29 | |
| 30 | // MakeJSONName creates a JSON name from the protobuf short name. |
| 31 | func (*nameBuilder) MakeJSONName(s pref.Name) string { |
| 32 | var b []byte |
| 33 | var wasUnderscore bool |
| 34 | for i := 0; i < len(s); i++ { // proto identifiers are always ASCII |
| 35 | c := s[i] |
| 36 | if c != '_' { |
| 37 | isLower := 'a' <= c && c <= 'z' |
| 38 | if wasUnderscore && isLower { |
| 39 | c -= 'a' - 'A' |
| 40 | } |
| 41 | b = append(b, c) |
| 42 | } |
| 43 | wasUnderscore = c == '_' |
| 44 | } |
| 45 | return string(b) |
| 46 | } |