Skip to content

Commit

Permalink
main: trim whitespace prefix from tag name
Browse files Browse the repository at this point in the history
Close universal-ctags#1141

Original issue:

    [yamato@x201]~/var/ctags-github% cat /tmp/foo.html
    cat /tmp/foo.html
    <h1> ABC</h1>

    [yamato@x201]~/var/ctags-github% ./ctags /tmp/foo.html
    ./ctags /tmp/foo.html
    [yamato@x201]~/var/ctags-github% cat tags
    cat tags
     ABC    /tmp/foo.html   /^<h1> ABC<\/h1>$/;"    h
    !_TAG_FILE_FORMAT   2   /extended format; --format=1 will not append ;" to lines/
    !_TAG_FILE_SORTED   1   /0=unsorted, 1=sorted, 2=foldcase/
    !_TAG_PROGRAM_AUTHOR    Universal Ctags Team    //
    !_TAG_PROGRAM_NAME  Universal Ctags /Derived from Exuberant Ctags/
    !_TAG_PROGRAM_URL   https://ctags.io/   /official site/
    !_TAG_PROGRAM_VERSION   0.0.0   /25bad34/

    Look at the whiespace before ABC.

    If a tag name is started with a whitespace, it is printed in tags file before pseudo tags.
    I guess this behavior make client tools get into crazy.

This patch trims whitespace characters at the head of tag name.

trimPrefixedWhitespaces() function is much simpflied by @codebrainz.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Oct 5, 2017
1 parent 7317871 commit 2bcd419
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
heading1 input.html /^<\/h1>$/;" h
3 changes: 3 additions & 0 deletions Units/parser-html.r/whitespace-prefixed.html.d/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>
heading1
</h1>
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
\n input.js /^let`$/;" v
29 changes: 28 additions & 1 deletion main/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -1280,8 +1280,25 @@ static void makeTagEntriesForSubwords (tagEntryInfo *const subtag)
stringListDelete (list);
}

extern int makeTagEntry (const tagEntryInfo *const tag)
static char *trimPrefixedWhitespaces (const char *name)
{
const char *start;

for (start = name; isspace(*start); start++)
;

if (start != name)
return eStrdup (start);

return NULL;
}

extern int makeTagEntry (const tagEntryInfo *const tag_const)
{
char *trimmed_name;
const tagEntryInfo *tag = tag_const;
tagEntryInfo tag_backingstore;

int r = CORK_NIL;
Assert (tag->name != NULL);

Expand All @@ -1295,6 +1312,14 @@ extern int makeTagEntry (const tagEntryInfo *const tag)
return CORK_NIL;
}

trimmed_name = trimPrefixedWhitespaces (tag->name);
if (trimmed_name)
{
tag_backingstore = *tag_const;
tag = &tag_backingstore;
tag_backingstore.name = trimmed_name;
}

if (tag->name [0] == '\0' && (!tag->placeholder))
{
if (!doesInputLanguageAllowNullTag())
Expand All @@ -1314,6 +1339,8 @@ extern int makeTagEntry (const tagEntryInfo *const tag)
makeTagEntriesForSubwords (&subtag);
}
out:
if (trimmed_name)
eFree (trimmed_name);
return r;
}

Expand Down

0 comments on commit 2bcd419

Please sign in to comment.