Skip to content

Commit c9a1566

Browse files
committed
private function & private struct
1 parent ece0e3f commit c9a1566

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

services/gitdiff/gitdiff.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,12 @@ func DiffInlineWithHighlightCode(fileName, language, code string) DiffInline {
283283
return DiffInline{EscapeStatus: status, Content: template.HTML(content)}
284284
}
285285

286-
// HighlightCodeDiff is used to do diff with highlighted HTML code.
286+
// highlightCodeDiff is used to do diff with highlighted HTML code.
287287
// The HTML tags will be replaced by Unicode placeholders: "<span>{TEXT}</span>" => "\uE000{TEXT}\uE001"
288288
// These Unicode placeholders are friendly to the diff.
289289
// Then after diff, the placeholders in diff result will be recovered to the HTML tags.
290290
// It's guaranteed that the tags in final diff result are paired correctly.
291-
type HighlightCodeDiff struct {
291+
type highlightCodeDiff struct {
292292
placeholderBegin rune
293293
placeholderMaxCount int
294294
placeholderIndex int
@@ -298,8 +298,8 @@ type HighlightCodeDiff struct {
298298
lineWrapperTags []string
299299
}
300300

301-
func NewHighlightCodeDiff() *HighlightCodeDiff {
302-
return &HighlightCodeDiff{
301+
func newHighlightCodeDiff() *highlightCodeDiff {
302+
return &highlightCodeDiff{
303303
placeholderBegin: rune(0xE000), // Private Use Unicode: U+E000..U+F8FF, BMP(0), 6400
304304
placeholderMaxCount: 6400,
305305
placeholderTagMap: map[rune]string{},
@@ -310,7 +310,7 @@ func NewHighlightCodeDiff() *HighlightCodeDiff {
310310
// nextPlaceholder returns 0 if no more placeholder can be used
311311
// the diff is done line by line, usually there are only a few (no more than 10) placeholders in one line
312312
// so the placeholderMaxCount is impossible to be exhausted in real cases.
313-
func (hcd *HighlightCodeDiff) nextPlaceholder() rune {
313+
func (hcd *highlightCodeDiff) nextPlaceholder() rune {
314314
for hcd.placeholderIndex < hcd.placeholderMaxCount {
315315
r := hcd.placeholderBegin + rune(hcd.placeholderIndex)
316316
hcd.placeholderIndex++
@@ -322,11 +322,11 @@ func (hcd *HighlightCodeDiff) nextPlaceholder() rune {
322322
return 0 // no more available placeholder
323323
}
324324

325-
func (hcd *HighlightCodeDiff) isInPlaceholderRange(r rune) bool {
325+
func (hcd *highlightCodeDiff) isInPlaceholderRange(r rune) bool {
326326
return hcd.placeholderBegin <= r && r < hcd.placeholderBegin+rune(hcd.placeholderMaxCount)
327327
}
328328

329-
func (hcd *HighlightCodeDiff) collectUsedRunes(code string) {
329+
func (hcd *highlightCodeDiff) collectUsedRunes(code string) {
330330
for _, r := range code {
331331
if hcd.isInPlaceholderRange(r) {
332332
// put the existing rune (used by code) in map, then this rune won't be used a placeholder anymore.
@@ -335,7 +335,7 @@ func (hcd *HighlightCodeDiff) collectUsedRunes(code string) {
335335
}
336336
}
337337

338-
func (hcd *HighlightCodeDiff) diffWithHighlight(filename, language, codeA, codeB string) []diffmatchpatch.Diff {
338+
func (hcd *highlightCodeDiff) diffWithHighlight(filename, language, codeA, codeB string) []diffmatchpatch.Diff {
339339
hcd.collectUsedRunes(codeA)
340340
hcd.collectUsedRunes(codeB)
341341

@@ -354,7 +354,7 @@ func (hcd *HighlightCodeDiff) diffWithHighlight(filename, language, codeA, codeB
354354
return diffs
355355
}
356356

357-
func (hcd *HighlightCodeDiff) convertToPlaceholders(htmlCode string) string {
357+
func (hcd *highlightCodeDiff) convertToPlaceholders(htmlCode string) string {
358358
var tagStack []string
359359
res := strings.Builder{}
360360

@@ -419,7 +419,7 @@ func (hcd *HighlightCodeDiff) convertToPlaceholders(htmlCode string) string {
419419
return res.String()
420420
}
421421

422-
func (hcd *HighlightCodeDiff) recoverOneDiff(diff *diffmatchpatch.Diff) {
422+
func (hcd *highlightCodeDiff) recoverOneDiff(diff *diffmatchpatch.Diff) {
423423
sb := strings.Builder{}
424424
var tagStack []string
425425

@@ -501,7 +501,7 @@ func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine) Dif
501501
return DiffInlineWithHighlightCode(diffSection.FileName, language, diffLine.Content)
502502
}
503503

504-
hcd := NewHighlightCodeDiff()
504+
hcd := newHighlightCodeDiff()
505505
diffRecord := hcd.diffWithHighlight(diffSection.FileName, language, diff1[1:], diff2[1:])
506506
// it seems that Gitea doesn't need the line wrapper of Chroma, so do not add them back
507507
// if the line wrappers are still needed in the future, it can be added back by "diffToHTML(hcd.lineWrapperTags. ...)"

services/gitdiff/gitdiff_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ func TestGetDiffRangeWithWhitespaceBehavior(t *testing.T) {
645645
}
646646

647647
func TestDiffWithHighlight(t *testing.T) {
648-
hcd := NewHighlightCodeDiff()
648+
hcd := newHighlightCodeDiff()
649649
diffs := hcd.diffWithHighlight(
650650
"main.v", "",
651651
" run('<>')\n",
@@ -662,7 +662,7 @@ func TestDiffWithHighlight(t *testing.T) {
662662
}
663663

664664
func TestDiffWithHighlightPlaceholder(t *testing.T) {
665-
hcd := NewHighlightCodeDiff()
665+
hcd := newHighlightCodeDiff()
666666
diffs := hcd.diffWithHighlight(
667667
"main.js", "",
668668
"a='\uE000'",
@@ -675,7 +675,7 @@ func TestDiffWithHighlightPlaceholder(t *testing.T) {
675675
output := diffToHTML(hcd.lineWrapperTags, diffs, DiffLineDel)
676676
assert.Equal(t, expected, output)
677677

678-
hcd = NewHighlightCodeDiff()
678+
hcd = newHighlightCodeDiff()
679679
diffs = hcd.diffWithHighlight(
680680
"main.js", "",
681681
"a='\uE000'",

0 commit comments

Comments
 (0)