| 1 | // Copyright 2021 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 | package generator |
| 6 | |
| 7 | import ( |
| 8 | "bytes" |
| 9 | ) |
| 10 | |
| 11 | // stringparm describes a parameter of string type; it implements the |
| 12 | // "parm" interface |
| 13 | type stringparm struct { |
| 14 | tag string |
| 15 | isBlank |
| 16 | addrTakenHow |
| 17 | isGenValFunc |
| 18 | skipCompare |
| 19 | } |
| 20 | |
| 21 | func (p stringparm) Declare(b *bytes.Buffer, prefix string, suffix string, caller bool) { |
| 22 | b.WriteString(prefix + " string" + suffix) |
| 23 | } |
| 24 | |
| 25 | func (p stringparm) GenElemRef(elidx int, path string) (string, parm) { |
| 26 | return path, &p |
| 27 | } |
| 28 | |
| 29 | var letters = []rune("�꿦3f6ꂅ8ˋ<(z̽|ϣᇊq筁{ЂƜĽ") |
| 30 | |
| 31 | func (p stringparm) GenValue(s *genstate, f *funcdef, value int, caller bool) (string, int) { |
| 32 | ns := len(letters) - 9 |
| 33 | nel := int(s.wr.Intn(8)) |
| 34 | st := int(s.wr.Intn(int64(ns))) |
| 35 | en := st + nel |
| 36 | if en > ns { |
| 37 | en = ns |
| 38 | } |
| 39 | return "\"" + string(letters[st:en]) + "\"", value + 1 |
| 40 | } |
| 41 | |
| 42 | func (p stringparm) IsControl() bool { |
| 43 | return false |
| 44 | } |
| 45 | |
| 46 | func (p stringparm) NumElements() int { |
| 47 | return 1 |
| 48 | } |
| 49 | |
| 50 | func (p stringparm) String() string { |
| 51 | return "string" |
| 52 | } |
| 53 | |
| 54 | func (p stringparm) TypeName() string { |
| 55 | return "string" |
| 56 | } |
| 57 | |
| 58 | func (p stringparm) QualName() string { |
| 59 | return "string" |
| 60 | } |
| 61 | |
| 62 | func (p stringparm) HasPointer() bool { |
| 63 | return false |
| 64 | } |
| 65 |
Members