<commit_before>package model

import (
	"bytes"
	"go/doc"
	"regexp"
	"sort"
	"strings"

	"code.google.com/p/go.net/html"
	"github.com/aarzilli/sandblast"
)

func locationTraits(location string, shape *Shape) string {
	if shape == nil {
		return ""
	}

	var list []string
	for name, member := range shape.Members() {
		if member.Location == location {
			list = append(list, "\""+name+"\"")
		}
	}
	sort.Strings(list)
	return strings.Join(list, ",")
}

func requiredTraits(shape *Shape) string {
	if shape == nil {
		return ""
	}

	var list []string
	for name, member := range shape.Members() {
		if member.Required {
			list = append(list, "\""+name+"\"")
		}
	}
	sort.Strings(list)
	return strings.Join(list, ",")
}

func hasRequiredTrait(shape *Shape) bool {
	if shape != nil {
		for _, member := range shape.Members() {
			if member.Required {
				return true
			}
		}
	}
	return false
}

func godoc(member, content string) string {
	undocumented := "// " + exportable(member) + " is undocumented.\n"

	node, err := html.Parse(strings.NewReader(content))
	if err != nil {
		return undocumented
	}

	_, v, err := sandblast.Extract(node)
	if err != nil {
		return undocumented
	}

	v = strings.TrimSpace(v)
	if v == "" {
		return undocumented
	}

	if member != "" {
		v = exportable(member) + " " + strings.ToLower(v[0:1]) + v[1:]
	}

	out := bytes.NewBuffer(nil)
	doc.ToText(out, v, "// ", "", 72)
	return out.String()
}

func protocolPackage(protocol string) string {
	switch {
	case protocol == "json":
		return "jsonrpc"
	default:
		return strings.Replace(protocol, "-", "", -1)
	}
}

func structName(name string) string {
	str := exportable(name)
	str = regexp.MustCompile(`Request$`).ReplaceAllString(str, "Input")
	str = regexp.MustCompile(`Response$`).ReplaceAllString(str, "Output")
	return str
}

func exportable(name string) string {
	// make sure the symbol is exportable
	name = strings.ToUpper(name[0:1]) + name[1:]

	// fix common AWS<->Go bugaboos
	for regexp, repl := range replacements {
		name = regexp.ReplaceAllString(name, repl)
	}
	return name<commit_msg>Convert *Result shape names to *Output<commit_after>package model

import (
	"bytes"
	"go/doc"
	"regexp"
	"sort"
	"strings"

	"code.google.com/p/go.net/html"
	"github.com/aarzilli/sandblast"
)

func locationTraits(location string, shape *Shape) string {
	if shape == nil {
		return ""
	}

	var list []string
	for name, member := range shape.Members() {
		if member.Location == location {
			list = append(list, "\""+name+"\"")
		}
	}
	sort.Strings(list)
	return strings.Join(list, ",")
}

func requiredTraits(shape *Shape) string {
	if shape == nil {
		return ""
	}

	var list []string
	for name, member := range shape.Members() {
		if member.Required {
			list = append(list, "\""+name+"\"")
		}
	}
	sort.Strings(list)
	return strings.Join(list, ",")
}

func hasRequiredTrait(shape *Shape) bool {
	if shape != nil {
		for _, member := range shape.Members() {
			if member.Required {
				return true
			}
		}
	}
	return false
}

func godoc(member, content string) string {
	undocumented := "// " + exportable(member) + " is undocumented.\n"

	node, err := html.Parse(strings.NewReader(content))
	if err != nil {
		return undocumented
	}

	_, v, err := sandblast.Extract(node)
	if err != nil {
		return undocumented
	}

	v = strings.TrimSpace(v)
	if v == "" {
		return undocumented
	}

	if member != "" {
		v = exportable(member) + " " + strings.ToLower(v[0:1]) + v[1:]
	}

	out := bytes.NewBuffer(nil)
	doc.ToText(out, v, "// ", "", 72)
	return out.String()
}

func protocolPackage(protocol string) string {
	switch {
	case protocol == "json":
		return "jsonrpc"
	default:
		return strings.Replace(protocol, "-", "", -1)
	}
}

func structName(name string) string {
	str := exportable(name)
	str = regexp.MustCompile(`Request$`).ReplaceAllString(str, "Input")
	str = regexp.MustCompile(`Response$`).ReplaceAllString(str, "Output")
	str = regexp.MustCompile(`Result$`).ReplaceAllString(str, "Output")
	return str
}

func exportable(name string) string {
	// make sure the symbol is exportable
	name = strings.ToUpper(name[0:1]) + name[1:]

	// fix common AWS<->Go bugaboos
	for regexp, repl := range replacements {
		name = regexp.ReplaceAllString(name, repl)
	}
	return name
{'fraction_non_alphanumeric': 0.16157102539981186, 'fraction_numerical': 0.0042333019755409216, 'mean_word_length': 3.7519553072625698, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7439244', 'n_tokens_mistral': 1618, 'n_tokens_neox': 1506, 'n_words': 361}