blob: 5d1e6fe8ffe495b4a8fd1cb09282d7730a930095 [file] [log] [blame]
Damien Neil8012b442019-01-18 09:32:24 -08001// 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
7package fileinit
8
Damien Neile89e6242019-05-13 23:55:40 -07009import pref "google.golang.org/protobuf/reflect/protoreflect"
Damien Neil8012b442019-01-18 09:32:24 -080010
11func getNameBuilder() *nameBuilder { return nil }
12func putNameBuilder(*nameBuilder) {}
13
14type nameBuilder struct{}
15
16// AppendFullName is equivalent to protoreflect.FullName.Append.
17func (*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.
26func (*nameBuilder) MakeString(b []byte) string {
27 return string(b)
28}
29
30// MakeJSONName creates a JSON name from the protobuf short name.
31func (*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}