Пример #1
0
        // FormatMediaType serializes mediatype t and the parameters
        // param as a media type conforming to RFC 2045 and RFC 2616.
        // The type and parameter names are written in lower-case.
        // When any of the arguments result in a standard violation then
        // FormatMediaType returns the empty string.
        public static @string FormatMediaType(@string t, map <@string, @string> param)
        {
            strings.Builder b = default;
            {
                var slash = strings.IndexByte(t, '/');

                if (slash == -1L)
                {
                    if (!isToken(t))
                    {
                        return("");
                    }
                    b.WriteString(strings.ToLower(t));
                }
                else
                {
                    var major = t[..slash];
Пример #2
0
                            // ApplyEdits applies the set of edits to the before and returns the resulting
                            // content.
                            // It may panic or produce garbage if the edits are not valid for the provided
                            // before content.
                            public static @string ApplyEdits(@string before, slice <TextEdit> edits)
                            {
                                // Preconditions:
                                //   - all of the edits apply to before
                                //   - and all the spans for each TextEdit have the same URI
                                if (len(edits) == 0L)
                                {
                                    return(before);
                                }

                                _, edits, _ = prepareEdits(before, edits);
                                strings.Builder after = new strings.Builder();
                                long            last  = 0L;

                                foreach (var(_, edit) in edits)
                                {
                                    var start = edit.Span.Start().Offset();
                                    if (start > last)
                                    {
                                        after.WriteString(before[last..start]);
Пример #3
0
        // htmlOutput reads the profile data from profile and generates an HTML
        // coverage report, writing it to outfile. If outfile is empty,
        // it writes the report to a temporary file and opens it in a web browser.
        private static error htmlOutput(@string profile, @string outfile)
        {
            var(profiles, err) = ParseProfiles(profile);
            if (err != null)
            {
                return(error.As(err) !);
            }
            templateData d = default;

            var(dirs, err) = findPkgs(profiles);
            if (err != null)
            {
                return(error.As(err) !);
            }
            foreach (var(_, profile) in profiles)
            {
                var fn = profile.FileName;
                if (profile.Mode == "set")
                {
                    d.Set = true;
                }
                var(file, err) = findFile(dirs, fn);
                if (err != null)
                {
                    return(error.As(err) !);
                }
                var(src, err) = ioutil.ReadFile(file);
                if (err != null)
                {
                    return(error.As(fmt.Errorf("can't read %q: %v", fn, err)) !);
                }
                ref strings.Builder buf = ref heap(out ptr <strings.Builder> _addr_buf);
                err = htmlGen(_addr_buf, src, profile.Boundaries(src));
                if (err != null)
                {
                    return(error.As(err) !);
                }
                d.Files = append(d.Files, addr(new templateFile(Name: fn, Body: template.HTML(buf.String()), Coverage: percentCovered(profile), )));
            }
Пример #4
0
 public errorDetailBuffer(io.ReadCloser r = default, strings.Builder buf = default, long bufLines = default)
 {
     this.r        = r;
     this.buf      = buf;
     this.bufLines = bufLines;
 }