-
Notifications
You must be signed in to change notification settings - Fork 6
/
util_doc.go
45 lines (42 loc) · 1022 Bytes
/
util_doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package swift
import (
"bufio"
"strings"
)
// swiftDoc transforms the provided VDL doc and a doc suffix into the SwiftDoc format.
func swiftDoc(doc, suffix string) string {
if doc == "" && suffix == "" {
return ""
}
if doc == "" {
doc = suffix
} else if suffix != "" {
doc = doc + "\n" + suffix
}
ret := ""
reader := bufio.NewReader(strings.NewReader(doc))
hitContent := false
for {
line, err := reader.ReadString('\n')
if err != nil {
// A purely empty comment gets ignored
if !hitContent {
ret = ""
}
return ret
}
line = strings.TrimSpace(line)
if strings.HasPrefix(line, "//") {
// Three consequtive slashes is the format for Swiftdoc. Add the additional beyond what the line starts with.
ret += "/"
ret += line
ret += "\n"
if !hitContent && line != "//" {
hitContent = true
}
}
}
}