File: methods.cc

package info (click to toggle)
wreport 3.36-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 17,572 kB
  • sloc: cpp: 18,927; python: 583; sh: 78; makefile: 13
file content (65 lines) | stat: -rw-r--r-- 1,298 bytes parent folder | download | duplicates (3)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "methods.h"
#include <string>

namespace wreport {
namespace python {

std::string build_method_doc(const char* name, const char* signature, const char* returns, const char* summary, const char* doc)
{
    std::string res;
    unsigned doc_indent = 0;
    if (doc)
    {
        // Look up doc indentation
        // Count the leading spaces of the first non-empty line
        unsigned indent = 0;
        for (const char* c = doc; *c; ++c)
        {
            if (isblank(*c))
                ++indent;
            else if (*c == '\n' || *c == '\r')
            {
                // strip empty lines
                doc = c;
                indent = 0;
            }
            else
            {
                doc_indent = indent;
                break;
            }
        }
    }

    // Function name and signature
    res += name;
    res += '(';
    res += signature;
    res += ')';
    if (returns)
    {
        res += " -> ";
        res += returns;
    }
    res += "\n\n";

    // Indented summary
    if (summary)
    {
        for (unsigned i = 0; i < doc_indent; ++i) res += ' ';
        res += summary;
    }

    // Docstring
    if (doc)
    {
        res += "\n\n";
        res += doc;
    }

    // Return a C string with a copy of res
    return res;
}

}
}