Skip to content

Commit 1780d4a

Browse files
committed
nice -> pretty and fixed tests
1 parent f34cb68 commit 1780d4a

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

src/go/doc/comment.go

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ var (
3333
type Formatter interface {
3434
// Put makes sure that a string is propperly written to.
3535
// One thing Put should do is making sure the string is propperly escaped
36-
// Nice indicates if the text should be formatted or converted
37-
Put(text string, nice bool)
36+
// pretty indicates if the text should be formatted or converted
37+
Put(text string, pretty bool)
3838

3939
// WriteURL writes the URL to the writer using match as a display name.
40-
// italics indicates wether or not it should be italic. If nice is set,
40+
// italics indicates wether or not it should be italic. If pretty is set,
4141
// also turn `` and '' into appropirate quotes.
42-
WriteURL(url, match string, italics, nice bool)
42+
WriteURL(url, match string, italics, pretty bool)
4343

4444
StartPara()
4545
PreParaLine(line string)
@@ -77,10 +77,13 @@ var (
7777
htmlEndH = []byte("</h3>\n")
7878
)
7979

80-
// Escape escapes text for HTML. If nice is set,
80+
// Escape escapes text for HTML. If pretty is set,
8181
// also turn `` and '' into appropirate quotes.
82-
func (f *htmlFormatter) Put(text string, nice bool) {
83-
if nice {
82+
func (f *htmlFormatter) Put(text string, pretty bool) {
83+
if pretty {
84+
// In the first pass, we convert `` and '' into their unicode equivalents.
85+
// This prevents them from being escaped in HTMLEscape.
86+
text = convertQuotes(text)
8487
var buf bytes.Buffer
8588
template.HTMLEscape(&buf, []byte(text))
8689
// Now we convert the unicode quotes to their HTML escaped entities to maintain old behavior.
@@ -92,7 +95,7 @@ func (f *htmlFormatter) Put(text string, nice bool) {
9295
template.HTMLEscape(f.out, []byte(text))
9396
}
9497

95-
func (f *htmlFormatter) WriteURL(url, match string, italics, nice bool) {
98+
func (f *htmlFormatter) WriteURL(url, match string, italics, pretty bool) {
9699
if len(url) > 0 {
97100
f.out.Write(htmlPreLink)
98101
f.Put(url, false)
@@ -101,7 +104,7 @@ func (f *htmlFormatter) WriteURL(url, match string, italics, nice bool) {
101104
if italics {
102105
f.out.Write(htmlStartI)
103106
}
104-
f.Put(match, nice)
107+
f.Put(match, pretty)
105108
if italics {
106109
f.out.Write(htmlEndI)
107110
}
@@ -169,22 +172,22 @@ var newline = []byte("\n")
169172
var whiteSpace = []byte(" ")
170173
var prefix = []byte("// ")
171174

172-
// Escape escapes text for HTML. If nice is set,
175+
// Escape escapes text for HTML. If pretty is set,
173176
// also turn `` and '' into appropirate quotes.
174-
func (f *textFormatter) Put(text string, nice bool) {
175-
if nice {
177+
func (f *textFormatter) Put(text string, pretty bool) {
178+
if pretty {
176179
text = convertQuotes(text)
177180
f.line += text
178181
return
179182
}
180183
f.out.Write([]byte(text))
181184
}
182185

183-
func (f *textFormatter) WriteURL(url, match string, italics, nice bool) {
186+
func (f *textFormatter) WriteURL(url, match string, italics, pretty bool) {
184187
if url == "" {
185188
url = match
186189
}
187-
f.Put(url, nice)
190+
f.Put(url, pretty)
188191
}
189192

190193
func (f *textFormatter) StartPara() {
@@ -295,18 +298,18 @@ var (
295298
mdLinkEnd = []byte(")")
296299
)
297300

298-
// Escape escapes text for HTML. If nice is set,
301+
// Escape escapes text for HTML. If pretty is set,
299302
// also turn `` and '' into appropirate quotes.
300-
func (f *markdownFormatter) Put(text string, nice bool) {
303+
func (f *markdownFormatter) Put(text string, pretty bool) {
301304
text = mdEscape.ReplaceAllString(text, `\$1`)
302305
f.out.Write([]byte(text))
303306
}
304307

305-
func (f *markdownFormatter) WriteURL(url, match string, italics, nice bool) {
308+
func (f *markdownFormatter) WriteURL(url, match string, italics, pretty bool) {
306309
if len(url) > 0 {
307310
f.out.Write(mdLinkStart)
308311
}
309-
f.Put(match, nice)
312+
f.Put(match, pretty)
310313
if italics {
311314
f.out.Write(htmlStartI)
312315
}
@@ -497,10 +500,10 @@ var matchRx = lazyregexp.New(`(` + urlRx + `)|(` + identRx + `)`)
497500
// the corresponding map value is the empty string, the URL is not converted
498501
// into a link). Go identifiers that appear in the words map are italicized; if
499502
// the corresponding map value is not the empty string, it is considered a URL
500-
// and the word is converted into a link. If nice is set, the remaining text's
503+
// and the word is converted into a link. If pretty is set, the remaining text's
501504
// appearance is improved where it makes sense (e.g., `` is turned into &ldquo;
502505
// and '' into &rdquo;).
503-
func emphasize(w io.Writer, f Formatter, line string, words map[string]string, nice bool) {
506+
func emphasize(w io.Writer, f Formatter, line string, words map[string]string, pretty bool) {
504507
for {
505508
m := matchRx.FindStringSubmatchIndex(line)
506509
if m == nil {
@@ -510,10 +513,10 @@ func emphasize(w io.Writer, f Formatter, line string, words map[string]string, n
510513

511514
// write text before match
512515
pre := line[0:m[0]]
513-
if nice {
516+
if pretty {
514517
pre = convertQuotes(line[0:m[0]])
515518
}
516-
f.Put(pre, nice)
519+
f.Put(pre, pretty)
517520

518521
// adjust match for URLs
519522
match := line[m[0]:m[1]]
@@ -552,20 +555,20 @@ func emphasize(w io.Writer, f Formatter, line string, words map[string]string, n
552555
}
553556
italics = false // don't italicize URLs
554557
}
555-
if nice {
558+
if pretty {
556559
match = convertQuotes(match)
557560
}
558561

559562
// write match
560-
f.WriteURL(url, match, italics, nice)
563+
f.WriteURL(url, match, italics, pretty)
561564

562565
// advance
563566
line = line[m[1]:]
564567
}
565-
if nice {
568+
if pretty {
566569
line = convertQuotes(line)
567570
}
568-
f.Put(line, nice)
571+
f.Put(line, pretty)
569572
}
570573

571574
func convertQuotes(text string) string {

src/go/doc/comment_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ type testFormatter struct {
2020
headID string
2121
}
2222

23-
// Escape escapes text for HTML. If nice is set,
23+
// Put escapes text for HTML. If pretty is set,
2424
// also turn `` and '' into appropirate quotes.
25-
func (f *testFormatter) Escape(text string, nice bool) {
26-
if nice {
25+
func (f *testFormatter) Put(text string, pretty bool) {
26+
if pretty {
2727
// In the first pass, we convert `` and '' into their unicode equivalents.
2828
// This prevents them from being escaped in HTMLEscape.
2929
text = convertQuotes(text)
@@ -38,16 +38,16 @@ func (f *testFormatter) Escape(text string, nice bool) {
3838
template.HTMLEscape(f.out, []byte(text))
3939
}
4040

41-
func (f *testFormatter) WriteURL(url, match string, italics, nice bool) {
41+
func (f *testFormatter) WriteURL(url, match string, italics, pretty bool) {
4242
if len(url) > 0 {
4343
f.out.Write(htmlPreLink)
44-
f.Escape(url, false)
44+
f.Put(url, false)
4545
f.out.Write(htmlPostLink)
4646
}
4747
if italics {
4848
f.out.Write(htmlStartI)
4949
}
50-
f.Escape(match, nice)
50+
f.Put(match, pretty)
5151
if italics {
5252
f.out.Write(htmlEndI)
5353
}
@@ -320,7 +320,7 @@ func TestHtmlEscape(t *testing.T) {
320320
for i, tt := range commentTests {
321321
var buf strings.Builder
322322
html.out = &buf
323-
html.Escape(tt.in, true)
323+
html.Put(tt.in, true)
324324
out := buf.String()
325325
if out != tt.out {
326326
t.Errorf("#%d: mismatch\nhave: %q\nwant: %q", i, out, tt.out)

0 commit comments

Comments
 (0)